From 758e39e3785993b09c9039ae917c44e4ff58fcb5 Mon Sep 17 00:00:00 2001 From: Oluwatobi Samue Omisakin Date: Tue, 16 Jun 2020 22:56:49 +0300 Subject: [PATCH 1/3] enable and test map metho having optional array after callback --- src/Arrayed.php | 4 ++-- tests/ArrayPrefixTraitTest.php | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/Arrayed.php b/src/Arrayed.php index 06d7d09..fcf0f1f 100644 --- a/src/Arrayed.php +++ b/src/Arrayed.php @@ -38,9 +38,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 = [ From bfc92e968cb7f24fbd3a3c666b58f713e9ee69ec Mon Sep 17 00:00:00 2001 From: Oluwatobi Samue Omisakin Date: Tue, 16 Jun 2020 22:58:53 +0300 Subject: [PATCH 2/3] [travis skip] correct the url link to travis --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 27a178e..dd2c361 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@

- Build Status + Build Status Latest Stable Version Total Downloads Latest Unstable Version From ddfc15e311b44ea7fbe4b61943a767896f240a03 Mon Sep 17 00:00:00 2001 From: Oluwatobi Samue Omisakin Date: Tue, 16 Jun 2020 23:17:36 +0300 Subject: [PATCH 3/3] [travis skip] Add collectPipe as future feature --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dd2c361..6ca7110 100644 --- a/README.md +++ b/README.md @@ -184,6 +184,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 @@ -269,7 +279,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: