-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheitherUtility.hs
More file actions
30 lines (24 loc) · 763 Bytes
/
eitherUtility.hs
File metadata and controls
30 lines (24 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module EitherUtility where
import Text.Megaparsec as P
import Data.Void
import Nodes
foldE f =
foldr (
\fa fb ->
do
a <- fa
b <- fb
Right $ f a b
)
mapEW :: (a -> String) -> (b -> b) -> [Either a b] -> Either a [b]
mapEW sf _ [] = Right []
mapEW sf f ls@(_:_) = return $ map (f . nf) ls where
nf (Right a) = a
nf (Left e) = error $ sf e
mapE :: (TraversableStream s, VisualStream s, ShowErrorComponent v) =>
(a -> a) -> [Either (ParseErrorBundle s v) a] -> Either (ParseErrorBundle s v) [a]
mapE = mapEW P.errorBundlePretty
verify :: [Either a ()] -> Either a ()
verify = foldE (\_ b -> b) (Right ())
(|>>) :: Either a b -> Either a bx -> Either a bx
(|>>) = (*>)