Skip to content

Commit

Permalink
refactor: Use new keyword on some operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jan 6, 2022
1 parent f54b002 commit 323b4c8
Show file tree
Hide file tree
Showing 38 changed files with 98 additions and 101 deletions.
2 changes: 1 addition & 1 deletion src/Operation/AsyncMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static function (Iterator $iterator) use ($callback): Generator {
*/
static fn (array $value): array => [$value[0], $callback($value[1], $value[0])];

$iter = map(fromIterable(Pack::of()($iterator)), new LocalSemaphore(32), parallel($parallelCallBack));
$iter = map(fromIterable((new Pack())()($iterator)), new LocalSemaphore(32), parallel($parallelCallBack));

while (wait($iter->advance())) {
/** @var array{0: TKey, 1: V} $item */
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/AsyncMapN.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static function (Iterator $iterator) use ($callbacks): Generator {
*/
static fn (array $value): array => [$value[0], array_reduce($callbacks, $callbackFactory($value[0]), $value[1])];

$iter = map(fromIterable(Pack::of()($iterator)), new LocalSemaphore(32), parallel($callback));
$iter = map(fromIterable((new Pack())()($iterator)), new LocalSemaphore(32), parallel($callback));

while (wait($iter->advance())) {
/** @var array{0: mixed, 1: mixed} $item */
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Chunk.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __invoke(): Closure
*/
static function (Iterator $iterator) use ($sizes): Generator {
/** @var Iterator<int, int> $sizesIterator */
$sizesIterator = Cycle::of()(new ArrayIterator($sizes));
$sizesIterator = (new Cycle())()(new ArrayIterator($sizes));
$sizesIterator->rewind();

$values = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Collapse.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __invoke(): Closure
static fn ($value): bool => is_iterable($value);

/** @var Closure(Iterator<TKey, (T|iterable<TKey, T>)>): Generator<TKey, T> $pipe */
$pipe = Pipe::of()(
$pipe = (new Pipe())()(
(new Filter())()($filterCallback),
(new Flatten())()(1),
);
Expand Down
8 changes: 4 additions & 4 deletions src/Operation/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ static function ($column): Closure {
static fn ($value, $key, Iterator $iterator): bool => $key === $column;

/** @var Closure(Iterator<TKey, T>): Generator<int, mixed> $pipe */
$pipe = Pipe::of()(
Transpose::of(),
$pipe = (new Pipe())()(
(new Transpose())(),
(new Filter())()($filterCallbackBuilder($column)),
Head::of(),
Flatten::of()(1)
(new Head())(),
(new Flatten())()(1)
);

// Point free style.
Expand Down
4 changes: 2 additions & 2 deletions src/Operation/Combine.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ static function (Iterator $iterator) use ($keyIterator): MultipleIterator {
/** @var Closure(Iterator<TKey, T>): Generator<null|U, null|T> $pipe */
$pipe = Pipe::of()(
$buildMultipleIterator(new ArrayIterator($keys)),
Flatten::of()(1),
Pair::of(),
(new Flatten())()(1),
(new Pair())(),
);

// Point free style.
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Contains.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static function (...$values): Closure {
static fn ($right): bool => $left === $right;

/** @var Closure(Iterator<TKey, T>): Generator<TKey, bool> $matchOne */
$matchOne = MatchOne::of()(static fn (): bool => true)(...array_map($callback, $values));
$matchOne = (new MatchOne())()(static fn (): bool => true)(...array_map($callback, $values));

// Point free style.
return $matchOne;
Expand Down
4 changes: 2 additions & 2 deletions src/Operation/Current.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public function __invoke(): Closure
*/
static function ($default) use ($index): Closure {
/** @var Closure(Iterator<TKey, T>): Generator<int, T|V> $pipe */
$pipe = Pipe::of()(
$pipe = (new Pipe())()(
(new Normalize())(),
Get::of()($index)($default)
(new Get())()($index)($default)
);

// Point free style.
Expand Down
10 changes: 5 additions & 5 deletions src/Operation/Every.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ static function (callable ...$callbacks) use ($matchers): Closure {
static fn ($value, $key, Iterator $iterator): bool => $reducer1($value, $key, $iterator) !== $reducer2($value, $key, $iterator);

/** @var Closure(Iterator<TKey, T>): Generator<TKey, bool> $pipe */
$pipe = Pipe::of()(
Map::of()($mapCallback($callbackReducer($callbacks))($callbackReducer($matchers))),
DropWhile::of()(static fn (bool $value): bool => true === $value),
Append::of()(true),
Head::of(),
$pipe = (new Pipe())()(
(new Map())()($mapCallback($callbackReducer($callbacks))($callbackReducer($matchers))),
(new DropWhile())()(static fn (bool $value): bool => true === $value),
(new Append())()(true),
(new Head())(),
);

// Point free style.
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Explode.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __invoke(): Closure
*/
static function (...$explodes): Closure {
/** @var Closure(Iterator<TKey, T>): Generator<int, list<T>> $split */
$split = Split::of()(Splitable::REMOVE)(
$split = (new Split())()(Splitable::REMOVE)(
...array_map(
/**
* @param T $explode
Expand Down
6 changes: 3 additions & 3 deletions src/Operation/Find.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public function __invoke(): Closure
*/
static function (callable ...$callbacks) use ($default): Closure {
/** @var Closure(Iterator<TKey, T>): Generator<TKey, T|V> $pipe */
$pipe = Pipe::of()(
$pipe = (new Pipe())()(
(new Filter())()(...$callbacks),
Append::of()($default),
Head::of(),
(new Append())()($default),
(new Head())(),
);

// Point free style.
Expand Down
6 changes: 3 additions & 3 deletions src/Operation/FlatMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public function __invoke(): Closure
*/
static function (callable $callback): Closure {
/** @var Closure(Iterator<TKey, T>): Generator<IKey, IValue> $flatMap */
$flatMap = Pipe::of()(
Map::of()($callback),
Flatten::of()(1)
$flatMap = (new Pipe())()(
(new Map())()($callback),
(new Flatten())()(1)
);

// Point free style
Expand Down
6 changes: 3 additions & 3 deletions src/Operation/FoldLeft.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public function __invoke(): Closure
*/
static function ($initial = null) use ($callback): Closure {
/** @var Closure(Iterator<TKey, T>): Generator<TKey, T> $pipe */
$pipe = Pipe::of()(
ScanLeft::of()($callback)($initial),
Last::of()
$pipe = (new Pipe())()(
(new ScanLeft())()($callback)($initial),
(new Last())()
);

// Point free style.
Expand Down
6 changes: 3 additions & 3 deletions src/Operation/FoldLeft1.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public function __invoke(): Closure
*/
static function (callable $callback): Closure {
/** @var Closure(Iterator<TKey, T>):(Generator<int|TKey, T|null>) $pipe */
$pipe = Pipe::of()(
ScanLeft1::of()($callback),
Last::of()
$pipe = (new Pipe())()(
(new ScanLeft1())()($callback),
(new Last())()
);

// Point free style.
Expand Down
6 changes: 3 additions & 3 deletions src/Operation/FoldRight.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public function __invoke(): Closure
*/
static fn (callable $callback): Closure => static function ($initial = null) use ($callback): Closure {
/** @var Closure(Iterator<TKey, T>): Generator<TKey, T> $pipe */
$pipe = Pipe::of()(
ScanRight::of()($callback)($initial),
Head::of()
$pipe = (new Pipe())()(
(new ScanRight())()($callback)($initial),
(new Head())()
);

// Point free style.
Expand Down
6 changes: 3 additions & 3 deletions src/Operation/FoldRight1.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public function __invoke(): Closure
*/
static function (callable $callback): Closure {
/** @var Closure(Iterator<TKey, T>):(Generator<int|TKey, T|null>) $pipe */
$pipe = Pipe::of()(
ScanRight1::of()($callback),
Head::of()
$pipe = (new Pipe())()(
(new ScanRight1())()($callback),
(new Head())()
);

// Point free style.
Expand Down
6 changes: 3 additions & 3 deletions src/Operation/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ static function ($default) use ($keyToGet): Closure {
static fn ($value, $key): bool => $key === $keyToGet;

/** @var Closure(Iterator<TKey, T>): (Generator<TKey, T|V>) $pipe */
$pipe = Pipe::of()(
$pipe = (new Pipe())()(
(new Filter())()($filterCallback),
Append::of()($default),
Head::of()
(new Append())()($default),
(new Head())()
);

// Point free style.
Expand Down
6 changes: 3 additions & 3 deletions src/Operation/GroupBy.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ static function (array $collect, $value, $key) use ($callback): array {
};

/** @var Closure(Iterator<TKey, T>): Generator<NewTKey, non-empty-list<T>> $pipe */
$pipe = Pipe::of()(
Reduce::of()($reducerFactory($callable))([]),
Flatten::of()(1)
$pipe = (new Pipe())()(
(new Reduce())()($reducerFactory($callable))([]),
(new Flatten())()(1)
);

// Point free style.
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Has.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __invoke(): Closure
*/
static function (callable ...$callbacks): Closure {
/** @var Closure(Iterator<TKey, T>): Generator<TKey, bool> $pipe */
$pipe = MatchOne::of()(static fn (): bool => true)(
$pipe = (new MatchOne())()(static fn (): bool => true)(
...array_map(
static fn (callable $callback): callable =>
/**
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/IfThenElse.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __invoke(): Closure
*/
static function (callable $else) use ($condition, $then): Closure {
/** @var Closure(Iterator<TKey, T>): Generator<TKey, T> $map */
$map = Map::of()(
$map = (new Map())()(
/**
* @param T $value
* @param TKey $key
Expand Down
8 changes: 4 additions & 4 deletions src/Operation/Implode.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ static function (string $glue): Closure {
static fn (string $carry, $item): string => $carry .= $item;

/** @var Closure(Iterator<TKey, T>): Generator<TKey, string> $pipe */
$pipe = Pipe::of()(
Intersperse::of()($glue)(1)(0),
Drop::of()(1),
Reduce::of()($reducer)('')
$pipe = (new Pipe())()(
(new Intersperse())()($glue)(1)(0),
(new Drop())()(1),
(new Reduce())()($reducer)('')
);

// Point free style.
Expand Down
6 changes: 3 additions & 3 deletions src/Operation/Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public function __invoke(): Closure
*/
static function (int $index): Closure {
/** @var Closure(Iterator<TKey, T>): Generator<int, TKey> $pipe */
$pipe = Pipe::of()(
Limit::of()(1)($index),
Flip::of()
$pipe = (new Pipe())()(
(new Limit())()(1)($index),
(new Flip())()
);

// Point free style.
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class Map extends AbstractOperation
*
* @template V
*
* @return Closure(callable(T=, TKey=, Iterator<TKey, T>=): V): Closure(Iterator<TKey, T>): Generator<TKey, V>
* @return Closure(callable(T=, TKey=, Iterator<TKey, T>=): mixed): Closure(Iterator<TKey, T>): Generator<TKey, mixed>
*/
public function __invoke(): Closure
{
Expand Down
10 changes: 5 additions & 5 deletions src/Operation/MatchOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ static function (callable ...$matchers): Closure {
*/
static function (callable ...$callbacks) use ($matchers): Closure {
/** @var Closure(Iterator<TKey, T>): Generator<TKey, bool> $pipe */
$pipe = Pipe::of()(
Map::of()(
$pipe = (new Pipe())()(
(new Map())()(
/**
* @param T $value
* @param TKey $key
* @param Iterator<TKey, T> $iterator
*/
static fn ($value, $key, Iterator $iterator): bool => CallbacksArrayReducer::or()($callbacks, $value, $key, $iterator) === CallbacksArrayReducer::or()($matchers, $value, $key, $iterator)
),
DropWhile::of()(static fn (bool $value): bool => false === $value),
Append::of()(false),
Head::of()
(new DropWhile())()(static fn (bool $value): bool => false === $value),
(new Append())()(false),
(new Head())()
);

// Point free style.
Expand Down
6 changes: 3 additions & 3 deletions src/Operation/Nth.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ static function (int $offset) use ($step): Closure {
static fn (array $value, int $key): bool => (($key % $step) === $offset);

/** @var Closure(Iterator<TKey, T>): Generator<TKey, T> $pipe */
$pipe = Pipe::of()(
Pack::of(),
$pipe = (new Pipe())()(
(new Pack())(),
(new Filter())()($filterCallback),
Unpack::of()
(new Unpack())()
);

// Point free style.
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __invoke(): Closure
*/
static function (iterable ...$iterables): Closure {
/** @var Closure(Iterator<TKey, T>): Generator<int, list<T|U>> $pipe */
$pipe = Pipe::of()(
$pipe = (new Pipe())()(
(
/**
* @param list<Iterator<UKey, U>> $iterables
Expand Down
6 changes: 3 additions & 3 deletions src/Operation/Random.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ static function (int $seed): Closure {
*/
static function (int $size) use ($seed): Closure {
/** @var Closure(Iterator<TKey, T>): Generator<TKey, T> $pipe */
$pipe = Pipe::of()(
Shuffle::of()($seed),
Limit::of()($size)(0)
$pipe = (new Pipe())()(
(new Shuffle())()($seed),
(new Limit())()($size)(0)
);

// Point free style.
Expand Down
4 changes: 2 additions & 2 deletions src/Operation/Reduce.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public function __invoke(): Closure
*/
static function ($initial) use ($callback): Closure {
/** @var Closure(Iterator<TKey, T>): Generator<TKey, W> $pipe */
$pipe = Pipe::of()(
$pipe = (new Pipe())()(
(new Reduction())()($callback)($initial),
Last::of(),
(new Last())(),
);

// Point free style.
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Scale.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static function (float $base = 0.0) use ($lowerBound, $upperBound, $wantedLowerB
$wantedLowerBound = (0.0 === $wantedLowerBound) ? (0.0 === $base ? 0.0 : 1.0) : $wantedLowerBound;
$wantedUpperBound = (1.0 === $wantedUpperBound) ? (0.0 === $base ? 1.0 : $base) : $wantedUpperBound;
/** @var callable(Generator<TKey, (float | int)>):Generator<TKey, float> $mapper */
$mapper = Map::of()(
$mapper = (new Map())()(
/**
* @param float|int $v
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Operation/ScanLeft.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class ScanLeft extends AbstractOperation
* @template V
* @template W
*
* @return Closure(callable((V|W)=, T=, TKey=, Iterator<TKey, T>=): W): Closure(V): Closure(Iterator<TKey, T>): Generator<int|TKey, V|W>
* @return Closure(callable(mixed=, T=, TKey=, Iterator<TKey, T>=): mixed): Closure(mixed): Closure(Iterator<TKey, T>): Generator<int|TKey, mixed>
*/
public function __invoke(): Closure
{
Expand All @@ -47,9 +47,9 @@ public function __invoke(): Closure
*/
static function ($initial) use ($callback): Closure {
/** @var Closure(Iterator<TKey, T>): Generator<int|TKey, V|W> $pipe */
$pipe = Pipe::of()(
Reduction::of()($callback)($initial),
Prepend::of()($initial)
$pipe = (new Pipe())()(
(new Reduction())()($callback)($initial),
(new Prepend())()($initial)
);

return $pipe;
Expand Down
10 changes: 5 additions & 5 deletions src/Operation/ScanLeft1.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class ScanLeft1 extends AbstractOperation
*
* @template V
*
* @return Closure(callable(T|V, T, TKey, Iterator<TKey, T>): V): Closure(Iterator<TKey, T>): Generator<int|TKey, T|V>
* @return Closure(callable(mixed, T, TKey, Iterator<TKey, T>): mixed): Closure(Iterator<TKey, T>): Generator<int|TKey, mixed>
*/
public function __invoke(): Closure
{
Expand All @@ -48,10 +48,10 @@ static function (Iterator $iterator) use ($callback): Iterator {
$initial = $iterator->current();

/** @var Closure(Iterator<TKey, T>): Generator<int|TKey, T|V> $pipe */
$pipe = Pipe::of()(
Tail::of(),
Reduction::of()($callback)($initial),
Prepend::of()($initial)
$pipe = (new Pipe())()(
(new Tail())(),
(new Reduction())()($callback)($initial),
(new Prepend())()($initial)
);

return $pipe($iterator);
Expand Down
Loading

0 comments on commit 323b4c8

Please sign in to comment.