Skip to content

Commit

Permalink
Update annotations.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Sep 1, 2020
1 parent 3bb8caa commit af3226f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
18 changes: 18 additions & 0 deletions spec/loophp/collection/CollectionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -1933,6 +1933,24 @@ public function it_can_truthy(): void
->shouldReturn(false);
}

public function it_can_unfold(): void
{
$this::unfold(1, static function (int $n): int {return $n + 1; })
->limit(10)
->shouldIterateAs([
1 => 1,
2 => 2,
3 => 3,
4 => 4,
5 => 5,
6 => 6,
7 => 7,
8 => 8,
9 => 9,
10 => 10,
]);
}

public function it_can_unpack(): void
{
$input = [
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Combine.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static function (...$keys): Closure {
/**
* @psalm-param Iterator<TKey, T> $iterator
*
* @psalm-retur Generator<T, T>
* @psalm-return Generator<T, T>
*/
static function (Iterator $iterator) use ($keys): Generator {
$keys = new ArrayIterator($keys);
Expand Down
14 changes: 10 additions & 4 deletions src/Operation/Iterate.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,34 @@
*/
final class Iterate extends AbstractOperation
{
// phpcs:disable
/**
* @psalm-return Closure(callable(T...):(array<TKey, T>)): Closure(T...): Generator<TKey, T>
* @psalm-return Closure(callable(T...):(array<TKey, T>)): Closure(T...): Closure(Iterator<TKey, T>=): Generator<int, T|false, mixed, void>
*/
// phpcs:enable
public function __invoke(): Closure
{
return
/**
* @psalm-param callable(T...):(array<TKey, T>) $callback
*
* @psalm-return Closure(T...): Closure(Iterator<TKey, T>=): Generator<int, T|false, mixed, void>
*/
static function (callable $callback): Closure {
return
/**
* @psalm-param T ...$parameters
*
* @psalm-return Closure(Iterator<TKey, T>=): Generator<int, T|false, mixed, void>
*/
static function (...$parameters) use ($callback): Closure {
return
/**
* @psalm-param Iterator<TKey, T> $iterator
* @psalm-param null|Iterator<TKey, T> $iterator
*
* @psalm-return Generator<TKey, T>
* @psalm-return Generator<int, T|false, mixed, void>
*/
static function (Iterator $iterator) use ($callback, $parameters): Generator {
static function (?Iterator $iterator = null) use ($callback, $parameters): Generator {
while (true) {
yield current(
$parameters = (array) $callback(...array_values((array) $parameters))
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Pair.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
final class Pair extends AbstractOperation
{
/**
* @psalm-return Closure(Iterator<TKey, T>): Generator<TKey, T>
* @psalm-return Closure(Iterator<TKey, T>): Generator<T, T>
*/
public function __invoke(): Closure
{
Expand Down

0 comments on commit af3226f

Please sign in to comment.