Skip to content

Commit

Permalink
feat: Implement tail method
Browse files Browse the repository at this point in the history
  • Loading branch information
omitobi committed Apr 29, 2024
1 parent 740ffd3 commit 1e96128
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Traits/ArrayPrefix.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public function head(bool $preserveKeys = false): ArrayedInterface
return $this->slice(0, 1, $preserveKeys);
}

public function tail(): ArrayedInterface
{
return $this->slice(1);
}

/**
* Forward the calls to `array_*` that is not yet implemented
* <br>
Expand Down
17 changes: 17 additions & 0 deletions tests/ArrayPrefixTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,21 @@ public function testHead(): void
arrayed($data)->head()->result(),
);
}

public function testTail(): void
{
$data = ['a', 'b', 'c', 'd'];

$this->assertSame(
['b', 'c', 'd'],
arrayed($data)->tail()->result(),
);

$data = ['a' => 'b', 'c' => 'd'];

$this->assertSame(
['c' => 'd'],
arrayed($data)->tail()->result(),
);
}
}

0 comments on commit 1e96128

Please sign in to comment.