]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Added Prelude/maybe 75/1875/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 21 Jun 2018 15:01:28 +0000 (18:01 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 21 Jun 2018 15:01:28 +0000 (18:01 +0300)
`maybe def f v` returns `def` if `v=Nothing` and `f x` if `v=Just x`.

gitlab #31

Change-Id: I3319ee8e9e4cf678aece4878c1fb2ddf33395bc4

bundles/org.simantics.scl.runtime/scl/Prelude.scl

index 751294a11bb44ea03df62391d7120c83bf9a1a0c..03eabb66fb8ecd2ff7218fa5191db648350ee280 100644 (file)
@@ -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 -> <e> b) -> Maybe a -> <e> 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