From 93237ba8a6100c035c99067151dc939397868e68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Fri, 16 Nov 2018 00:53:59 +0100 Subject: Add from-just to (data optional). --- data/optional.scm | 7 +++++++ 1 file changed, 7 insertions(+) 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 ) port) (if (just? this) -- cgit v1.2.3