diff options
Diffstat (limited to 'stdlib/maybe.lisp')
| -rw-r--r-- | stdlib/maybe.lisp | 59 |
1 files changed, 25 insertions, 34 deletions
diff --git a/stdlib/maybe.lisp b/stdlib/maybe.lisp index 0bc7ac4..07adaee 100644 --- a/stdlib/maybe.lisp +++ b/stdlib/maybe.lisp @@ -1,60 +1,51 @@ ; LIB -(let! just (\[a] +(let! Maybe/just (\[a] ["maybe" "just" a])) -(let! nothing (\[] +(let! Maybe/nothing (\[] ["maybe" "nothing"])) -(let! unsafe-at (\[n seq] +(let! Maybe/#at (\[n seq] (match seq [] - (fatal! "unsafe-at out of bounds") + (fatal! "Maybe/#at out of bounds") otherwise (match n 0 (head seq) otherwise - (unsafe-at (- n 1) (tail seq)))))) + (Maybe/#at (- n 1) (tail seq)))))) -(let! unpack-just (unsafe-at 2)) -(let! kind (unsafe-at 1)) +(let! Maybe/unpack (Maybe/#at 2)) +(let! Maybe/kind (Maybe/#at 1)) -(let! map (\[f m] - (match (kind m) - "just" (just (f (unpack-just m))) - "nothing" (nothing)))) +(let! Maybe/map (\[f m] + (match (Maybe/kind m) + "just" (Maybe/just (f (Maybe/unpack m))) + "nothing" (Maybe/nothing)))) -(let! and-then (\[f m] - (match (kind m) - "just" (f (unpack-just m)) - "nothing" (nothing)))) +(let! Maybe/and-then (\[f m] + (match (Maybe/kind m) + "just" (f (Maybe/unpack m)) + "nothing" (Maybe/nothing)))) ; TESTING ;; (let! print-line! (\[s] ;; (print! (concat s "\n")))) -;; (let! a (just 10)) -;; (let! b (nothing)) +;; (let! a (Maybe/just 10)) +;; (let! b (Maybe/nothing)) -;; (map (+ 5) a) -;; (map (+ 5) b) +;; (Maybe/map (+ 5) a) +;; (Maybe/map (+ 5) b) -;; (and-then (\[n] (just (+ n 5))) a) -;; (and-then (\[n] (just (+ n 5))) b) +;; (Maybe/and-then (\[n] (Maybe/just (+ n 5))) a) +;; (Maybe/and-then (\[n] (Maybe/just (+ n 5))) b) -;; (let! m (just 10)) +;; (let! m (Maybe/just 10)) ;; (match m -;; (just _) -;; (print-line! (fmt "found just {0}!" [(unpack-just m)])) -;; (nothing) +;; (Maybe/just _) +;; (print-line! (fmt "found just {0}!" [(Maybe/unpack m)])) +;; (Maybe/nothing) ;; (print-line! "found nothing!")) - -(let! lazy exports [ - just - nothing - unpack-just - kind - map - and-then -]) |
