3{-| Represents any data that can take two different types.
9@docs either, isLeft, isRight
12@docs lefts, rights, partition
18{-| Represents any data may take two forms. For example, a user ID may be
19either an `Int` or a `String`.
21This can also be used for error handling `(Either String a)` where
22error messages are stored on the left, and the correct values
23(“right” values) are stored on the right.
25data Either a b = Left a | Right b
27{-| Apply the first function to a `Left` and the second function to a `Right`.
28This allows the extraction of a value from an `Either`.
30either : (a -> c) -> (b -> c) -> Either a b -> c
31either f g e = case e of { Left x -> f x ; Right y -> g y }
33{-| True if the value is a `Left`. -}
34isLeft : Either a b -> Bool
35isLeft e = case e of { Left _ -> True ; _ -> False }
37{-| True if the value is a `Right`. -}
38isRight : Either a b -> Bool
39isRight e = case e of { Right _ -> True ; _ -> False }
41{-| Keep only the values held in `Left` values. -}
42lefts : [Either a b] -> [a]
43lefts es = List.foldr consLeft [] es
45{-| Keep only the values held in `Right` values. -}
46rights : [Either a b] -> [b]
47rights es = List.foldr consRight [] es
49{-| Split into two lists, lefts on the left and rights on the right. So we
50have the equivalence: `(partition es == (lefts es, rights es))`
52partition : [Either a b] -> ([a],[b])
53partition es = List.foldr consEither ([],[]) es
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list