Skip to content

Commit

Permalink
refactor: Minor documentation changes.
Browse files Browse the repository at this point in the history
drupol committed Jan 1, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 37593eb commit 7957e26
Showing 4 changed files with 14 additions and 18 deletions.
6 changes: 4 additions & 2 deletions spec/loophp/collection/CollectionSpec.php
Original file line number Diff line number Diff line change
@@ -1970,6 +1970,10 @@ static function ($carry, $item) {

public function it_can_reverse(): void
{
$this::empty()
->reverse()
->shouldIterateAs([]);

$this::fromIterable(range('A', 'F'))
->reverse()
->shouldIterateAs([5 => 'F', 4 => 'E', 3 => 'D', 2 => 'C', 1 => 'B', 0 => 'A']);
@@ -2473,7 +2477,6 @@ public function it_can_unpack(): void
['c', 'c'],
['d', 'd'],
['e', 'e'],
'bar',
];

$this::fromIterable($input)
@@ -2490,7 +2493,6 @@ public function it_can_unpack(): void
['a', 'b', 'c' => 'c', 'd' => 'd'],
['e', 'f', 'g' => 'g', 'h' => 'h'],
['i', 'j'],
'foo',
];

$this::fromIterable($input)
4 changes: 2 additions & 2 deletions src/Operation/Pack.php
Original file line number Diff line number Diff line change
@@ -22,11 +22,11 @@ public function __invoke(): Closure
{
$mapCallback =
/**
* @param mixed $value
* @psalm-param T $value
* @psalm-param TKey $key
*
* @param mixed $value
* @param mixed $key
* @psalm-param TKey $key
*
* @psalm-return array{0: TKey, 1: T}
*/
8 changes: 6 additions & 2 deletions src/Operation/Reverse.php
Original file line number Diff line number Diff line change
@@ -9,6 +9,10 @@
use Iterator;

/**
* @todo Remove the Wrap and Unwrap operations
* @todo They are only needed when: Collection::empty()->reverse()
* @todo Most probably that the FoldLeft operation needs an update.
*
* @psalm-template TKey
* @psalm-template TKey of array-key
* @psalm-template T
@@ -37,9 +41,9 @@ public function __invoke(): Closure
$pipe = Pipe::of()(
Pack::of(),
Wrap::of(),
FoldLeft1::of()($callback),
FoldLeft::of()($callback)([]),
Unwrap::of(),
Unpack::of()
Unpack::of(),
);

// Point free style.
14 changes: 2 additions & 12 deletions src/Operation/Unpack.php
Original file line number Diff line number Diff line change
@@ -23,40 +23,30 @@ final class Unpack extends AbstractOperation
*/
public function __invoke(): Closure
{
$isIterable =
/**
* @param mixed $value
* @psalm-param T $value
*/
static fn ($value): bool => is_iterable($value);

$toIterableIterator = static fn (iterable $value): Iterator => new IterableIterator($value);

$callbackForKeys =
/**
* @param mixed $initial
* @psalm-param T $initial
* @psalm-param array{0: TKey, 1: T} $value
*
* @psalm-return TKey
*
* @param mixed $initial
*/
static fn ($initial, int $key, array $value) => $value[0];

$callbackForValues =
/**
* @param mixed $initial
* @psalm-param T $initial
* @psalm-param array{0: TKey, 1: T} $value
*
* @psalm-return T
*
* @param mixed $initial
*/
static fn ($initial, int $key, array $value) => $value[1];

/** @psalm-var Closure(Iterator<int, array{0: TKey, 1: T}>): Generator<T, T> $pipe */
$pipe = Pipe::of()(
Filter::of()($isIterable),
Map::of()($toIterableIterator, Chunk::of()(2)),
Unwrap::of(),
Associate::of()($callbackForKeys)($callbackForValues)

0 comments on commit 7957e26

Please sign in to comment.