Skip to content

Commit 371049a

Browse files
authored
Fix stream iterate factory (#91)
1 parent d60d80b commit 371049a

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/Collection/Stream.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,8 @@ public static function continually(callable $supplier): self
105105
*/
106106
public static function iterate($seed, callable $iterator): self
107107
{
108-
$current = $iterator($seed);
109-
110-
return new Cons($current, function () use ($iterator, $current) {
111-
return self::iterate($current, $iterator);
108+
return new Cons($seed, function () use ($iterator, $seed) {
109+
return self::iterate($iterator($seed), $iterator);
112110
});
113111
}
114112

tests/Collection/StreamTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ public function testStreamContinually(): void
143143

144144
public function testStreamIterate(): void
145145
{
146-
self::assertTrue(Stream::of(2, 4, 8)->equals(Stream::iterate(1, function (int $i) {return $i * 2; })->take(3)));
147-
self::assertTrue(Stream::of(-1, -2, -3)->equals(Stream::iterate(0, function (int $i) {return --$i; })->take(3)));
146+
self::assertTrue(Stream::of(1, 2, 4)->equals(Stream::iterate(1, function (int $i) {return $i * 2; })->take(3)));
147+
self::assertTrue(Stream::of(0, -1, -2)->equals(Stream::iterate(0, function (int $i) {return --$i; })->take(3)));
148+
self::assertTrue(Stream::of('a', 'aa', 'aaaa')->equals(Stream::iterate('a', function (string $t) {return $t.$t; })->take(3)));
148149
}
149150

150151
public function testStreamCons(): void

0 commit comments

Comments
 (0)