on master help sign in
Remove weird cons functions and make documentation nicer.
commit83406ff73acdda012678bf180fb289119cc3a514 authorEvan Czaplicki <info@elm-lang.org> dateThu 17 Oct 2013, 23:54 (13 years ago) parent5b2ba67
2 files changed+11−11
libraries/Either.elm+6−6 libraries/Maybe.elm+5−5
libraries/Either.elm+6−6
@@ -9,7 +9,7 @@ module Either where
99@docs either, isLeft, isRight
1010
1111# Eithers and Lists
12−@docs lefts, rights, partition, consLeft, consRight, consEither
12+@docs lefts, rights, partition
1313
1414-}
1515
@@ -25,7 +25,7 @@ error messages are stored on the left, and the correct values
2525data Either a b = Left a | Right b
2626
2727{-| Apply the first function to a `Left` and the second function to a `Right`.
28− This allows the extraction of a value from an `Either`.
28+This allows the extraction of a value from an `Either`.
2929-}
3030either : (a -> c) -> (b -> c) -> Either a b -> c
3131either f g e = case e of { Left x -> f x ; Right y -> g y }
@@ -47,13 +47,13 @@ rights : [Either a b] -> [b]
4747rights es = List.foldr consRight [] es
4848
4949{-| Split into two lists, lefts on the left and rights on the right. So we
50− have the equivalence: `(partition es == (lefts es, rights es))`
50+have the equivalence: `(partition es == (lefts es, rights es))`
5151-}
5252partition : [Either a b] -> ([a],[b])
5353partition es = List.foldr consEither ([],[]) es
5454
5555{-| If `Left`, add the value to the front of the list.
56− If `Right`, return the list unchanged
56+If `Right`, return the list unchanged
5757-}
5858consLeft : Either a b -> [a] -> [a]
5959consLeft e vs =
@@ -62,7 +62,7 @@ consLeft e vs =
6262 Right _ -> vs
6363
6464{-| If `Right`, add the value to the front of the list.
65− If `Left`, return the list unchanged.
65+If `Left`, return the list unchanged.
6666-}
6767consRight : Either a b -> [b] -> [b]
6868consRight e vs =
@@ -71,7 +71,7 @@ consRight e vs =
7171 Right v -> v::vs
7272
7373{-| If `Left`, add the value to the left list.
74− If `Right`, add the value to the right list.
74+If `Right`, add the value to the right list.
7575-}
7676consEither : Either a b -> ([a], [b]) -> ([a], [b])
7777consEither e (ls,rs) =
libraries/Maybe.elm+5−5
@@ -9,20 +9,20 @@ module Maybe where
99@docs maybe, isJust, isNothing
1010
1111# Maybes and Lists
12−@docs cons, justs
12+@docs justs
1313-}
1414
1515import Basics (not, (.))
1616import List (foldr)
1717
1818{-| The Maybe datatype. Useful when a computation may or may not
19− result in a value (e.g. logarithm is defined only for positive
20− numbers).
19+result in a value (e.g. logarithm is defined only for positive
20+numbers).
2121-}
2222data Maybe a = Just a | Nothing
2323
2424{-| Apply a function to the contents of a `Maybe`.
25− Return default when given `Nothing`.
25+Return default when given `Nothing`.
2626-}
2727maybe : b -> (a -> b) -> Maybe a -> b
2828maybe b f m = case m of
@@ -41,7 +41,7 @@ isNothing = not . isJust
4141
4242
4343{-| If `Just`, adds the value to the front of the list.
44− If `Nothing`, list is unchanged.
44+If `Nothing`, list is unchanged.
4545-}
4646cons : Maybe a -> [a] -> [a]
4747cons mx xs = maybe xs (\x -> x :: xs) mx