aboutsummaryrefslogtreecommitdiff
path: root/src/client/Utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/Utils')
-rw-r--r--src/client/Utils/Either.elm9
-rw-r--r--src/client/Utils/Maybe.elm9
-rw-r--r--src/client/Utils/Validation.elm21
3 files changed, 39 insertions, 0 deletions
diff --git a/src/client/Utils/Either.elm b/src/client/Utils/Either.elm
new file mode 100644
index 0000000..10c40e3
--- /dev/null
+++ b/src/client/Utils/Either.elm
@@ -0,0 +1,9 @@
+module Utils.Either
+ ( toMaybeError
+ ) where
+
+toMaybeError : Result a b -> Maybe a
+toMaybeError result =
+ case result of
+ Ok _ -> Nothing
+ Err x -> Just x
diff --git a/src/client/Utils/Maybe.elm b/src/client/Utils/Maybe.elm
new file mode 100644
index 0000000..507d9a4
--- /dev/null
+++ b/src/client/Utils/Maybe.elm
@@ -0,0 +1,9 @@
+module Utils.Maybe
+ ( isJust
+ ) where
+
+isJust : Maybe a -> Bool
+isJust maybe =
+ case maybe of
+ Just _ -> True
+ Nothing -> False
diff --git a/src/client/Utils/Validation.elm b/src/client/Utils/Validation.elm
new file mode 100644
index 0000000..0c1773e
--- /dev/null
+++ b/src/client/Utils/Validation.elm
@@ -0,0 +1,21 @@
+module Utils.Validation
+ ( validateNonEmpty
+ , validateNumber
+ ) where
+
+import String
+import Reads exposing (readInt)
+
+validateNonEmpty : String -> String -> Result String String
+validateNonEmpty message str =
+ if String.isEmpty str
+ then Err message
+ else Ok str
+
+validateNumber : String -> String -> Result String Int
+validateNumber message str =
+ case readInt str of
+ Just number ->
+ Ok number
+ Nothing ->
+ Err message