module Text.Pandoc.Readers.ODT.Generic.Fallible where
type Failure = ()
type Fallible a = Either Failure a
maybeToEither :: Maybe a -> Fallible a
maybeToEither :: forall a. Maybe a -> Fallible a
maybeToEither (Just a
a) = forall a b. b -> Either a b
Right a
a
maybeToEither Maybe a
Nothing = forall a b. a -> Either a b
Left ()
eitherToMaybe :: Either _l a -> Maybe a
eitherToMaybe :: forall _l a. Either _l a -> Maybe a
eitherToMaybe (Left _l
_) = forall a. Maybe a
Nothing
eitherToMaybe (Right a
a) = forall a. a -> Maybe a
Just a
a
recover :: a -> Either _f a -> a
recover :: forall a _f. a -> Either _f a -> a
recover a
a (Left _f
_) = a
a
recover a
_ (Right a
a) = a
a
failWith :: failure -> Either failure _x
failWith :: forall a b. a -> Either a b
failWith failure
f = forall a b. a -> Either a b
Left failure
f
failEmpty :: (Monoid failure) => Either failure _x
failEmpty :: forall failure _x. Monoid failure => Either failure _x
failEmpty = forall a b. a -> Either a b
failWith forall a. Monoid a => a
mempty
succeedWith :: a -> Either _x a
succeedWith :: forall a _x. a -> Either _x a
succeedWith = forall a b. b -> Either a b
Right
collapseEither :: Either failure (Either failure x)
-> Either failure x
collapseEither :: forall failure x.
Either failure (Either failure x) -> Either failure x
collapseEither (Left failure
f ) = forall a b. a -> Either a b
Left failure
f
collapseEither (Right (Left failure
f)) = forall a b. a -> Either a b
Left failure
f
collapseEither (Right (Right x
x)) = forall a b. b -> Either a b
Right x
x
chooseMax :: (Monoid a, Monoid b) => Either a b -> Either a b -> Either a b
chooseMax :: forall a b.
(Monoid a, Monoid b) =>
Either a b -> Either a b -> Either a b
chooseMax = forall a b.
Monoid a =>
(b -> b -> b) -> Either a b -> Either a b -> Either a b
chooseMaxWith forall a. Monoid a => a -> a -> a
mappend
chooseMaxWith :: (Monoid a) => (b -> b -> b)
-> Either a b
-> Either a b
-> Either a b
chooseMaxWith :: forall a b.
Monoid a =>
(b -> b -> b) -> Either a b -> Either a b -> Either a b
chooseMaxWith b -> b -> b
(><) (Right b
a) (Right b
b) = forall a b. b -> Either a b
Right forall a b. (a -> b) -> a -> b
$ b
a b -> b -> b
>< b
b
chooseMaxWith b -> b -> b
_ (Left a
a) (Left a
b) = forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ a
a forall a. Monoid a => a -> a -> a
`mappend` a
b
chooseMaxWith b -> b -> b
_ (Right b
a) Either a b
_ = forall a b. b -> Either a b
Right b
a
chooseMaxWith b -> b -> b
_ Either a b
_ (Right b
b) = forall a b. b -> Either a b
Right b
b
class ChoiceVector v where
spreadChoice :: v (Either f a) -> Either f (v a)
instance ChoiceVector ((,) a) where
spreadChoice :: forall f a. (a, Either f a) -> Either f (a, a)
spreadChoice (a
_, Left f
f) = forall a b. a -> Either a b
Left f
f
spreadChoice (a
x, Right a
y) = forall a b. b -> Either a b
Right (a
x,a
y)
newtype SuccessList a = SuccessList { forall a. SuccessList a -> [a]
collectNonFailing :: [a] }
deriving ( SuccessList a -> SuccessList a -> Bool
forall a. Eq a => SuccessList a -> SuccessList a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SuccessList a -> SuccessList a -> Bool
$c/= :: forall a. Eq a => SuccessList a -> SuccessList a -> Bool
== :: SuccessList a -> SuccessList a -> Bool
$c== :: forall a. Eq a => SuccessList a -> SuccessList a -> Bool
Eq, SuccessList a -> SuccessList a -> Bool
SuccessList a -> SuccessList a -> Ordering
SuccessList a -> SuccessList a -> SuccessList a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {a}. Ord a => Eq (SuccessList a)
forall a. Ord a => SuccessList a -> SuccessList a -> Bool
forall a. Ord a => SuccessList a -> SuccessList a -> Ordering
forall a. Ord a => SuccessList a -> SuccessList a -> SuccessList a
min :: SuccessList a -> SuccessList a -> SuccessList a
$cmin :: forall a. Ord a => SuccessList a -> SuccessList a -> SuccessList a
max :: SuccessList a -> SuccessList a -> SuccessList a
$cmax :: forall a. Ord a => SuccessList a -> SuccessList a -> SuccessList a
>= :: SuccessList a -> SuccessList a -> Bool
$c>= :: forall a. Ord a => SuccessList a -> SuccessList a -> Bool
> :: SuccessList a -> SuccessList a -> Bool
$c> :: forall a. Ord a => SuccessList a -> SuccessList a -> Bool
<= :: SuccessList a -> SuccessList a -> Bool
$c<= :: forall a. Ord a => SuccessList a -> SuccessList a -> Bool
< :: SuccessList a -> SuccessList a -> Bool
$c< :: forall a. Ord a => SuccessList a -> SuccessList a -> Bool
compare :: SuccessList a -> SuccessList a -> Ordering
$ccompare :: forall a. Ord a => SuccessList a -> SuccessList a -> Ordering
Ord, Int -> SuccessList a -> ShowS
forall a. Show a => Int -> SuccessList a -> ShowS
forall a. Show a => [SuccessList a] -> ShowS
forall a. Show a => SuccessList a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SuccessList a] -> ShowS
$cshowList :: forall a. Show a => [SuccessList a] -> ShowS
show :: SuccessList a -> String
$cshow :: forall a. Show a => SuccessList a -> String
showsPrec :: Int -> SuccessList a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> SuccessList a -> ShowS
Show )
instance ChoiceVector SuccessList where
spreadChoice :: forall f a. SuccessList (Either f a) -> Either f (SuccessList a)
spreadChoice = forall a b. b -> Either a b
Right forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> SuccessList a
SuccessList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr forall {a} {a}. Either a a -> [a] -> [a]
unTagRight [] forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. SuccessList a -> [a]
collectNonFailing
where unTagRight :: Either a a -> [a] -> [a]
unTagRight (Right a
x) = (a
xforall a. a -> [a] -> [a]
:)
unTagRight Either a a
_ = forall a. a -> a
id