diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2018-11-16 00:53:59 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2018-11-16 00:53:59 +0100 |
commit | 93237ba8a6100c035c99067151dc939397868e68 (patch) | |
tree | 542d53c189454392dbd8914130b905201adce1dc | |
parent | Add instance of fmap for <optional>. (diff) | |
download | scheme-monad-93237ba8a6100c035c99067151dc939397868e68.tar.gz scheme-monad-93237ba8a6100c035c99067151dc939397868e68.tar.xz |
Add from-just to (data optional).
-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) |