on master help sign in
Add (OneOrMore.destruct : (a -> [a] -> b) -> OneOrMore a -> b)
1b94b5cEvan Czaplicki
compiler/src/Data/OneOrMore.hs+20
@@ -5,6 +5,7 @@ module Data.OneOrMore
5 , more
5 , more
6 , toList
6 , toList
7 , map
7 , map
8+ , destruct
8 )
9 )
9 where
10 where
10
11
@@ -62,3 +63,22 @@ map func oneOrMore =
62
63
63 More left right ->
64 More left right ->
64 More (map func left) (map func right)
65 More (map func left) (map func right)
66+
67+
68+
69+-- DESTRUCT
70+
71+
72+destruct :: (a -> [a] -> b) -> OneOrMore a -> b
73+destruct func oneOrMore =
74+ destructHelp func oneOrMore []
75+
76+
77+destructHelp :: (a -> [a] -> b) -> OneOrMore a -> [a] -> b
78+destructHelp func oneOrMore xs =
79+ case oneOrMore of
80+ One x ->
81+ func x xs
82+
83+ More a b ->
84+ destructHelp func a (toListHelp b xs)