diff --git a/README.md b/README.md index b868593..8858788 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@
-
+
@@ -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
@@ -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:
diff --git a/src/Arrayed.php b/src/Arrayed.php
index f2f26eb..c93ef85 100644
--- a/src/Arrayed.php
+++ b/src/Arrayed.php
@@ -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
diff --git a/tests/ArrayPrefixTraitTest.php b/tests/ArrayPrefixTraitTest.php
index 7cc4001..1451c35 100644
--- a/tests/ArrayPrefixTraitTest.php
+++ b/tests/ArrayPrefixTraitTest.php
@@ -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 = [