on master help sign in
Remove weird cons functions and make documentation nicer.
83406ffEvan Czaplicki
libraries/Either.elm+6−6
@@ -9,7 +9,7 @@ module Either where
9@docs either, isLeft, isRight
9@docs either, isLeft, isRight
10
10
11# Eithers and Lists
11# Eithers and Lists
12−@docs lefts, rights, partition, consLeft, consRight, consEither
12+@docs lefts, rights, partition
13
13
14-}
14-}
15
15
@@ -25,7 +25,7 @@ error messages are stored on the left, and the correct values
25data Either a b = Left a | Right b
25data Either a b = Left a | Right b
26
26
27{-| Apply the first function to a `Left` and the second function to a `Right`.
27{-| 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`.
29-}
29-}
30either : (a -> c) -> (b -> c) -> Either a b -> c
30either : (a -> c) -> (b -> c) -> Either a b -> c
31either f g e = case e of { Left x -> f x ; Right y -> g y }
31either f g e = case e of { Left x -> f x ; Right y -> g y }
@@ -47,13 +47,13 @@ rights : [Either a b] -> [b]
47rights es = List.foldr consRight [] es
47rights es = List.foldr consRight [] es
48
48
49{-| Split into two lists, lefts on the left and rights on the right. So we
49{-| 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))`
51-}
51-}
52partition : [Either a b] -> ([a],[b])
52partition : [Either a b] -> ([a],[b])
53partition es = List.foldr consEither ([],[]) es
53partition es = List.foldr consEither ([],[]) es
54
54
55{-| If `Left`, add the value to the front of the list.
55{-| 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
57-}
57-}
58consLeft : Either a b -> [a] -> [a]
58consLeft : Either a b -> [a] -> [a]
59consLeft e vs =
59consLeft e vs =
@@ -62,7 +62,7 @@ consLeft e vs =
62 Right _ -> vs
62 Right _ -> vs
63
63
64{-| If `Right`, add the value to the front of the list.
64{-| 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.
66-}
66-}
67consRight : Either a b -> [b] -> [b]
67consRight : Either a b -> [b] -> [b]
68consRight e vs =
68consRight e vs =
@@ -71,7 +71,7 @@ consRight e vs =
71 Right v -> v::vs
71 Right v -> v::vs
72
72
73{-| If `Left`, add the value to the left list.
73{-| 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.
75-}
75-}
76consEither : Either a b -> ([a], [b]) -> ([a], [b])
76consEither : Either a b -> ([a], [b]) -> ([a], [b])
77consEither e (ls,rs) =
77consEither e (ls,rs) =
libraries/Maybe.elm+5−5
@@ -9,20 +9,20 @@ module Maybe where
9@docs maybe, isJust, isNothing
9@docs maybe, isJust, isNothing
10
10
11# Maybes and Lists
11# Maybes and Lists
12−@docs cons, justs
12+@docs justs
13-}
13-}
14
14
15import Basics (not, (.))
15import Basics (not, (.))
16import List (foldr)
16import List (foldr)
17
17
18{-| The Maybe datatype. Useful when a computation may or may not
18{-| The Maybe datatype. Useful when a computation may or may not
19− result in a value (e.g. logarithm is defined only for positive
19+result in a value (e.g. logarithm is defined only for positive
20− numbers).
20+numbers).
21-}
21-}
22data Maybe a = Just a | Nothing
22data Maybe a = Just a | Nothing
23
23
24{-| Apply a function to the contents of a `Maybe`.
24{-| Apply a function to the contents of a `Maybe`.
25− Return default when given `Nothing`.
25+Return default when given `Nothing`.
26-}
26-}
27maybe : b -> (a -> b) -> Maybe a -> b
27maybe : b -> (a -> b) -> Maybe a -> b
28maybe b f m = case m of
28maybe b f m = case m of
@@ -41,7 +41,7 @@ isNothing = not . isJust
41
41
42
42
43{-| If `Just`, adds the value to the front of the list.
43{-| If `Just`, adds the value to the front of the list.
44− If `Nothing`, list is unchanged.
44+If `Nothing`, list is unchanged.
45-}
45-}
46cons : Maybe a -> [a] -> [a]
46cons : Maybe a -> [a] -> [a]
47cons mx xs = maybe xs (\x -> x :: xs) mx
47cons mx xs = maybe xs (\x -> x :: xs) mx