From 71a556ce81726908aad08e0d2428486a5b9b61af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Rowicki?= <35342116+radrow@users.noreply.github.com> Date: Fri, 30 Aug 2019 13:46:02 +0200 Subject: [PATCH] nth update --- priv/stdlib/List.aes | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/priv/stdlib/List.aes b/priv/stdlib/List.aes index 2113bc4..57d2250 100644 --- a/priv/stdlib/List.aes +++ b/priv/stdlib/List.aes @@ -38,16 +38,14 @@ namespace List = h::t => find_indices_(p, t, n+1, if(p(h)) n::acc else acc) function nth(n : int, l : list('a)) : option('a) = - if(n < 0) None - else switch(l) + switch(l) [] => None h::t => if(n == 0) Some(h) else nth(n-1, t) /* Unsafe version of `nth` */ function get(n : int, l : list('a)) : 'a = - if(n < 0) abort("Negative index get") - else switch(l) - [] => abort("Out of index get") + switch(l) + [] => abort(if(n < 0) "Negative index get" else "Out of index get") h::t => if(n == 0) h else get(n-1, t)