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