-
Notifications
You must be signed in to change notification settings - Fork 0
/
2018-11-14_1.hs
36 lines (25 loc) · 966 Bytes
/
2018-11-14_1.hs
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
31
32
33
34
35
36
{-# OPTIONS -Weverything -fno-warn-implicit-prelude #-}
import qualified Data.Bifunctor
import Control.Applicative.Lift (eitherToErrors, runErrors)
import Control.Monad.Trans.Except (ExceptT(ExceptT), runExceptT)
sequenceEither :: (Traversable t, Monoid e) => t (Either e a) -> Either e (t a)
sequenceEither = sequenceEither' id
sequenceEither'
:: (Traversable t, Monoid e)
=> (e' -> e)
-> t (Either e' a)
-> Either e (t a)
sequenceEither' f = runErrors . traverse (eitherToErrors . mapLeft f)
sequenceExceptT
:: (Traversable t, Monoid e, Applicative f)
=> t (ExceptT e f a)
-> ExceptT e f (t a)
sequenceExceptT = sequenceExceptT' id
sequenceExceptT'
:: (Traversable t, Monoid e, Applicative f)
=> (e' -> e)
-> t (ExceptT e' f a)
-> ExceptT e f (t a)
sequenceExceptT' f es = ExceptT (sequenceEither' f <$> traverse runExceptT es)
mapLeft :: (e' -> e) -> Either e' a -> Either e a
mapLeft = Data.Bifunctor.first