mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-10 19:55:41 +03:00
Merge pull request #206611 from h7x4/lib-lists-add-repeat
lib.lists: add `replicate`
This commit is contained in:
commit
0a60663e67
3 changed files with 18 additions and 1 deletions
|
@ -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.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue