aboutsummaryrefslogtreecommitdiff
path: root/src/Utils/Maybe.elm
blob: db25bff310a931d0578884e1a9082dde53121a36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module Utils.Maybe exposing
  ( filterMaybe
  , orElse
  )

filterMaybe : (a -> Bool) -> Maybe a -> Maybe a
filterMaybe cond maybe =
  case maybe of
    Just x ->
      if cond x
        then Just x
        else Nothing
    Nothing ->
      Nothing

orElse : Maybe a -> Maybe a -> Maybe a
orElse mb1 mb2 =
  case mb1 of
    Just x -> Just x
    Nothing -> mb2