File tree 6 files changed +36
-12
lines changed
6 files changed +36
-12
lines changed Original file line number Diff line number Diff line change @@ -46,13 +46,16 @@ public function __construct(array $data = [])
46
46
parent ::__construct ($ data );
47
47
}
48
48
49
- public function merge (...$ stack ): MapInterface
49
+ public function merge (MapInterface ...$ stack ): MapInterface
50
50
{
51
51
$ instance = clone $ this ;
52
- foreach ($ stack as $ list ) {
53
- $ instance ->data = array_merge ($ instance ->data , $ list ->toNativeArray ());
52
+ $ merges = [];
53
+ foreach ($ stack as $ map ) {
54
+ $ merges [] = $ map ->toNativeArray ();
54
55
}
55
56
57
+ $ instance ->data = array_merge ($ instance ->data , ...$ merges );
58
+
56
59
return $ instance ;
57
60
}
58
61
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ public function sort(?callable $callback = null): MapInterface;
32
32
* @psalm-param list<MapInterface<TKey,TValue>> $stack
33
33
* @psalm-return MapInterface<TKey,TValue>
34
34
*/
35
- public function merge (...$ stack ): MapInterface ;
35
+ public function merge (MapInterface ...$ stack ): MapInterface ;
36
36
37
37
/**
38
38
* @psalm-param MapInterface<TKey,TValue> $other
Original file line number Diff line number Diff line change 11
11
12
12
use function array_key_exists ;
13
13
use function array_keys ;
14
- use function array_map ;
15
14
use function array_merge ;
16
15
use function array_replace ;
17
16
use function array_reverse ;
@@ -46,14 +45,14 @@ final public function __construct(array $data = [])
46
45
parent ::__construct ($ data );
47
46
}
48
47
49
- public function merge (...$ stack ): OrderedListInterface
48
+ public function merge (OrderedListInterface ...$ stack ): OrderedListInterface
50
49
{
51
50
$ instance = clone $ this ;
52
- $ values = array_map ( static function ( OrderedListInterface $ list ): array {
53
- return $ list ->toNativeArray ();
54
- }, $ stack ) ;
55
-
56
- $ instance -> data = array_values ( array_merge ( $ instance -> data , ... $ values ));
51
+ foreach ( $ stack as $ list ) {
52
+ foreach ( $ list ->toNativeArray () as $ value ) {
53
+ $ instance -> data [] = $ value ;
54
+ }
55
+ }
57
56
58
57
return $ instance ;
59
58
}
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ public function sort(?callable $callback = null): OrderedListInterface;
44
44
* @psalm-param list<OrderedListInterface<TValue>> $stack
45
45
* @psalm-return OrderedListInterface<TValue>
46
46
*/
47
- public function merge (...$ stack ): OrderedListInterface ;
47
+ public function merge (OrderedListInterface ...$ stack ): OrderedListInterface ;
48
48
49
49
/**
50
50
* @template TNewValue
Original file line number Diff line number Diff line change @@ -185,6 +185,14 @@ public function mergeStacks(): Generator
185
185
['baz ' => 'bar ' , 'qoo ' => 'ooq ' ],
186
186
],
187
187
];
188
+
189
+ yield 'none ' => [
190
+ ['foo ' => 'bar ' ],
191
+ ['foo ' => 'bar ' ],
192
+ [
193
+ [],
194
+ ],
195
+ ];
188
196
}
189
197
190
198
/**
Original file line number Diff line number Diff line change @@ -164,6 +164,20 @@ public function mergeStacks(): Generator
164
164
['baz ' , 'foo ' ],
165
165
],
166
166
];
167
+
168
+ yield 'none ' => [
169
+ [
170
+ 'foo ' ,
171
+ 'bar ' ,
172
+ ],
173
+ [
174
+ 'foo ' ,
175
+ 'bar ' ,
176
+ ],
177
+ [
178
+ [],
179
+ ],
180
+ ];
167
181
}
168
182
169
183
public function testWillMapByUsingCallable (): void
You can’t perform that action at this time.
0 commit comments