on master help sign in
Add OneOrMore.map
4eaeee5Evan Czaplicki
src/Data/OneOrMore.hs+18
@@ -4,10 +4,14 @@ module Data.OneOrMore
4 , one
4 , one
5 , more
5 , more
6 , toList
6 , toList
7+ , map
7 )
8 )
8 where
9 where
9
10
10
11
12+import Prelude hiding (map)
13+
14+
11
15
12-- ONE OR MORE
16-- ONE OR MORE
13
17
@@ -44,3 +48,17 @@ toListHelp oneOrMore list =
44
48
45 More a b ->
49 More a b ->
46 toListHelp a (toListHelp b list)
50 toListHelp a (toListHelp b list)
51+
52+
53+
54+-- MAP
55+
56+
57+map :: (a -> b) -> OneOrMore a -> OneOrMore b
58+map func oneOrMore =
59+ case oneOrMore of
60+ One value ->
61+ One (func value)
62+
63+ More left right ->
64+ More (map func left) (map func right)