Skip to content

Commit

Permalink
use SortIterableAggregate
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jan 27, 2024
1 parent 7696dc9 commit 0778f4e
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/RandomIterableAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ public function __construct(private readonly iterable $iterable, private readonl
public function getIterator(): Generator
{
$cache = new CachingIteratorAggregate((new PackIterableAggregate($this->iterable))->getIterator());
$shuffle = new ShuffleIteratorAggregate(iterator_count($cache), $this->seed);

foreach ($shuffle as $number) {
foreach ($cache as $key => $value) {
if ($key === $number) {
yield $value[0] => $value[1];
}
}
}
$sort = new SortIterableAggregate(
(new UnpackIterableAggregate(new MultipleIterableAggregate([

Check failure on line 31 in src/RandomIterableAggregate.php

View workflow job for this annotation

GitHub Actions / Static Analysis (ubuntu-latest, 8.1)

Parameter #1 $iterable of class loophp\iterators\UnpackIterableAggregate constructor expects iterable<(int|string), array{mixed, mixed}>, loophp\iterators\MultipleIterableAggregate<mixed, mixed> given.

Check failure on line 31 in src/RandomIterableAggregate.php

View workflow job for this annotation

GitHub Actions / Static Analysis (ubuntu-latest, 8.1)

InvalidArgument

src/RandomIterableAggregate.php:31:42: InvalidArgument: Argument 1 of loophp\iterators\UnpackIterableAggregate::__construct expects iterable<array-key, array{0: mixed, 1: mixed}>, but loophp\iterators\MultipleIterableAggregate<int, array{0: TKey:loophp\iterators\RandomIterableAggregate as mixed, 1: T:loophp\iterators\RandomIterableAggregate as mixed}> provided (see https://psalm.dev/004)

Check failure on line 31 in src/RandomIterableAggregate.php

View workflow job for this annotation

GitHub Actions / Static Analysis (ubuntu-latest, 8.1)

Parameter #1 $iterable of class loophp\iterators\UnpackIterableAggregate constructor expects iterable<(int|string), array{mixed, mixed}>, loophp\iterators\MultipleIterableAggregate<mixed, mixed> given.
new ShuffleIteratorAggregate(iterator_count($cache), $this->seed),
$cache,
]))),
static fn (array $a, array $b, int $ka, int $kb): int => $ka <=> $kb

Check failure on line 35 in src/RandomIterableAggregate.php

View workflow job for this annotation

GitHub Actions / Static Analysis (ubuntu-latest, 8.1)

Parameter #2 $callback of class loophp\iterators\SortIterableAggregate constructor expects Closure(mixed, mixed, mixed, mixed): int, Closure(array, array, int, int): int<-1, 1> given.
);

yield from new UnpackIterableAggregate($sort);

Check failure on line 38 in src/RandomIterableAggregate.php

View workflow job for this annotation

GitHub Actions / Static Analysis (ubuntu-latest, 8.1)

Parameter #1 $iterable of class loophp\iterators\UnpackIterableAggregate constructor expects iterable<(int|string), array{TKey, T}>, loophp\iterators\SortIterableAggregate<mixed, mixed> given.
}
}

0 comments on commit 0778f4e

Please sign in to comment.