mirror of
https://github.com/SebastianWendel/nixpkgs.git
synced 2024-09-20 04:19:00 +02:00
Merge pull request #206611 from h7x4/lib-lists-add-repeat
lib.lists: add `replicate`
This commit is contained in:
commit
0a60663e67
|
@ -88,7 +88,7 @@ let
|
||||||
updateManyAttrsByPath;
|
updateManyAttrsByPath;
|
||||||
inherit (self.lists) singleton forEach foldr fold foldl foldl' imap0 imap1
|
inherit (self.lists) singleton forEach foldr fold foldl foldl' imap0 imap1
|
||||||
concatMap flatten remove findSingle findFirst any all count
|
concatMap flatten remove findSingle findFirst any all count
|
||||||
optional optionals toList range partition zipListsWith zipLists
|
optional optionals toList range replicate partition zipListsWith zipLists
|
||||||
reverseList listDfs toposort sort naturalSort compareLists take
|
reverseList listDfs toposort sort naturalSort compareLists take
|
||||||
drop sublist last init crossLists unique intersectLists
|
drop sublist last init crossLists unique intersectLists
|
||||||
subtractLists mutuallyExclusive groupBy groupBy';
|
subtractLists mutuallyExclusive groupBy groupBy';
|
||||||
|
|
|
@ -303,6 +303,18 @@ rec {
|
||||||
else
|
else
|
||||||
genList (n: first + n) (last - first + 1);
|
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
|
/* Splits the elements of a list in two lists, `right` and
|
||||||
`wrong`, depending on the evaluation of a predicate.
|
`wrong`, depending on the evaluation of a predicate.
|
||||||
|
|
||||||
|
|
|
@ -479,6 +479,11 @@ runTests {
|
||||||
expected = [2 30 40 42];
|
expected = [2 30 40 42];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
testReplicate = {
|
||||||
|
expr = replicate 3 "a";
|
||||||
|
expected = ["a" "a" "a"];
|
||||||
|
};
|
||||||
|
|
||||||
testToIntShouldConvertStringToInt = {
|
testToIntShouldConvertStringToInt = {
|
||||||
expr = toInt "27";
|
expr = toInt "27";
|
||||||
expected = 27;
|
expected = 27;
|
||||||
|
|
Loading…
Reference in a new issue