summaryrefslogtreecommitdiff
path: root/test/program1.elm
diff options
context:
space:
mode:
Diffstat (limited to 'test/program1.elm')
-rw-r--r--test/program1.elm46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/program1.elm b/test/program1.elm
new file mode 100644
index 0000000..cf700a3
--- /dev/null
+++ b/test/program1.elm
@@ -0,0 +1,46 @@
+module Maybe exposing (Maybe(Just, Nothing), andThen, map, map2, map3, map4, map5, withDefault)
+
+
+type Maybe a
+ = Nothing
+ | Just a
+
+
+withDefault : a -> Maybe a -> a
+withDefault default maybe =
+ case maybe of
+ Just value ->
+ value
+
+ Nothing ->
+ default
+
+
+map : (a -> b) -> Maybe a -> Maybe b
+map f maybe =
+ case maybe of
+ Just value ->
+ Just (f value)
+
+ Nothing ->
+ Nothing
+
+
+map2 : (a -> b -> value) -> Maybe a -> Maybe b -> Maybe value
+map2 func ma mb =
+ case ( ma, mb ) of
+ ( Just a, Just b ) ->
+ Just (func a b)
+
+ _ ->
+ Nothing
+
+
+map3 : (a -> b -> c -> value) -> Maybe a -> Maybe b -> Maybe c -> Maybe value
+map3 func ma mb mc =
+ case ( ma, mb, mc ) of
+ ( Just a, Just b, Just c ) ->
+ Just (func a b c)
+
+ _ ->
+ Nothing