From 6b9782ce4a36e93156426b5747efcc90401b6251 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Tue, 6 Dec 2022 21:18:18 +0200 Subject: Add core/result.milch --- core/common.milch | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'core/common.milch') 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] -- cgit v1.3