Add primop genList
This can be used to implement functions like ‘imap’ (or for that matter, ‘map’) without the quadratic complexity incurred by calling ‘++’ repeatedly.
This commit is contained in:
parent
f3dda728a4
commit
50807f3dd5
3 changed files with 41 additions and 3 deletions
|
@ -54,8 +54,8 @@ rec {
|
|||
const = x: y: x;
|
||||
|
||||
range = first: last:
|
||||
if builtins.lessThan last first
|
||||
then []
|
||||
else [first] ++ range (builtins.add first 1) last;
|
||||
if first > last
|
||||
then []
|
||||
else genList (n: first + n) (last - first + 1);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue