Skip to content

Commit

Permalink
SA: Fix a couple of operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed May 2, 2022
1 parent 843c9c4 commit 679834b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/Operation/Every.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ static function (callable ...$predicates): Closure {
static function (iterable $iterable) use ($predicates): Generator {
$predicate = CallbacksArrayReducer::or()($predicates);

foreach ((new Pack())()($iterable) as $index => [$key, $value]) {
/** @var Generator<int, array{0: TKey, 1:T}> $packed */
$packed = (new Pack())()($iterable);

foreach ($packed as $index => [$key, $value]) {
if (false === $predicate($index, $value, $key, $iterable)) {
return yield $index => false;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Operation/ScanLeft1.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public function __invoke(): Closure
*/
static fn (callable $callback): Closure =>
/**
* @param iterable<TKey, T> $iterable
*
* @return Generator<int|TKey, T|V>
*/
static function (iterable $iterable) use ($callback): Generator {
Expand Down
28 changes: 19 additions & 9 deletions src/Operation/Unwindow.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,27 @@ final class Unwindow extends AbstractOperation
*/
public function __invoke(): Closure
{
/** @var Closure(iterable<TKey, list<T>>): Generator<TKey, T|null> $unwindow */
$unwindow = (new Map())()(
/**
* @param list<T> $iterable
*
* @return T|null
*/
static fn (iterable $iterable) => (new Last())()($iterable)->current()
/** @var Closure(iterable<TKey, list<T>>): Generator<TKey, T|null> $pipe */
$pipe = (new Pipe())()(
(new Map())()(
/**
* @param list<T> $iterable
*
* @return Generator<TKey, T>
*/
static fn (iterable $iterable): Generator => (new Last())()($iterable)
),
(new Map())()(
/**
* @param Generator<TKey, T> $iterable
*
* @return T|null
*/
static fn (Generator $iterable) => $iterable->current()
),
);

// Point free style.
return $unwindow;
return $pipe;
}
}

0 comments on commit 679834b

Please sign in to comment.