mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-25 16:33:15 +00:00
nixpkgs lib: adding haskell's take
svn path=/nixpkgs/trunk/; revision=18848
This commit is contained in:
parent
89b59e3fbc
commit
7ef915ebc8
@ -161,4 +161,10 @@ rec {
|
||||
in
|
||||
qs list [];
|
||||
|
||||
|
||||
# haskell's take: take 2 [1 2 3 4] yields [1 2]
|
||||
take = count: list:
|
||||
if list == [] || count == 0 then []
|
||||
else [ (head list) ] ++ take (builtins.sub count 1) (tail list);
|
||||
|
||||
}
|
||||
|
@ -61,6 +61,15 @@ runTests {
|
||||
expected = true;
|
||||
};
|
||||
|
||||
testTake = testAllTrue [
|
||||
([] == (take 0 [ 1 2 3 ]))
|
||||
([1] == (take 1 [ 1 2 3 ]))
|
||||
([ 1 2 ] == (take 2 [ 1 2 3 ]))
|
||||
([ 1 2 3 ] == (take 3 [ 1 2 3 ]))
|
||||
([ 1 2 3 ] == (take 4 [ 1 2 3 ]))
|
||||
];
|
||||
|
||||
|
||||
testOverridableDelayableArgsTest = {
|
||||
expr =
|
||||
let res1 = defaultOverridableDelayableArgs id {};
|
||||
|
Loading…
Reference in New Issue
Block a user