diff --git a/library/optional.lisp b/library/optional.lisp index 7e38a3c0..4a001194 100644 --- a/library/optional.lisp +++ b/library/optional.lisp @@ -7,6 +7,7 @@ (#:cell #:coalton-library/cell) (#:iter #:coalton-library/iterator)) (:export + #:from-optional #:from-some #:some? #:none?)) @@ -23,6 +24,13 @@ ;; Optional ;; + (declare from-optional (:a -> (Optional :a) -> :a)) + (define (from-optional def opt) + "Get the value of OPT, or return DEF if OPT is None." + (match opt + ((Some x) x) + ((None) def))) + (declare from-some (String -> (Optional :a) -> :a)) (define (from-some str opt) "Get the value of OPT, erroring with the provided string if it is None." diff --git a/library/prelude.lisp b/library/prelude.lisp index f7756e22..937d86e6 100644 --- a/library/prelude.lisp +++ b/library/prelude.lisp @@ -130,10 +130,12 @@ (:import-from #:coalton-library/optional + #:from-optional #:from-some #:some? #:none?) (:export + #:from-optional #:from-some #:some? #:none?)