aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Utils/Maybe.elm
blob: d954ae0758cea0ad8600418679dc7128825d8dd7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module Utils.Maybe
  ( isJust
  , catMaybes
  , maybeToList
  ) where

isJust : Maybe a -> Bool
isJust maybe =
  case maybe of
    Just _  -> True
    Nothing -> False

catMaybes : List (Maybe a) -> List a
catMaybes =
  List.foldr
    (\mb xs ->
      case mb of
        Just x  -> x :: xs
        Nothing -> xs
    )
    []

maybeToList : Maybe a -> List a
maybeToList mb =
  case mb of
    Just a  -> [a]
    Nothing -> []