aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Utils/Maybe.elm
blob: 4a94aa50b606e7ee2919980ed69c727e9d4d94c9 (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 exposing
  ( isJust
  , catMaybes
  , maybeToList
  )

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 -> []