diff options
-rw-r--r-- | data/optional.scm | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/data/optional.scm b/data/optional.scm index c90fec5..4130bab 100644 --- a/data/optional.scm +++ b/data/optional.scm @@ -5,6 +5,7 @@ #:use-module (data functor) #:export (nothing just nothing? just? + from-just return-optional) #:re-export (>>= >> fmap)) @@ -26,6 +27,12 @@ (define (just? this) (not (nothing? this))) +(define (from-just default maybe-val) + "Returns default if maybe-val is nothing, otherwise +the value embedded in maybe-val" + (if (just? maybe-val) + (slot-ref maybe-val 'slot) + default)) (define-method (write (this <optional>) port) (if (just? this) |