Skip to content

Commit

Permalink
feat: Ensure tail must have array values to work with
Browse files Browse the repository at this point in the history
  • Loading branch information
omitobi committed Apr 29, 2024
1 parent e53c765 commit c8433ce
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Traits/ArrayPrefix.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions tests/ArrayPrefixTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,10 @@ public function testTail(): void
['c' => 'd'],
arrayed($data)->tail()->result(),
);

// Test empty.
$this->expectException(\InvalidArgumentException::class);

arrayed([])->tail();
}
}

0 comments on commit c8433ce

Please sign in to comment.