From f49f7842146fcec61f6e510b6c1bb2eb2a8e0027 Mon Sep 17 00:00:00 2001 From: Cristian Iosif Date: Thu, 29 Jun 2023 18:07:10 +0300 Subject: [PATCH] Add last method for collections --- src/Concerns/EnumerableMethods.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Concerns/EnumerableMethods.php b/src/Concerns/EnumerableMethods.php index 0cf94c8c..01633413 100644 --- a/src/Concerns/EnumerableMethods.php +++ b/src/Concerns/EnumerableMethods.php @@ -65,6 +65,19 @@ public function first(callable|null $callback = null, $default = null) return $this->items->first($callback, $default); } + /** + * @template TLastDefault + * + * @param null| (callable(TValue,TKey): bool) $callback + * @param TLastDefault|(\Closure(): TLastDefault) $default + * + * @return TValue|TLastDefault + */ + public function last(callable|null $callback = null, $default = null) + { + return $this->items->last($callback, $default); + } + /** * @param callable(TValue, TKey): mixed $callback *