Skip to content

Commit

Permalink
Update typing information.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jul 7, 2021
1 parent 7c8a9ee commit bef7ace
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 34 deletions.
5 changes: 3 additions & 2 deletions src/Contract/Operation/Partitionable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace loophp\collection\Contract\Operation;

use Iterator;
use loophp\collection\Contract\Collection;

/**
Expand All @@ -18,9 +19,9 @@
interface Partitionable
{
/**
* @param callable(T, TKey):bool ...$callbacks
* @param callable(T, TKey, Iterator<TKey, T>): bool ...$callbacks
*
* @return Collection<int, array<int, array{0: TKey, 1: T}>>
* @return Collection<int, Collection<TKey, T>>
*/
public function partition(callable ...$callbacks): Collection;
}
5 changes: 4 additions & 1 deletion src/Contract/Operation/Spanable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace loophp\collection\Contract\Operation;

use Iterator;
use loophp\collection\Contract\Collection;

/**
Expand All @@ -18,7 +19,9 @@
interface Spanable
{
/**
* @return Collection<TKey, T>
* @param callable(T, TKey, Iterator<TKey, T>): bool $callback
*
* @return Collection<int, Collection<TKey, T>>
*/
public function span(callable $callback): Collection;
}
39 changes: 8 additions & 31 deletions src/Operation/Partition.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,52 +26,29 @@ final class Partition extends AbstractOperation
/**
* @pure
*
* @return Closure(callable(T, TKey, Iterator<TKey, T>):bool...): Closure(Iterator<TKey, T>): Generator<int, list<array{0: TKey, 1: T}>>
* @return Closure(callable(T, TKey, Iterator<TKey, T>):bool...): Closure(Iterator<TKey, T>): Generator<int, Iterator<TKey, T>>
*/
public function __invoke(): Closure
{
return
/**
* @param callable(T, TKey, Iterator<TKey, T>):bool ...$callbacks
*
* @return Closure(Iterator<TKey, T>): Generator<int, list<array{0: TKey, 1: T}>>
* @return Closure(Iterator<TKey, T>): Generator<int, Iterator<TKey, T>>
*/
static fn (callable ...$callbacks): Closure =>
/**
* @param Iterator<TKey, T> $iterator
*
* @return Generator<int, list<array{0: TKey, 1: T}>>
* @return Generator<int, Iterator<TKey, T>>
*/
static function (Iterator $iterator) use ($callbacks): Iterator {
$reducerCallback =
/**
* @param TKey $key
*
* @return Closure(T): Closure(Iterator<TKey, T>): Closure(bool, callable(T, TKey, Iterator<TKey, T>): bool): bool
*/
static fn ($key): Closure =>
/**
* @param T $current
*
* @return Closure(Iterator<TKey, T>): Closure(bool, callable(T, TKey, Iterator<TKey, T>): bool): bool
*/
static fn ($current): Closure =>
/**
* @param Iterator<TKey, T> $iterator
*
* @return Closure(bool, callable(T, TKey, Iterator<TKey, T>): bool): bool
*/
static fn (Iterator $iterator): Closure =>
/**
* @param bool $carry
* @param callable(T, TKey, Iterator<TKey, T>): bool $callable
*/
static fn (bool $carry, callable $callable): bool => $carry || $callable($current, $key, $iterator);
/** @var Iterator<TKey, T> $filter */
$filter = Filter::of()(...$callbacks)($iterator);
/** @var Iterator<TKey, T> $reject */
$reject = Reject::of()(...$callbacks)($iterator);

$happy = Filter::of()(...$callbacks)($iterator);
$unhappy = Reject::of()(...$callbacks)($iterator);

return yield from [$happy, $unhappy];
return yield from [$filter, $reject];
};
}
}

0 comments on commit bef7ace

Please sign in to comment.