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
|
in
|
||||||
qs list [];
|
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;
|
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 = {
|
testOverridableDelayableArgsTest = {
|
||||||
expr =
|
expr =
|
||||||
let res1 = defaultOverridableDelayableArgs id {};
|
let res1 = defaultOverridableDelayableArgs id {};
|
||||||
|
|
Loading…
Reference in New Issue