diff options
Diffstat (limited to 'lib/lists.nix')
| -rw-r--r-- | lib/lists.nix | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/lists.nix b/lib/lists.nix index e119606dd5e7..ec0fe22d2afa 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -1463,6 +1463,40 @@ rec { take = count: sublist 0 count; /** + Return the last (at most) N elements of a list. + + # Inputs + + `count` + + : Maximum number of elements to pick + + `list` + + : Input list + + # Type + + ``` + takeEnd :: int -> [a] -> [a] + ``` + + # Examples + :::{.example} + ## `lib.lists.takeEnd` usage example + + ```nix + takeEnd 2 [ "a" "b" "c" "d" ] + => [ "c" "d" ] + takeEnd 2 [ ] + => [ ] + ``` + + ::: + */ + takeEnd = n: xs: drop (max 0 (length xs - n)) xs; + + /** Remove the first (at most) N elements of a list. # Inputs |
