module Incipit.Either where
import Incipit.Base
leftToMaybe :: Either l r -> Maybe l
leftToMaybe :: forall l r. Either l r -> Maybe l
leftToMaybe = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall a. a -> Maybe a
Just (forall a b. a -> b -> a
const forall a. Maybe a
Nothing)
{-# inline leftToMaybe #-}
rightToMaybe :: Either l r -> Maybe r
rightToMaybe :: forall l r. Either l r -> Maybe r
rightToMaybe = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall a b. a -> b -> a
const forall a. Maybe a
Nothing) forall a. a -> Maybe a
Just
{-# inline rightToMaybe #-}
maybeToRight :: l -> Maybe r -> Either l r
maybeToRight :: forall l r. l -> Maybe r -> Either l r
maybeToRight l
l = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall a b. a -> Either a b
Left l
l) forall a b. b -> Either a b
Right
{-# inline maybeToRight #-}
maybeToLeft :: r -> Maybe l -> Either l r
maybeToLeft :: forall r l. r -> Maybe l -> Either l r
maybeToLeft r
r = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall a b. b -> Either a b
Right r
r) forall a b. a -> Either a b
Left
{-# inline maybeToLeft #-}
unify :: Either a a -> a
unify :: forall a. Either a a -> a
unify =
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall a. a -> a
id forall a. a -> a
id
{-# inline unify #-}
leftA ::
Applicative m =>
(a -> m b) ->
Either a b ->
m b
leftA :: forall (m :: * -> *) a b.
Applicative m =>
(a -> m b) -> Either a b -> m b
leftA a -> m b
f = \case
Right b
b -> forall (f :: * -> *) a. Applicative f => a -> f a
pure b
b
Left a
a -> a -> m b
f a
a
{-# inline leftA #-}