Skip to content

Commit

Permalink
Minor changes here and there.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Dec 26, 2019
1 parent 9fe3d5a commit 97769de
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
12 changes: 6 additions & 6 deletions src/Operation/Until.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ final class Until implements Operation
/**
* Until constructor.
*
* @param callable $until
* @param callable $callable
*/
public function __construct(callable $until)
public function __construct(callable $callable)
{
$this->callable = $until;
$this->callable = $callable;
}

/**
* {@inheritdoc}
*/
public function on(iterable $collection): Closure
{
$until = $this->callable;
$callable = $this->callable;

return static function () use ($until, $collection): Generator {
return static function () use ($callable, $collection): Generator {
foreach ($collection as $key => $value) {
yield $key => $value;

if (true === $until($value, $key)) {
if (true === $callable($value, $key)) {
break;
}
}
Expand Down
19 changes: 5 additions & 14 deletions src/Transformation/Last.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,12 @@ final class Last implements Transformation
*/
public function on(iterable $collection)
{
$iterator = new ClosureIterator(
static function () use ($collection): Generator {
foreach ($collection as $key => $value) {
yield $key => $value;
}
}
);
$value = null;

$reduced = new Reduce(
static function ($carry, $item) {
return $item;
},
$iterator->current()
);
foreach ($collection as $key => $value) {

return $reduced->on($collection);
}

return $value;
}
}

0 comments on commit 97769de

Please sign in to comment.