Updated some functions, renamed some stuff, added from_to IN STDLIB #627
@ -38,16 +38,14 @@ namespace List =
|
|||||||
h::t => find_indices_(p, t, n+1, if(p(h)) n::acc else acc)
|
h::t => find_indices_(p, t, n+1, if(p(h)) n::acc else acc)
|
||||||
|
|
||||||
function nth(n : int, l : list('a)) : option('a) =
|
function nth(n : int, l : list('a)) : option('a) =
|
||||||
if(n < 0) None
|
switch(l)
|
||||||
else switch(l)
|
|
||||||
[] => None
|
[] => None
|
||||||
h::t => if(n == 0) Some(h) else nth(n-1, t)
|
h::t => if(n == 0) Some(h) else nth(n-1, t)
|
||||||
|
|
||||||
/* Unsafe version of `nth` */
|
/* Unsafe version of `nth` */
|
||||||
function get(n : int, l : list('a)) : 'a =
|
function get(n : int, l : list('a)) : 'a =
|
||||||
if(n < 0) abort("Negative index get")
|
switch(l)
|
||||||
else switch(l)
|
[] => abort(if(n < 0) "Negative index get" else "Out of index get")
|
||||||
[] => abort("Out of index get")
|
|
||||||
h::t => if(n == 0) h else get(n-1, t)
|
h::t => if(n == 0) h else get(n-1, t)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user