diff --git a/src/Traits/ArrayPrefix.php b/src/Traits/ArrayPrefix.php index a1f372d..0d9cb4f 100644 --- a/src/Traits/ArrayPrefix.php +++ b/src/Traits/ArrayPrefix.php @@ -97,7 +97,8 @@ public function head(bool $preserveKeys = false) public function tail(): ArrayedInterface { - return $this->slice(1); + return $this->when($this->getWorkableItem()) + ->slice(1); } private function when($truthyValue, $default = Undefined::class) diff --git a/tests/ArrayPrefixTraitTest.php b/tests/ArrayPrefixTraitTest.php index 91cd397..bb2f701 100644 --- a/tests/ArrayPrefixTraitTest.php +++ b/tests/ArrayPrefixTraitTest.php @@ -214,5 +214,10 @@ public function testTail(): void ['c' => 'd'], arrayed($data)->tail()->result(), ); + + // Test empty. + $this->expectException(\InvalidArgumentException::class); + + arrayed([])->tail(); } }