From 4bd61d39280c064917fe517200482649cfc179ff Mon Sep 17 00:00:00 2001 From: Chris Gray Date: Thu, 17 Mar 2016 07:17:12 -0500 Subject: [PATCH] Make head and tail calls more memory efficient Used array_slice as opposed to using array_pop/array_shift to keep a copy of the source array from being created --- src/array.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/array.php b/src/array.php index 83bcbca..2cd22ee 100644 --- a/src/array.php +++ b/src/array.php @@ -27,7 +27,7 @@ function grab(array $source, $keys) */ function head(array $list) { - return array_shift($list); + return $list ? current(array_slice($list, 0, 1)) : null; } /** @@ -39,5 +39,5 @@ function head(array $list) */ function tail(array $list) { - return array_pop($list); + return $list ? current(array_slice($list, -1, 1)) : null; }