Skip to content

Commit

Permalink
fix colletion methods docblocks (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
akondas authored May 18, 2024
1 parent 134f1bc commit 3c9c97e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Collection/GenericList.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ public function map(callable $mapper): self
return new Cons($mapper($this->head()), $this->tail()->map($mapper));
}

/**
* @template U
*
* @param callable(T): Traversable<U> $mapper
*
* @return GenericList<U>
*/
public function flatMap(callable $mapper)
{
$list = self::empty();
Expand Down Expand Up @@ -224,6 +231,9 @@ public function reverse(): self
return $list;
}

/**
* @return GenericList<T>
*/
public function appendAll(Traversable $elements)
{
if ($elements->isEmpty()) {
Expand All @@ -233,6 +243,9 @@ public function appendAll(Traversable $elements)
return self::ofAll($elements)->prependAll($this);
}

/**
* @return GenericList<T>
*/
public function prependAll(Traversable $elements)
{
if ($this->isEmpty()) {
Expand Down
10 changes: 10 additions & 0 deletions src/Collection/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ public function map(callable $mapper): self
return new Cons($mapper($this->head()), function () use ($mapper) {return $this->tail()->map($mapper); });
}

/**
* @template U
*
* @param callable(T): Traversable<U> $mapper
*
* @return Stream<U>
*/
public function flatMap(callable $mapper)
{
$stream = self::empty();
Expand Down Expand Up @@ -292,6 +299,9 @@ public function prepend($element)
return new Cons($element, function () {return $this; });
}

/**
* @return Stream<T>
*/
public function prependAll(Traversable $elements)
{
if ($elements->isEmpty()) {
Expand Down
6 changes: 6 additions & 0 deletions src/Collection/Stream/Cons.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,19 @@ public function iterator(): Iterator
return new StreamIterator($this);
}

/**
* @return Stream<T>
*/
public function append($element)
{
return new Cons($this->head, function () use ($element) {
return $this->tail()->append($element);
});
}

/**
* @return Stream<T>
*/
public function appendAll(Traversable $elements)
{
if ($elements->isEmpty()) {
Expand Down
6 changes: 6 additions & 0 deletions src/Collection/Stream/EmptyStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,17 @@ public function iterator(): Iterator
return Iterator::empty();
}

/**
* @return Stream<T>
*/
public function append($element)
{
return Stream::of($element);
}

/**
* @return Stream<T>
*/
public function appendAll(Traversable $elements)
{
if ($elements->isEmpty()) {
Expand Down

0 comments on commit 3c9c97e

Please sign in to comment.