]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.runtime/scl/Prelude.scl
Added Prelude/maybe
[simantics/platform.git] / 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