Skip to content

Commit

Permalink
refactor: Minor optimization, remove return keyword.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jan 3, 2022
1 parent 782a48e commit 7683362
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/Operation/Chunk.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static function (Iterator $iterator) use ($sizes): Generator {
$size = $sizesIterator->current();

if (0 >= $size) {
return new EmptyIterator();
return yield [];
}

if (count($values) !== $size) {
Expand All @@ -69,7 +69,7 @@ static function (Iterator $iterator) use ($sizes): Generator {
$values = [$value];
}

return yield $values;
yield $values;
};
}
}
2 changes: 1 addition & 1 deletion src/Operation/Equals.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static function (Iterator $other): Closure {
*/
static fn ($current): bool => (new Contains())()($current)($other)->current();

return yield from (new Every())()(static fn (): bool => false)($containsCallback)($iterator);
yield from (new Every())()(static fn (): bool => false)($containsCallback)($iterator);
};
};
}
Expand Down
11 changes: 4 additions & 7 deletions src/Operation/Head.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,28 @@ final class Head extends AbstractOperation
/**
* @pure
*
* @return Closure(Iterator<TKey, T>): Generator<TKey, T>
* @return Closure(Iterator<TKey, T>): Generator<TKey, T, mixed, void>
*/
public function __invoke(): Closure
{
return
/**
* @param Iterator<TKey, T> $iterator
*
* @return Generator<TKey, T>
* @return Generator<TKey, T, mixed, void>
*/
static function (Iterator $iterator): Generator {
$isEmpty = true;

$key = $current = null;
foreach ($iterator as $key => $current) {
$isEmpty = false;

break;
}

if (false === $isEmpty) {
/**
* @var TKey $key
* @var T $current
*/
return yield $key => $current;
yield $key => $current;
}
};
}
Expand Down
7 changes: 2 additions & 5 deletions src/Operation/Last.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,13 @@ public function __invoke(): Closure
static function (Iterator $iterator): Generator {
$isEmpty = true;

$key = $current = null;
foreach ($iterator as $key => $current) {
$isEmpty = false;
}

if (false === $isEmpty) {
/**
* @var TKey $key
* @var T $current
*/
return yield $key => $current;
yield $key => $current;
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Pack.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static function (Iterator $iterator): Generator {
/** @var PackIterableAggregate<TKey, T> $packIterableAggregate */
$packIterableAggregate = new PackIterableAggregate($iterator);

return yield from $packIterableAggregate->getIterator();
yield from $packIterableAggregate->getIterator();
};
}
}
2 changes: 1 addition & 1 deletion src/Operation/Same.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static function (Iterator $iterator) use ($other, $comparatorCallback): Generato
$other->next();
}

return yield $iterator->valid() === $other->valid();
yield $iterator->valid() === $other->valid();
};
}
}
2 changes: 1 addition & 1 deletion src/Operation/Tails.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static function (Iterator $iterator): Generator {
array_shift($data);
}

return yield [];
yield [];
};
}
}

0 comments on commit 7683362

Please sign in to comment.