Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
</p>

<p align="center">
<a href="https://travis-ci.com/transprime-research/arrayed"> <img src="https://travis-ci.org/transprime-research/arrayed.svg?branch=master" alt="Build Status"/></a>
<a href="https://travis-ci.org/transprime-research/arrayed"> <img src="https://travis-ci.org/transprime-research/arrayed.svg?branch=master" alt="Build Status"/></a>
<a href="https://packagist.org/packages/transprime-research/arrayed"> <img src="https://poser.pugx.org/transprime-research/arrayed/v/stable" alt="Latest Stable Version"/></a>
<a href="https://packagist.org/packages/transprime-research/arrayed"> <img src="https://poser.pugx.org/transprime-research/arrayed/downloads" alt="Total Downloads"/></a>
<a href="https://packagist.org/packages/transprime-research/arrayed"> <img src="https://poser.pugx.org/transprime-research/arrayed/v/unstable" alt="Latest Unstable Version"/></a>
Expand Down Expand Up @@ -187,6 +187,16 @@ arrayed(['a', 'b'])

- Implement other `array_*` methods

- pipe into Collection with `collectPipe`

```php
use Illuminate\Support\Collection;

arrayed(1,2,3)->collectPipe(function (Collection $collected) {
return $collected->take(2)->all();
})->keys();
```

> Api implementation to be decided

## APIs
Expand Down Expand Up @@ -272,7 +282,7 @@ Arrayed::diffKey(array $array2, array ...$_): ArrayedInterface;

## Additional Information

Be aware that this package is part of a series of "The Proof of Concept".
This package is part of a series of "Code Dare"

See other packages in this series here:

Expand Down
4 changes: 2 additions & 2 deletions src/Arrayed.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public function __invoke(callable $callable = null)
return $this->result($callable);
}

public function map($callback): ArrayedInterface
public function map($callback, ...$_): ArrayedInterface
{
return $this->setResult(array_map($callback, $this->getWorkableItem()));
return $this->setResult(array_map($callback, $this->getWorkableItem(), ...$_));
}

public function filter($callback = null, int $flag = 0): ArrayedInterface
Expand Down
34 changes: 34 additions & 0 deletions tests/ArrayPrefixTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,40 @@ public function testChunk()
);
}

public function testMap()
{
$array1 = [1, 2];
$array2 = ['one', 'two'];

$this->assertEquals(
['ONE', 'TWO'],
arrayed($array2)
->map(function ($value) {
return strtoupper($value);
})->result()
);

$this->assertEquals(
[
[1 => 'one'],
[2 => 'two'],
],
arrayed($array1)
->map(function ($first, $second) {
return [$first => $second];
}, $array2)
->result()
);

$this->assertEquals(
[
[1, 'one'],
[2, 'two'],
],
arrayed($array1)->map(null, $array2)->result()
);
}

public function testColumn()
{
$array = [
Expand Down