aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2018-11-16 00:53:15 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2018-11-16 00:53:15 +0100
commit3c96e1e1819d3fe68d5986cc8cb268e7698e0ab9 (patch)
treefa5e59199f127b54e4f818c63d9d83efe574a400
parentAdd fmap instance for state monad. (diff)
downloadscheme-monad-3c96e1e1819d3fe68d5986cc8cb268e7698e0ab9.tar.gz
scheme-monad-3c96e1e1819d3fe68d5986cc8cb268e7698e0ab9.tar.xz
Add instance of fmap for <optional>.
-rw-r--r--data/optional.scm9
1 files changed, 7 insertions, 2 deletions
diff --git a/data/optional.scm b/data/optional.scm
index b008471..c90fec5 100644
--- a/data/optional.scm
+++ b/data/optional.scm
@@ -2,11 +2,11 @@
#:use-module (oop goops)
#:use-module (ice-9 match)
#:use-module (control monad)
+ #:use-module (data functor)
#:export (nothing just
nothing? just?
return-optional)
- ;; TODO is this reexport needed?
- #:re-export (>>=))
+ #:re-export (>>= >> fmap))
(define-class <optional> ()
(slot #:init-value #f
@@ -47,3 +47,8 @@
(nothing? b))
(nothing)
b))
+
+(define-method (fmap (f <procedure>)
+ (m <optional>))
+ (do x <- m
+ (return-optional (f x))))