From ff1f702b73a03ddf5877d9caabeb82056eb18705 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 28 May 2020 09:43:55 +0200 Subject: [PATCH] Use FoldLeft in "Last" transformation. --- src/Transformation/Last.php | 14 +++++++------- src/Transformation/Transform.php | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Transformation/Last.php b/src/Transformation/Last.php index 7e233824c..5748be408 100644 --- a/src/Transformation/Last.php +++ b/src/Transformation/Last.php @@ -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); } } diff --git a/src/Transformation/Transform.php b/src/Transformation/Transform.php index 9a81df5a0..030cf7d10 100644 --- a/src/Transformation/Transform.php +++ b/src/Transformation/Transform.php @@ -17,7 +17,7 @@ final class Transform implements Transformation private $transformers; /** - * Run constructor. + * Transform constructor. * * @param \loophp\collection\Contract\Transformation ...$transformers */