Skip to content

Commit 78d8185

Browse files
committed
fix: fix stream class syntax error
1 parent 9b44011 commit 78d8185

File tree

4 files changed

+15
-26
lines changed

4 files changed

+15
-26
lines changed

src/Util/Optional.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,14 @@ public static function ofNullable(mixed $value, mixed $nullValue = null): self
8989
*/
9090
public static function ofArrayKey(ArrayAccess|array $array, int|string $key): self
9191
{
92-
if (!(is_array($array) || $array instanceof ArrayAccess) || !isset($array[$key])) {
93-
return self::empty();
94-
}
95-
96-
return self::of($array[$key]);
92+
return isset($array[$key]) ? self::of($array[$key]) : self::empty();
9793
}
9894

95+
/**
96+
* @param callable(): mixed $fn
97+
*
98+
* @return static
99+
*/
99100
public static function ofReturn(callable $fn): self
100101
{
101102
return self::ofNullable($fn());
@@ -259,15 +260,18 @@ public function or(callable $supplier): self
259260
* If a value is present, returns a sequential Stream containing only that value,
260261
* otherwise returns an empty Stream.
261262
*
263+
* @param class-string $streamClass
264+
*
262265
* @return DataStream<T>
263266
*/
264-
public function stream(): DataStream
267+
public function stream(string $streamClass = DataStream::class): DataStream
265268
{
269+
/** @var $streamClass DataStream */
266270
if (!$this->isPresent()) {
267-
return DataStream::empty();
271+
return $streamClass::empty();
268272
}
269273

270-
return DataStream::of($this->value);
274+
return $streamClass::of($this->value);
271275
}
272276

273277
/**

src/Util/Stream/IntStream.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@ class IntStream extends ListStream
1111
{
1212
/**
1313
* @param numeric $value
14-
*
15-
* @return $this
1614
*/
17-
public function append(mixed $value): static
15+
public function append(mixed $value): void
1816
{
1917
parent::append((int)$value);
20-
return $this;
2118
}
2219
}

src/Util/Stream/ListStream.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,5 @@
99
*/
1010
class ListStream extends DataStream
1111
{
12-
/**
13-
* @param mixed $value
14-
*
15-
* @return $this
16-
*/
17-
public function append(mixed $value): static
18-
{
19-
parent::append($value);
20-
return $this;
21-
}
12+
2213
}

src/Util/Stream/StringStream.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ class StringStream extends ListStream
1111
{
1212
/**
1313
* @param mixed $value
14-
*
15-
* @return $this
1614
*/
17-
public function append(mixed $value): static
15+
public function append(mixed $value): void
1816
{
1917
parent::append((string)$value);
20-
return $this;
2118
}
2219

2320
/**

0 commit comments

Comments
 (0)