diff options
author | Silvan Mosberger <contact@infinisil.com> | 2023-02-07 06:16:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-07 06:16:09 +0100 |
commit | 0a60663e67fd32a27301aecad3a3bbca76932c39 (patch) | |
tree | a259a826abd7725ccb9097183e6202703d912225 /lib/lists.nix | |
parent | 4ee1a6c3ae9ebf58183e446aa53e5efaac34cbb3 (diff) | |
parent | 7c4abbf80e1471d7844aae825f6d1015ce315a48 (diff) |
Merge pull request #206611 from h7x4/lib-lists-add-repeat
lib.lists: add `replicate`
Diffstat (limited to 'lib/lists.nix')
-rw-r--r-- | lib/lists.nix | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/lists.nix b/lib/lists.nix index 9f69485b40862..2186cd4a79f60 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -303,6 +303,18 @@ rec { else genList (n: first + n) (last - first + 1); + /* Return a list with `n` copies of an element. + + Type: replicate :: int -> a -> [a] + + Example: + replicate 3 "a" + => [ "a" "a" "a" ] + replicate 2 true + => [ true true ] + */ + replicate = n: elem: genList (_: elem) n; + /* Splits the elements of a list in two lists, `right` and `wrong`, depending on the evaluation of a predicate. |