From: Tuukka Lehtonen Date: Thu, 21 Jun 2018 15:01:28 +0000 (+0300) Subject: Added Prelude/maybe X-Git-Tag: v1.43.0~136^2~453 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=77e4291d372e7b4b40ee868ad61cc07c51de8c6b;p=simantics%2Fplatform.git Added Prelude/maybe `maybe def f v` returns `def` if `v=Nothing` and `f x` if `v=Just x`. gitlab #31 Change-Id: I3319ee8e9e4cf678aece4878c1fb2ddf33395bc4 --- diff --git a/bundles/org.simantics.scl.runtime/scl/Prelude.scl b/bundles/org.simantics.scl.runtime/scl/Prelude.scl index 751294a11..03eabb66f 100644 --- a/bundles/org.simantics.scl.runtime/scl/Prelude.scl +++ b/bundles/org.simantics.scl.runtime/scl/Prelude.scl @@ -1290,8 +1290,12 @@ fromMaybe :: a -> Maybe a -> a fromMaybe default maybeValue = match maybeValue with Just v -> v _ -> default - - + +"`maybe def f v` returns `def` if `v=Nothing` and `f x` if `v=Just x`." +maybe :: b -> (a -> b) -> Maybe a -> b +maybe n _ Nothing = n +maybe _ f (Just x) = f x + """ Provides a default value if the first parameter is Nothing. The default value is evaluated only if needed. The function