danielnarey/elm-toolkit/6.1.1

NOTE: this package is not compatible with Elm 0.19.1

Toolkit.Maybe

Helpers for error handling with multiple Maybe values

Zipping

zip : ( Maybe a, Maybe b ) -> Maybe ( a, b )

Given a 2-tuple of Maybe values, if both values are defined, return Just the 2-tuple of values; otherwise, return Nothing

(Just 1, Just 2)
  |> Toolkit.Maybe.zip


--> Just (1,2)


(Just 1, Nothing)
  |> Toolkit.Maybe.zip


--> Nothing
zip3 : ( Maybe a, Maybe b, Maybe c ) -> Maybe ( a, b, c )

Given a 3-tuple of Maybe values, if all three values are defined, return Just the 3-tuple of values; otherwise, return Nothing

zip4 : ( Maybe a, Maybe b, Maybe c, Maybe d ) -> Maybe ( a, b, c, d )

Given a 4-tuple of Maybe values, if all four values are defined, return Just the 4-tuple of values; otherwise, return Nothing

zipList : List (Maybe a) -> Maybe (List a)

Given a list of Maybe values, if all values are defined, return Just the list of values; otherwise, return Nothing. When passed an empty list, returns Just an empty list.

[Just 1, Just 2]
  |> Toolkit.Maybe.zipList


--> Just [1,2]


[Just 1, Nothing]
  |> Toolkit.Maybe.zipList


--> Nothing


[]
  |> Toolkit.Maybe.zipList


--> Just []

Filtering

filter : List (Maybe a) -> List a

Given a list of Maybe values, return a list containing only the defined values.

[ Just 1
, Just 2
, Nothing
]
  |> Toolkit.Maybe.filter


--> [1, 2]