Skip to content

Commit 94a5542

Browse files
committed
fix. Get immutable collection with collect method.
1 parent 536513c commit 94a5542

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/WS/Utils/Collections/SerialStream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public function reverse(): Stream
182182
*/
183183
public function collect(callable $collector)
184184
{
185-
return $collector($this->getCollection());
185+
return $collector($this->getCollection()->copy());
186186
}
187187

188188
/**

tests/WS/Utils/Collections/ImmutableStreamTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class ImmutableStreamTest extends TestCase
1616
/**
1717
* @test
1818
*/
19-
public function shouldBeImmutableInReorganizeWithCollection(): void {
19+
public function shouldBeImmutableInReorganizeWithCollection(): void
20+
{
2021
$stream = self::toCollection(1, 2, 3)
2122
->stream();
2223

@@ -30,4 +31,22 @@ public function shouldBeImmutableInReorganizeWithCollection(): void {
3031

3132
self::assertThat($collection, CollectionIsEqual::to([1, 2, 3]));
3233
}
34+
35+
/**
36+
* @test
37+
*/
38+
public function shouldBeImmutableInCollectWithCollection(): void
39+
{
40+
$stream = self::toCollection(1, 2, 3)
41+
->stream();
42+
43+
$collection = $stream->getCollection();
44+
$stream
45+
->collect(static function (Collection $c) {
46+
$c->clear();
47+
return 1;
48+
});
49+
50+
self::assertThat($collection, CollectionIsEqual::to([1, 2, 3]));
51+
}
3352
}

0 commit comments

Comments
 (0)