aboutsummaryrefslogtreecommitdiffstats
path: root/core/common.milch
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2022-12-06 21:18:18 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2022-12-06 21:36:54 +0200
commit6b9782ce4a36e93156426b5747efcc90401b6251 (patch)
tree3a7c68ee5eb3a03ec00a0dd850bb8512eec5b84a /core/common.milch
parent35bf45fe54788c6fca6b105b65fc1622a4bb7d34 (diff)
Add core/result.milch
Diffstat (limited to 'core/common.milch')
-rw-r--r--core/common.milch11
1 files changed, 9 insertions, 2 deletions
diff --git a/core/common.milch b/core/common.milch
index 55fa2b8..2aa72a2 100644
--- a/core/common.milch
+++ b/core/common.milch
@@ -141,11 +141,18 @@
(let split-by (\[delim vals]
(_split-by delim [] vals)))
-(let at (\[n seq]
+(let at! (\![n seq]
(match seq
- [] (fatal! (fmt "at out of bounds, n: {0}" [n]))
+ [] (fatal! (fmt "at out of bounds, index: {0}" [n]))
otherwise (match n
0 (head seq)
+ otherwise (at! (- n 1) (tail seq))))))
+
+(let at (\[n seq]
+ (match seq
+ [] (Result/ex (fmt "at out of bounds, index: {0}" [n]))
+ otherwise (match n
+ 0 (Result/ok (head seq))
otherwise (at (- n 1) (tail seq))))))
(let maximum (\[vals]