Skip to content

Commit

Permalink
Use FoldLeft in "Last" transformation.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed May 28, 2020
1 parent 18d20d7 commit ff1f702
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/Transformation/Last.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ final class Last implements Transformation
*/
public function on(iterable $collection)
{
$return = null;

foreach ($collection as $value) {
$return = $value;
}

return $return;
return (
new FoldLeft(
static function ($carry, $item) {
return $item;
}
)
)->on($collection);
}
}
2 changes: 1 addition & 1 deletion src/Transformation/Transform.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class Transform implements Transformation
private $transformers;

/**
* Run constructor.
* Transform constructor.
*
* @param \loophp\collection\Contract\Transformation ...$transformers
*/
Expand Down

0 comments on commit ff1f702

Please sign in to comment.