{-# LANGUAGE CPP #-}
{-# LANGUAGE ConstrainedClassMethods #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeSynonymInstances #-}
module Control.Functor.Dichotomous
(
Dichotomous (..)
, hushLeft, hushRight, swap
, AltSum (..)
, mfold', mlefts, mrights
, flipThese
, LeftOnly(..)
, LeftOrBoth(..)
, RightOnly(..)
, RightOrBoth(..)
, These(..)
, None (..)
, MaybeBoth(..)
, MaybeRight(..)
, MaybeRightOrBoth(..)
, MaybeLeft(..)
, MaybeLeftOrBoth(..)
, MaybeEither(..)
, TheseOrNot(..)
) where
import Control.Applicative (Alternative (empty, (<|>)))
import Data.Bifoldable (Bifoldable (bifoldMap))
import Data.Kind (Type)
import Data.These (These (..))
import GHC.Generics (Generic)
class Dichotomous (f :: Type -> Type -> Type) where
dichotomy :: f a b -> Maybe (These a b)
ymotohcid :: Maybe (These a b) -> Maybe (f a b)
instance Dichotomous (,) where
dichotomy :: (a, b) -> Maybe (These a b)
dichotomy (a
x,b
y) = These a b -> Maybe (These a b)
forall a. a -> Maybe a
Just (These a b -> Maybe (These a b)) -> These a b -> Maybe (These a b)
forall a b. (a -> b) -> a -> b
$ a -> b -> These a b
forall a b. a -> b -> These a b
These a
x b
y
{-# INLINE dichotomy #-}
ymotohcid :: Maybe (These a b) -> Maybe (a, b)
ymotohcid = \case Just (These a
x b
y) -> (a, b) -> Maybe (a, b)
forall a. a -> Maybe a
Just (a
x, b
y); Maybe (These a b)
_ -> Maybe (a, b)
forall a. Maybe a
Nothing
{-# INLINE ymotohcid #-}
newtype LeftOnly a b = LeftOnly { LeftOnly a b -> a
unLeftOnly :: a }
deriving (LeftOnly a b -> LeftOnly a b -> Bool
(LeftOnly a b -> LeftOnly a b -> Bool)
-> (LeftOnly a b -> LeftOnly a b -> Bool) -> Eq (LeftOnly a b)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a b. Eq a => LeftOnly a b -> LeftOnly a b -> Bool
/= :: LeftOnly a b -> LeftOnly a b -> Bool
$c/= :: forall a b. Eq a => LeftOnly a b -> LeftOnly a b -> Bool
== :: LeftOnly a b -> LeftOnly a b -> Bool
$c== :: forall a b. Eq a => LeftOnly a b -> LeftOnly a b -> Bool
Eq, Eq (LeftOnly a b)
Eq (LeftOnly a b)
-> (LeftOnly a b -> LeftOnly a b -> Ordering)
-> (LeftOnly a b -> LeftOnly a b -> Bool)
-> (LeftOnly a b -> LeftOnly a b -> Bool)
-> (LeftOnly a b -> LeftOnly a b -> Bool)
-> (LeftOnly a b -> LeftOnly a b -> Bool)
-> (LeftOnly a b -> LeftOnly a b -> LeftOnly a b)
-> (LeftOnly a b -> LeftOnly a b -> LeftOnly a b)
-> Ord (LeftOnly a b)
LeftOnly a b -> LeftOnly a b -> Bool
LeftOnly a b -> LeftOnly a b -> Ordering
LeftOnly a b -> LeftOnly a b -> LeftOnly a b
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 b. Ord a => Eq (LeftOnly a b)
forall a b. Ord a => LeftOnly a b -> LeftOnly a b -> Bool
forall a b. Ord a => LeftOnly a b -> LeftOnly a b -> Ordering
forall a b. Ord a => LeftOnly a b -> LeftOnly a b -> LeftOnly a b
min :: LeftOnly a b -> LeftOnly a b -> LeftOnly a b
$cmin :: forall a b. Ord a => LeftOnly a b -> LeftOnly a b -> LeftOnly a b
max :: LeftOnly a b -> LeftOnly a b -> LeftOnly a b
$cmax :: forall a b. Ord a => LeftOnly a b -> LeftOnly a b -> LeftOnly a b
>= :: LeftOnly a b -> LeftOnly a b -> Bool
$c>= :: forall a b. Ord a => LeftOnly a b -> LeftOnly a b -> Bool
> :: LeftOnly a b -> LeftOnly a b -> Bool
$c> :: forall a b. Ord a => LeftOnly a b -> LeftOnly a b -> Bool
<= :: LeftOnly a b -> LeftOnly a b -> Bool
$c<= :: forall a b. Ord a => LeftOnly a b -> LeftOnly a b -> Bool
< :: LeftOnly a b -> LeftOnly a b -> Bool
$c< :: forall a b. Ord a => LeftOnly a b -> LeftOnly a b -> Bool
compare :: LeftOnly a b -> LeftOnly a b -> Ordering
$ccompare :: forall a b. Ord a => LeftOnly a b -> LeftOnly a b -> Ordering
$cp1Ord :: forall a b. Ord a => Eq (LeftOnly a b)
Ord, Int -> LeftOnly a b -> ShowS
[LeftOnly a b] -> ShowS
LeftOnly a b -> String
(Int -> LeftOnly a b -> ShowS)
-> (LeftOnly a b -> String)
-> ([LeftOnly a b] -> ShowS)
-> Show (LeftOnly a b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a b. Show a => Int -> LeftOnly a b -> ShowS
forall a b. Show a => [LeftOnly a b] -> ShowS
forall a b. Show a => LeftOnly a b -> String
showList :: [LeftOnly a b] -> ShowS
$cshowList :: forall a b. Show a => [LeftOnly a b] -> ShowS
show :: LeftOnly a b -> String
$cshow :: forall a b. Show a => LeftOnly a b -> String
showsPrec :: Int -> LeftOnly a b -> ShowS
$cshowsPrec :: forall a b. Show a => Int -> LeftOnly a b -> ShowS
Show, ReadPrec [LeftOnly a b]
ReadPrec (LeftOnly a b)
Int -> ReadS (LeftOnly a b)
ReadS [LeftOnly a b]
(Int -> ReadS (LeftOnly a b))
-> ReadS [LeftOnly a b]
-> ReadPrec (LeftOnly a b)
-> ReadPrec [LeftOnly a b]
-> Read (LeftOnly a b)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall a b. Read a => ReadPrec [LeftOnly a b]
forall a b. Read a => ReadPrec (LeftOnly a b)
forall a b. Read a => Int -> ReadS (LeftOnly a b)
forall a b. Read a => ReadS [LeftOnly a b]
readListPrec :: ReadPrec [LeftOnly a b]
$creadListPrec :: forall a b. Read a => ReadPrec [LeftOnly a b]
readPrec :: ReadPrec (LeftOnly a b)
$creadPrec :: forall a b. Read a => ReadPrec (LeftOnly a b)
readList :: ReadS [LeftOnly a b]
$creadList :: forall a b. Read a => ReadS [LeftOnly a b]
readsPrec :: Int -> ReadS (LeftOnly a b)
$creadsPrec :: forall a b. Read a => Int -> ReadS (LeftOnly a b)
Read, (forall x. LeftOnly a b -> Rep (LeftOnly a b) x)
-> (forall x. Rep (LeftOnly a b) x -> LeftOnly a b)
-> Generic (LeftOnly a b)
forall x. Rep (LeftOnly a b) x -> LeftOnly a b
forall x. LeftOnly a b -> Rep (LeftOnly a b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a b x. Rep (LeftOnly a b) x -> LeftOnly a b
forall a b x. LeftOnly a b -> Rep (LeftOnly a b) x
$cto :: forall a b x. Rep (LeftOnly a b) x -> LeftOnly a b
$cfrom :: forall a b x. LeftOnly a b -> Rep (LeftOnly a b) x
Generic)
instance Dichotomous LeftOnly where
dichotomy :: LeftOnly a b -> Maybe (These a b)
dichotomy (LeftOnly a
l) = These a b -> Maybe (These a b)
forall a. a -> Maybe a
Just (a -> These a b
forall a b. a -> These a b
This a
l)
{-# INLINE dichotomy #-}
ymotohcid :: Maybe (These a b) -> Maybe (LeftOnly a b)
ymotohcid = \case
Just (This a
l) -> LeftOnly a b -> Maybe (LeftOnly a b)
forall a. a -> Maybe a
Just (a -> LeftOnly a b
forall a b. a -> LeftOnly a b
LeftOnly a
l)
Just (These a
l b
_) -> LeftOnly a b -> Maybe (LeftOnly a b)
forall a. a -> Maybe a
Just (a -> LeftOnly a b
forall a b. a -> LeftOnly a b
LeftOnly a
l)
Maybe (These a b)
_ -> Maybe (LeftOnly a b)
forall a. Maybe a
Nothing
{-# INLINE ymotohcid #-}
data LeftOrBoth a b = Left' a | LBoth a b
deriving (LeftOrBoth a b -> LeftOrBoth a b -> Bool
(LeftOrBoth a b -> LeftOrBoth a b -> Bool)
-> (LeftOrBoth a b -> LeftOrBoth a b -> Bool)
-> Eq (LeftOrBoth a b)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a b.
(Eq a, Eq b) =>
LeftOrBoth a b -> LeftOrBoth a b -> Bool
/= :: LeftOrBoth a b -> LeftOrBoth a b -> Bool
$c/= :: forall a b.
(Eq a, Eq b) =>
LeftOrBoth a b -> LeftOrBoth a b -> Bool
== :: LeftOrBoth a b -> LeftOrBoth a b -> Bool
$c== :: forall a b.
(Eq a, Eq b) =>
LeftOrBoth a b -> LeftOrBoth a b -> Bool
Eq, Eq (LeftOrBoth a b)
Eq (LeftOrBoth a b)
-> (LeftOrBoth a b -> LeftOrBoth a b -> Ordering)
-> (LeftOrBoth a b -> LeftOrBoth a b -> Bool)
-> (LeftOrBoth a b -> LeftOrBoth a b -> Bool)
-> (LeftOrBoth a b -> LeftOrBoth a b -> Bool)
-> (LeftOrBoth a b -> LeftOrBoth a b -> Bool)
-> (LeftOrBoth a b -> LeftOrBoth a b -> LeftOrBoth a b)
-> (LeftOrBoth a b -> LeftOrBoth a b -> LeftOrBoth a b)
-> Ord (LeftOrBoth a b)
LeftOrBoth a b -> LeftOrBoth a b -> Bool
LeftOrBoth a b -> LeftOrBoth a b -> Ordering
LeftOrBoth a b -> LeftOrBoth a b -> LeftOrBoth a b
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 b. (Ord a, Ord b) => Eq (LeftOrBoth a b)
forall a b.
(Ord a, Ord b) =>
LeftOrBoth a b -> LeftOrBoth a b -> Bool
forall a b.
(Ord a, Ord b) =>
LeftOrBoth a b -> LeftOrBoth a b -> Ordering
forall a b.
(Ord a, Ord b) =>
LeftOrBoth a b -> LeftOrBoth a b -> LeftOrBoth a b
min :: LeftOrBoth a b -> LeftOrBoth a b -> LeftOrBoth a b
$cmin :: forall a b.
(Ord a, Ord b) =>
LeftOrBoth a b -> LeftOrBoth a b -> LeftOrBoth a b
max :: LeftOrBoth a b -> LeftOrBoth a b -> LeftOrBoth a b
$cmax :: forall a b.
(Ord a, Ord b) =>
LeftOrBoth a b -> LeftOrBoth a b -> LeftOrBoth a b
>= :: LeftOrBoth a b -> LeftOrBoth a b -> Bool
$c>= :: forall a b.
(Ord a, Ord b) =>
LeftOrBoth a b -> LeftOrBoth a b -> Bool
> :: LeftOrBoth a b -> LeftOrBoth a b -> Bool
$c> :: forall a b.
(Ord a, Ord b) =>
LeftOrBoth a b -> LeftOrBoth a b -> Bool
<= :: LeftOrBoth a b -> LeftOrBoth a b -> Bool
$c<= :: forall a b.
(Ord a, Ord b) =>
LeftOrBoth a b -> LeftOrBoth a b -> Bool
< :: LeftOrBoth a b -> LeftOrBoth a b -> Bool
$c< :: forall a b.
(Ord a, Ord b) =>
LeftOrBoth a b -> LeftOrBoth a b -> Bool
compare :: LeftOrBoth a b -> LeftOrBoth a b -> Ordering
$ccompare :: forall a b.
(Ord a, Ord b) =>
LeftOrBoth a b -> LeftOrBoth a b -> Ordering
$cp1Ord :: forall a b. (Ord a, Ord b) => Eq (LeftOrBoth a b)
Ord, Int -> LeftOrBoth a b -> ShowS
[LeftOrBoth a b] -> ShowS
LeftOrBoth a b -> String
(Int -> LeftOrBoth a b -> ShowS)
-> (LeftOrBoth a b -> String)
-> ([LeftOrBoth a b] -> ShowS)
-> Show (LeftOrBoth a b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a b. (Show a, Show b) => Int -> LeftOrBoth a b -> ShowS
forall a b. (Show a, Show b) => [LeftOrBoth a b] -> ShowS
forall a b. (Show a, Show b) => LeftOrBoth a b -> String
showList :: [LeftOrBoth a b] -> ShowS
$cshowList :: forall a b. (Show a, Show b) => [LeftOrBoth a b] -> ShowS
show :: LeftOrBoth a b -> String
$cshow :: forall a b. (Show a, Show b) => LeftOrBoth a b -> String
showsPrec :: Int -> LeftOrBoth a b -> ShowS
$cshowsPrec :: forall a b. (Show a, Show b) => Int -> LeftOrBoth a b -> ShowS
Show, ReadPrec [LeftOrBoth a b]
ReadPrec (LeftOrBoth a b)
Int -> ReadS (LeftOrBoth a b)
ReadS [LeftOrBoth a b]
(Int -> ReadS (LeftOrBoth a b))
-> ReadS [LeftOrBoth a b]
-> ReadPrec (LeftOrBoth a b)
-> ReadPrec [LeftOrBoth a b]
-> Read (LeftOrBoth a b)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall a b. (Read a, Read b) => ReadPrec [LeftOrBoth a b]
forall a b. (Read a, Read b) => ReadPrec (LeftOrBoth a b)
forall a b. (Read a, Read b) => Int -> ReadS (LeftOrBoth a b)
forall a b. (Read a, Read b) => ReadS [LeftOrBoth a b]
readListPrec :: ReadPrec [LeftOrBoth a b]
$creadListPrec :: forall a b. (Read a, Read b) => ReadPrec [LeftOrBoth a b]
readPrec :: ReadPrec (LeftOrBoth a b)
$creadPrec :: forall a b. (Read a, Read b) => ReadPrec (LeftOrBoth a b)
readList :: ReadS [LeftOrBoth a b]
$creadList :: forall a b. (Read a, Read b) => ReadS [LeftOrBoth a b]
readsPrec :: Int -> ReadS (LeftOrBoth a b)
$creadsPrec :: forall a b. (Read a, Read b) => Int -> ReadS (LeftOrBoth a b)
Read, (forall x. LeftOrBoth a b -> Rep (LeftOrBoth a b) x)
-> (forall x. Rep (LeftOrBoth a b) x -> LeftOrBoth a b)
-> Generic (LeftOrBoth a b)
forall x. Rep (LeftOrBoth a b) x -> LeftOrBoth a b
forall x. LeftOrBoth a b -> Rep (LeftOrBoth a b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a b x. Rep (LeftOrBoth a b) x -> LeftOrBoth a b
forall a b x. LeftOrBoth a b -> Rep (LeftOrBoth a b) x
$cto :: forall a b x. Rep (LeftOrBoth a b) x -> LeftOrBoth a b
$cfrom :: forall a b x. LeftOrBoth a b -> Rep (LeftOrBoth a b) x
Generic)
instance Dichotomous LeftOrBoth where
dichotomy :: LeftOrBoth a b -> Maybe (These a b)
dichotomy (Left' a
l) = These a b -> Maybe (These a b)
forall a. a -> Maybe a
Just (a -> These a b
forall a b. a -> These a b
This a
l)
dichotomy (LBoth a
l b
r) = These a b -> Maybe (These a b)
forall a. a -> Maybe a
Just (a -> b -> These a b
forall a b. a -> b -> These a b
These a
l b
r)
{-# INLINE dichotomy #-}
ymotohcid :: Maybe (These a b) -> Maybe (LeftOrBoth a b)
ymotohcid = \case
Just (This a
l) -> LeftOrBoth a b -> Maybe (LeftOrBoth a b)
forall a. a -> Maybe a
Just (a -> LeftOrBoth a b
forall a b. a -> LeftOrBoth a b
Left' a
l)
Just (These a
l b
r) -> LeftOrBoth a b -> Maybe (LeftOrBoth a b)
forall a. a -> Maybe a
Just (a -> b -> LeftOrBoth a b
forall a b. a -> b -> LeftOrBoth a b
LBoth a
l b
r)
Maybe (These a b)
_ -> Maybe (LeftOrBoth a b)
forall a. Maybe a
Nothing
{-# INLINE ymotohcid #-}
newtype RightOnly a b = RightOnly { RightOnly a b -> b
unRightOnly :: b }
deriving (RightOnly a b -> RightOnly a b -> Bool
(RightOnly a b -> RightOnly a b -> Bool)
-> (RightOnly a b -> RightOnly a b -> Bool) -> Eq (RightOnly a b)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a b. Eq b => RightOnly a b -> RightOnly a b -> Bool
/= :: RightOnly a b -> RightOnly a b -> Bool
$c/= :: forall a b. Eq b => RightOnly a b -> RightOnly a b -> Bool
== :: RightOnly a b -> RightOnly a b -> Bool
$c== :: forall a b. Eq b => RightOnly a b -> RightOnly a b -> Bool
Eq, Eq (RightOnly a b)
Eq (RightOnly a b)
-> (RightOnly a b -> RightOnly a b -> Ordering)
-> (RightOnly a b -> RightOnly a b -> Bool)
-> (RightOnly a b -> RightOnly a b -> Bool)
-> (RightOnly a b -> RightOnly a b -> Bool)
-> (RightOnly a b -> RightOnly a b -> Bool)
-> (RightOnly a b -> RightOnly a b -> RightOnly a b)
-> (RightOnly a b -> RightOnly a b -> RightOnly a b)
-> Ord (RightOnly a b)
RightOnly a b -> RightOnly a b -> Bool
RightOnly a b -> RightOnly a b -> Ordering
RightOnly a b -> RightOnly a b -> RightOnly a b
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 b. Ord b => Eq (RightOnly a b)
forall a b. Ord b => RightOnly a b -> RightOnly a b -> Bool
forall a b. Ord b => RightOnly a b -> RightOnly a b -> Ordering
forall a b.
Ord b =>
RightOnly a b -> RightOnly a b -> RightOnly a b
min :: RightOnly a b -> RightOnly a b -> RightOnly a b
$cmin :: forall a b.
Ord b =>
RightOnly a b -> RightOnly a b -> RightOnly a b
max :: RightOnly a b -> RightOnly a b -> RightOnly a b
$cmax :: forall a b.
Ord b =>
RightOnly a b -> RightOnly a b -> RightOnly a b
>= :: RightOnly a b -> RightOnly a b -> Bool
$c>= :: forall a b. Ord b => RightOnly a b -> RightOnly a b -> Bool
> :: RightOnly a b -> RightOnly a b -> Bool
$c> :: forall a b. Ord b => RightOnly a b -> RightOnly a b -> Bool
<= :: RightOnly a b -> RightOnly a b -> Bool
$c<= :: forall a b. Ord b => RightOnly a b -> RightOnly a b -> Bool
< :: RightOnly a b -> RightOnly a b -> Bool
$c< :: forall a b. Ord b => RightOnly a b -> RightOnly a b -> Bool
compare :: RightOnly a b -> RightOnly a b -> Ordering
$ccompare :: forall a b. Ord b => RightOnly a b -> RightOnly a b -> Ordering
$cp1Ord :: forall a b. Ord b => Eq (RightOnly a b)
Ord, Int -> RightOnly a b -> ShowS
[RightOnly a b] -> ShowS
RightOnly a b -> String
(Int -> RightOnly a b -> ShowS)
-> (RightOnly a b -> String)
-> ([RightOnly a b] -> ShowS)
-> Show (RightOnly a b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a b. Show b => Int -> RightOnly a b -> ShowS
forall a b. Show b => [RightOnly a b] -> ShowS
forall a b. Show b => RightOnly a b -> String
showList :: [RightOnly a b] -> ShowS
$cshowList :: forall a b. Show b => [RightOnly a b] -> ShowS
show :: RightOnly a b -> String
$cshow :: forall a b. Show b => RightOnly a b -> String
showsPrec :: Int -> RightOnly a b -> ShowS
$cshowsPrec :: forall a b. Show b => Int -> RightOnly a b -> ShowS
Show, ReadPrec [RightOnly a b]
ReadPrec (RightOnly a b)
Int -> ReadS (RightOnly a b)
ReadS [RightOnly a b]
(Int -> ReadS (RightOnly a b))
-> ReadS [RightOnly a b]
-> ReadPrec (RightOnly a b)
-> ReadPrec [RightOnly a b]
-> Read (RightOnly a b)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall a b. Read b => ReadPrec [RightOnly a b]
forall a b. Read b => ReadPrec (RightOnly a b)
forall a b. Read b => Int -> ReadS (RightOnly a b)
forall a b. Read b => ReadS [RightOnly a b]
readListPrec :: ReadPrec [RightOnly a b]
$creadListPrec :: forall a b. Read b => ReadPrec [RightOnly a b]
readPrec :: ReadPrec (RightOnly a b)
$creadPrec :: forall a b. Read b => ReadPrec (RightOnly a b)
readList :: ReadS [RightOnly a b]
$creadList :: forall a b. Read b => ReadS [RightOnly a b]
readsPrec :: Int -> ReadS (RightOnly a b)
$creadsPrec :: forall a b. Read b => Int -> ReadS (RightOnly a b)
Read, (forall x. RightOnly a b -> Rep (RightOnly a b) x)
-> (forall x. Rep (RightOnly a b) x -> RightOnly a b)
-> Generic (RightOnly a b)
forall x. Rep (RightOnly a b) x -> RightOnly a b
forall x. RightOnly a b -> Rep (RightOnly a b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a b x. Rep (RightOnly a b) x -> RightOnly a b
forall a b x. RightOnly a b -> Rep (RightOnly a b) x
$cto :: forall a b x. Rep (RightOnly a b) x -> RightOnly a b
$cfrom :: forall a b x. RightOnly a b -> Rep (RightOnly a b) x
Generic)
instance Dichotomous RightOnly where
dichotomy :: RightOnly a b -> Maybe (These a b)
dichotomy (RightOnly b
r) = These a b -> Maybe (These a b)
forall a. a -> Maybe a
Just (b -> These a b
forall a b. b -> These a b
That b
r)
{-# INLINE dichotomy #-}
ymotohcid :: Maybe (These a b) -> Maybe (RightOnly a b)
ymotohcid = \case
Just (That b
r) -> RightOnly a b -> Maybe (RightOnly a b)
forall a. a -> Maybe a
Just (b -> RightOnly a b
forall a b. b -> RightOnly a b
RightOnly b
r)
Just (These a
_ b
r) -> RightOnly a b -> Maybe (RightOnly a b)
forall a. a -> Maybe a
Just (b -> RightOnly a b
forall a b. b -> RightOnly a b
RightOnly b
r)
Maybe (These a b)
_ -> Maybe (RightOnly a b)
forall a. Maybe a
Nothing
{-# INLINE ymotohcid #-}
data RightOrBoth a b = Right' b | RBoth a b
deriving (RightOrBoth a b -> RightOrBoth a b -> Bool
(RightOrBoth a b -> RightOrBoth a b -> Bool)
-> (RightOrBoth a b -> RightOrBoth a b -> Bool)
-> Eq (RightOrBoth a b)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a b.
(Eq b, Eq a) =>
RightOrBoth a b -> RightOrBoth a b -> Bool
/= :: RightOrBoth a b -> RightOrBoth a b -> Bool
$c/= :: forall a b.
(Eq b, Eq a) =>
RightOrBoth a b -> RightOrBoth a b -> Bool
== :: RightOrBoth a b -> RightOrBoth a b -> Bool
$c== :: forall a b.
(Eq b, Eq a) =>
RightOrBoth a b -> RightOrBoth a b -> Bool
Eq, Eq (RightOrBoth a b)
Eq (RightOrBoth a b)
-> (RightOrBoth a b -> RightOrBoth a b -> Ordering)
-> (RightOrBoth a b -> RightOrBoth a b -> Bool)
-> (RightOrBoth a b -> RightOrBoth a b -> Bool)
-> (RightOrBoth a b -> RightOrBoth a b -> Bool)
-> (RightOrBoth a b -> RightOrBoth a b -> Bool)
-> (RightOrBoth a b -> RightOrBoth a b -> RightOrBoth a b)
-> (RightOrBoth a b -> RightOrBoth a b -> RightOrBoth a b)
-> Ord (RightOrBoth a b)
RightOrBoth a b -> RightOrBoth a b -> Bool
RightOrBoth a b -> RightOrBoth a b -> Ordering
RightOrBoth a b -> RightOrBoth a b -> RightOrBoth a b
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 b. (Ord b, Ord a) => Eq (RightOrBoth a b)
forall a b.
(Ord b, Ord a) =>
RightOrBoth a b -> RightOrBoth a b -> Bool
forall a b.
(Ord b, Ord a) =>
RightOrBoth a b -> RightOrBoth a b -> Ordering
forall a b.
(Ord b, Ord a) =>
RightOrBoth a b -> RightOrBoth a b -> RightOrBoth a b
min :: RightOrBoth a b -> RightOrBoth a b -> RightOrBoth a b
$cmin :: forall a b.
(Ord b, Ord a) =>
RightOrBoth a b -> RightOrBoth a b -> RightOrBoth a b
max :: RightOrBoth a b -> RightOrBoth a b -> RightOrBoth a b
$cmax :: forall a b.
(Ord b, Ord a) =>
RightOrBoth a b -> RightOrBoth a b -> RightOrBoth a b
>= :: RightOrBoth a b -> RightOrBoth a b -> Bool
$c>= :: forall a b.
(Ord b, Ord a) =>
RightOrBoth a b -> RightOrBoth a b -> Bool
> :: RightOrBoth a b -> RightOrBoth a b -> Bool
$c> :: forall a b.
(Ord b, Ord a) =>
RightOrBoth a b -> RightOrBoth a b -> Bool
<= :: RightOrBoth a b -> RightOrBoth a b -> Bool
$c<= :: forall a b.
(Ord b, Ord a) =>
RightOrBoth a b -> RightOrBoth a b -> Bool
< :: RightOrBoth a b -> RightOrBoth a b -> Bool
$c< :: forall a b.
(Ord b, Ord a) =>
RightOrBoth a b -> RightOrBoth a b -> Bool
compare :: RightOrBoth a b -> RightOrBoth a b -> Ordering
$ccompare :: forall a b.
(Ord b, Ord a) =>
RightOrBoth a b -> RightOrBoth a b -> Ordering
$cp1Ord :: forall a b. (Ord b, Ord a) => Eq (RightOrBoth a b)
Ord, Int -> RightOrBoth a b -> ShowS
[RightOrBoth a b] -> ShowS
RightOrBoth a b -> String
(Int -> RightOrBoth a b -> ShowS)
-> (RightOrBoth a b -> String)
-> ([RightOrBoth a b] -> ShowS)
-> Show (RightOrBoth a b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a b. (Show b, Show a) => Int -> RightOrBoth a b -> ShowS
forall a b. (Show b, Show a) => [RightOrBoth a b] -> ShowS
forall a b. (Show b, Show a) => RightOrBoth a b -> String
showList :: [RightOrBoth a b] -> ShowS
$cshowList :: forall a b. (Show b, Show a) => [RightOrBoth a b] -> ShowS
show :: RightOrBoth a b -> String
$cshow :: forall a b. (Show b, Show a) => RightOrBoth a b -> String
showsPrec :: Int -> RightOrBoth a b -> ShowS
$cshowsPrec :: forall a b. (Show b, Show a) => Int -> RightOrBoth a b -> ShowS
Show, ReadPrec [RightOrBoth a b]
ReadPrec (RightOrBoth a b)
Int -> ReadS (RightOrBoth a b)
ReadS [RightOrBoth a b]
(Int -> ReadS (RightOrBoth a b))
-> ReadS [RightOrBoth a b]
-> ReadPrec (RightOrBoth a b)
-> ReadPrec [RightOrBoth a b]
-> Read (RightOrBoth a b)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall a b. (Read b, Read a) => ReadPrec [RightOrBoth a b]
forall a b. (Read b, Read a) => ReadPrec (RightOrBoth a b)
forall a b. (Read b, Read a) => Int -> ReadS (RightOrBoth a b)
forall a b. (Read b, Read a) => ReadS [RightOrBoth a b]
readListPrec :: ReadPrec [RightOrBoth a b]
$creadListPrec :: forall a b. (Read b, Read a) => ReadPrec [RightOrBoth a b]
readPrec :: ReadPrec (RightOrBoth a b)
$creadPrec :: forall a b. (Read b, Read a) => ReadPrec (RightOrBoth a b)
readList :: ReadS [RightOrBoth a b]
$creadList :: forall a b. (Read b, Read a) => ReadS [RightOrBoth a b]
readsPrec :: Int -> ReadS (RightOrBoth a b)
$creadsPrec :: forall a b. (Read b, Read a) => Int -> ReadS (RightOrBoth a b)
Read, (forall x. RightOrBoth a b -> Rep (RightOrBoth a b) x)
-> (forall x. Rep (RightOrBoth a b) x -> RightOrBoth a b)
-> Generic (RightOrBoth a b)
forall x. Rep (RightOrBoth a b) x -> RightOrBoth a b
forall x. RightOrBoth a b -> Rep (RightOrBoth a b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a b x. Rep (RightOrBoth a b) x -> RightOrBoth a b
forall a b x. RightOrBoth a b -> Rep (RightOrBoth a b) x
$cto :: forall a b x. Rep (RightOrBoth a b) x -> RightOrBoth a b
$cfrom :: forall a b x. RightOrBoth a b -> Rep (RightOrBoth a b) x
Generic)
instance Dichotomous RightOrBoth where
dichotomy :: RightOrBoth a b -> Maybe (These a b)
dichotomy (Right' b
r) = These a b -> Maybe (These a b)
forall a. a -> Maybe a
Just (b -> These a b
forall a b. b -> These a b
That b
r)
dichotomy (RBoth a
l b
r) = These a b -> Maybe (These a b)
forall a. a -> Maybe a
Just (a -> b -> These a b
forall a b. a -> b -> These a b
These a
l b
r)
{-# INLINE dichotomy #-}
ymotohcid :: Maybe (These a b) -> Maybe (RightOrBoth a b)
ymotohcid = \case
Just (That b
r) -> RightOrBoth a b -> Maybe (RightOrBoth a b)
forall a. a -> Maybe a
Just (b -> RightOrBoth a b
forall a b. b -> RightOrBoth a b
Right' b
r)
Just (These a
l b
r) -> RightOrBoth a b -> Maybe (RightOrBoth a b)
forall a. a -> Maybe a
Just (a -> b -> RightOrBoth a b
forall a b. a -> b -> RightOrBoth a b
RBoth a
l b
r)
Maybe (These a b)
_ -> Maybe (RightOrBoth a b)
forall a. Maybe a
Nothing
{-# INLINE ymotohcid #-}
instance Dichotomous Either where
dichotomy :: Either a b -> Maybe (These a b)
dichotomy = These a b -> Maybe (These a b)
forall a. a -> Maybe a
Just (These a b -> Maybe (These a b))
-> (Either a b -> These a b) -> Either a b -> Maybe (These a b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. \case Left a
l -> a -> These a b
forall a b. a -> These a b
This a
l; Right b
r -> b -> These a b
forall a b. b -> These a b
That b
r
{-# INLINABLE dichotomy #-}
ymotohcid :: Maybe (These a b) -> Maybe (Either a b)
ymotohcid = \case Just (This a
l) -> Either a b -> Maybe (Either a b)
forall a. a -> Maybe a
Just (a -> Either a b
forall a b. a -> Either a b
Left a
l)
Just (That b
r) -> Either a b -> Maybe (Either a b)
forall a. a -> Maybe a
Just (b -> Either a b
forall a b. b -> Either a b
Right b
r)
Maybe (These a b)
_ -> Maybe (Either a b)
forall a. Maybe a
Nothing
{-# INLINEABLE ymotohcid #-}
instance Dichotomous These where
dichotomy :: These a b -> Maybe (These a b)
dichotomy = These a b -> Maybe (These a b)
forall a. a -> Maybe a
Just
{-# INLINE dichotomy #-}
ymotohcid :: Maybe (These a b) -> Maybe (These a b)
ymotohcid = Maybe (These a b) -> Maybe (These a b)
forall a. a -> a
id
{-# INLINE ymotohcid #-}
data None a b = None
deriving (None a b -> None a b -> Bool
(None a b -> None a b -> Bool)
-> (None a b -> None a b -> Bool) -> Eq (None a b)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a b. None a b -> None a b -> Bool
/= :: None a b -> None a b -> Bool
$c/= :: forall a b. None a b -> None a b -> Bool
== :: None a b -> None a b -> Bool
$c== :: forall a b. None a b -> None a b -> Bool
Eq, Eq (None a b)
Eq (None a b)
-> (None a b -> None a b -> Ordering)
-> (None a b -> None a b -> Bool)
-> (None a b -> None a b -> Bool)
-> (None a b -> None a b -> Bool)
-> (None a b -> None a b -> Bool)
-> (None a b -> None a b -> None a b)
-> (None a b -> None a b -> None a b)
-> Ord (None a b)
None a b -> None a b -> Bool
None a b -> None a b -> Ordering
None a b -> None a b -> None a b
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 b. Eq (None a b)
forall a b. None a b -> None a b -> Bool
forall a b. None a b -> None a b -> Ordering
forall a b. None a b -> None a b -> None a b
min :: None a b -> None a b -> None a b
$cmin :: forall a b. None a b -> None a b -> None a b
max :: None a b -> None a b -> None a b
$cmax :: forall a b. None a b -> None a b -> None a b
>= :: None a b -> None a b -> Bool
$c>= :: forall a b. None a b -> None a b -> Bool
> :: None a b -> None a b -> Bool
$c> :: forall a b. None a b -> None a b -> Bool
<= :: None a b -> None a b -> Bool
$c<= :: forall a b. None a b -> None a b -> Bool
< :: None a b -> None a b -> Bool
$c< :: forall a b. None a b -> None a b -> Bool
compare :: None a b -> None a b -> Ordering
$ccompare :: forall a b. None a b -> None a b -> Ordering
$cp1Ord :: forall a b. Eq (None a b)
Ord, Int -> None a b -> ShowS
[None a b] -> ShowS
None a b -> String
(Int -> None a b -> ShowS)
-> (None a b -> String) -> ([None a b] -> ShowS) -> Show (None a b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a b. Int -> None a b -> ShowS
forall a b. [None a b] -> ShowS
forall a b. None a b -> String
showList :: [None a b] -> ShowS
$cshowList :: forall a b. [None a b] -> ShowS
show :: None a b -> String
$cshow :: forall a b. None a b -> String
showsPrec :: Int -> None a b -> ShowS
$cshowsPrec :: forall a b. Int -> None a b -> ShowS
Show, ReadPrec [None a b]
ReadPrec (None a b)
Int -> ReadS (None a b)
ReadS [None a b]
(Int -> ReadS (None a b))
-> ReadS [None a b]
-> ReadPrec (None a b)
-> ReadPrec [None a b]
-> Read (None a b)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall a b. ReadPrec [None a b]
forall a b. ReadPrec (None a b)
forall a b. Int -> ReadS (None a b)
forall a b. ReadS [None a b]
readListPrec :: ReadPrec [None a b]
$creadListPrec :: forall a b. ReadPrec [None a b]
readPrec :: ReadPrec (None a b)
$creadPrec :: forall a b. ReadPrec (None a b)
readList :: ReadS [None a b]
$creadList :: forall a b. ReadS [None a b]
readsPrec :: Int -> ReadS (None a b)
$creadsPrec :: forall a b. Int -> ReadS (None a b)
Read, (forall x. None a b -> Rep (None a b) x)
-> (forall x. Rep (None a b) x -> None a b) -> Generic (None a b)
forall x. Rep (None a b) x -> None a b
forall x. None a b -> Rep (None a b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a b x. Rep (None a b) x -> None a b
forall a b x. None a b -> Rep (None a b) x
$cto :: forall a b x. Rep (None a b) x -> None a b
$cfrom :: forall a b x. None a b -> Rep (None a b) x
Generic)
instance Dichotomous None where
dichotomy :: None a b -> Maybe (These a b)
dichotomy None a b
_ = Maybe (These a b)
forall a. Maybe a
Nothing
{-# INLINE dichotomy #-}
ymotohcid :: Maybe (These a b) -> Maybe (None a b)
ymotohcid Maybe (These a b)
_ = None a b -> Maybe (None a b)
forall a. a -> Maybe a
Just None a b
forall a b. None a b
None
{-# INLINE ymotohcid #-}
newtype MaybeBoth a b = MaybeBoth { MaybeBoth a b -> Maybe (a, b)
unMaybeOrBoth :: Maybe (a,b) }
deriving (MaybeBoth a b -> MaybeBoth a b -> Bool
(MaybeBoth a b -> MaybeBoth a b -> Bool)
-> (MaybeBoth a b -> MaybeBoth a b -> Bool) -> Eq (MaybeBoth a b)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a b. (Eq a, Eq b) => MaybeBoth a b -> MaybeBoth a b -> Bool
/= :: MaybeBoth a b -> MaybeBoth a b -> Bool
$c/= :: forall a b. (Eq a, Eq b) => MaybeBoth a b -> MaybeBoth a b -> Bool
== :: MaybeBoth a b -> MaybeBoth a b -> Bool
$c== :: forall a b. (Eq a, Eq b) => MaybeBoth a b -> MaybeBoth a b -> Bool
Eq, Eq (MaybeBoth a b)
Eq (MaybeBoth a b)
-> (MaybeBoth a b -> MaybeBoth a b -> Ordering)
-> (MaybeBoth a b -> MaybeBoth a b -> Bool)
-> (MaybeBoth a b -> MaybeBoth a b -> Bool)
-> (MaybeBoth a b -> MaybeBoth a b -> Bool)
-> (MaybeBoth a b -> MaybeBoth a b -> Bool)
-> (MaybeBoth a b -> MaybeBoth a b -> MaybeBoth a b)
-> (MaybeBoth a b -> MaybeBoth a b -> MaybeBoth a b)
-> Ord (MaybeBoth a b)
MaybeBoth a b -> MaybeBoth a b -> Bool
MaybeBoth a b -> MaybeBoth a b -> Ordering
MaybeBoth a b -> MaybeBoth a b -> MaybeBoth a b
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 b. (Ord a, Ord b) => Eq (MaybeBoth a b)
forall a b.
(Ord a, Ord b) =>
MaybeBoth a b -> MaybeBoth a b -> Bool
forall a b.
(Ord a, Ord b) =>
MaybeBoth a b -> MaybeBoth a b -> Ordering
forall a b.
(Ord a, Ord b) =>
MaybeBoth a b -> MaybeBoth a b -> MaybeBoth a b
min :: MaybeBoth a b -> MaybeBoth a b -> MaybeBoth a b
$cmin :: forall a b.
(Ord a, Ord b) =>
MaybeBoth a b -> MaybeBoth a b -> MaybeBoth a b
max :: MaybeBoth a b -> MaybeBoth a b -> MaybeBoth a b
$cmax :: forall a b.
(Ord a, Ord b) =>
MaybeBoth a b -> MaybeBoth a b -> MaybeBoth a b
>= :: MaybeBoth a b -> MaybeBoth a b -> Bool
$c>= :: forall a b.
(Ord a, Ord b) =>
MaybeBoth a b -> MaybeBoth a b -> Bool
> :: MaybeBoth a b -> MaybeBoth a b -> Bool
$c> :: forall a b.
(Ord a, Ord b) =>
MaybeBoth a b -> MaybeBoth a b -> Bool
<= :: MaybeBoth a b -> MaybeBoth a b -> Bool
$c<= :: forall a b.
(Ord a, Ord b) =>
MaybeBoth a b -> MaybeBoth a b -> Bool
< :: MaybeBoth a b -> MaybeBoth a b -> Bool
$c< :: forall a b.
(Ord a, Ord b) =>
MaybeBoth a b -> MaybeBoth a b -> Bool
compare :: MaybeBoth a b -> MaybeBoth a b -> Ordering
$ccompare :: forall a b.
(Ord a, Ord b) =>
MaybeBoth a b -> MaybeBoth a b -> Ordering
$cp1Ord :: forall a b. (Ord a, Ord b) => Eq (MaybeBoth a b)
Ord, Int -> MaybeBoth a b -> ShowS
[MaybeBoth a b] -> ShowS
MaybeBoth a b -> String
(Int -> MaybeBoth a b -> ShowS)
-> (MaybeBoth a b -> String)
-> ([MaybeBoth a b] -> ShowS)
-> Show (MaybeBoth a b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a b. (Show a, Show b) => Int -> MaybeBoth a b -> ShowS
forall a b. (Show a, Show b) => [MaybeBoth a b] -> ShowS
forall a b. (Show a, Show b) => MaybeBoth a b -> String
showList :: [MaybeBoth a b] -> ShowS
$cshowList :: forall a b. (Show a, Show b) => [MaybeBoth a b] -> ShowS
show :: MaybeBoth a b -> String
$cshow :: forall a b. (Show a, Show b) => MaybeBoth a b -> String
showsPrec :: Int -> MaybeBoth a b -> ShowS
$cshowsPrec :: forall a b. (Show a, Show b) => Int -> MaybeBoth a b -> ShowS
Show, ReadPrec [MaybeBoth a b]
ReadPrec (MaybeBoth a b)
Int -> ReadS (MaybeBoth a b)
ReadS [MaybeBoth a b]
(Int -> ReadS (MaybeBoth a b))
-> ReadS [MaybeBoth a b]
-> ReadPrec (MaybeBoth a b)
-> ReadPrec [MaybeBoth a b]
-> Read (MaybeBoth a b)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall a b. (Read a, Read b) => ReadPrec [MaybeBoth a b]
forall a b. (Read a, Read b) => ReadPrec (MaybeBoth a b)
forall a b. (Read a, Read b) => Int -> ReadS (MaybeBoth a b)
forall a b. (Read a, Read b) => ReadS [MaybeBoth a b]
readListPrec :: ReadPrec [MaybeBoth a b]
$creadListPrec :: forall a b. (Read a, Read b) => ReadPrec [MaybeBoth a b]
readPrec :: ReadPrec (MaybeBoth a b)
$creadPrec :: forall a b. (Read a, Read b) => ReadPrec (MaybeBoth a b)
readList :: ReadS [MaybeBoth a b]
$creadList :: forall a b. (Read a, Read b) => ReadS [MaybeBoth a b]
readsPrec :: Int -> ReadS (MaybeBoth a b)
$creadsPrec :: forall a b. (Read a, Read b) => Int -> ReadS (MaybeBoth a b)
Read, (forall x. MaybeBoth a b -> Rep (MaybeBoth a b) x)
-> (forall x. Rep (MaybeBoth a b) x -> MaybeBoth a b)
-> Generic (MaybeBoth a b)
forall x. Rep (MaybeBoth a b) x -> MaybeBoth a b
forall x. MaybeBoth a b -> Rep (MaybeBoth a b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a b x. Rep (MaybeBoth a b) x -> MaybeBoth a b
forall a b x. MaybeBoth a b -> Rep (MaybeBoth a b) x
$cto :: forall a b x. Rep (MaybeBoth a b) x -> MaybeBoth a b
$cfrom :: forall a b x. MaybeBoth a b -> Rep (MaybeBoth a b) x
Generic)
instance Dichotomous MaybeBoth where
dichotomy :: MaybeBoth a b -> Maybe (These a b)
dichotomy MaybeBoth a b
x = case MaybeBoth a b -> Maybe (a, b)
forall a b. MaybeBoth a b -> Maybe (a, b)
unMaybeOrBoth MaybeBoth a b
x of
Maybe (a, b)
Nothing -> Maybe (These a b)
forall a. Maybe a
Nothing
Just (a
a,b
b) -> These a b -> Maybe (These a b)
forall a. a -> Maybe a
Just (a -> b -> These a b
forall a b. a -> b -> These a b
These a
a b
b)
{-# INLINE dichotomy #-}
ymotohcid :: Maybe (These a b) -> Maybe (MaybeBoth a b)
ymotohcid = MaybeBoth a b -> Maybe (MaybeBoth a b)
forall a. a -> Maybe a
Just (MaybeBoth a b -> Maybe (MaybeBoth a b))
-> (Maybe (These a b) -> MaybeBoth a b)
-> Maybe (These a b)
-> Maybe (MaybeBoth a b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe (a, b) -> MaybeBoth a b
forall a b. Maybe (a, b) -> MaybeBoth a b
MaybeBoth (Maybe (a, b) -> MaybeBoth a b)
-> (Maybe (These a b) -> Maybe (a, b))
-> Maybe (These a b)
-> MaybeBoth a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. \case
Just (These a
a b
b) -> (a, b) -> Maybe (a, b)
forall a. a -> Maybe a
Just (a
a,b
b)
Maybe (These a b)
_ -> Maybe (a, b)
forall a. Maybe a
Nothing
{-# INLINE ymotohcid #-}
data MaybeRight a b = MRNothing | MRight b
deriving (MaybeRight a b -> MaybeRight a b -> Bool
(MaybeRight a b -> MaybeRight a b -> Bool)
-> (MaybeRight a b -> MaybeRight a b -> Bool)
-> Eq (MaybeRight a b)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a b. Eq b => MaybeRight a b -> MaybeRight a b -> Bool
/= :: MaybeRight a b -> MaybeRight a b -> Bool
$c/= :: forall a b. Eq b => MaybeRight a b -> MaybeRight a b -> Bool
== :: MaybeRight a b -> MaybeRight a b -> Bool
$c== :: forall a b. Eq b => MaybeRight a b -> MaybeRight a b -> Bool
Eq, Eq (MaybeRight a b)
Eq (MaybeRight a b)
-> (MaybeRight a b -> MaybeRight a b -> Ordering)
-> (MaybeRight a b -> MaybeRight a b -> Bool)
-> (MaybeRight a b -> MaybeRight a b -> Bool)
-> (MaybeRight a b -> MaybeRight a b -> Bool)
-> (MaybeRight a b -> MaybeRight a b -> Bool)
-> (MaybeRight a b -> MaybeRight a b -> MaybeRight a b)
-> (MaybeRight a b -> MaybeRight a b -> MaybeRight a b)
-> Ord (MaybeRight a b)
MaybeRight a b -> MaybeRight a b -> Bool
MaybeRight a b -> MaybeRight a b -> Ordering
MaybeRight a b -> MaybeRight a b -> MaybeRight a b
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 b. Ord b => Eq (MaybeRight a b)
forall a b. Ord b => MaybeRight a b -> MaybeRight a b -> Bool
forall a b. Ord b => MaybeRight a b -> MaybeRight a b -> Ordering
forall a b.
Ord b =>
MaybeRight a b -> MaybeRight a b -> MaybeRight a b
min :: MaybeRight a b -> MaybeRight a b -> MaybeRight a b
$cmin :: forall a b.
Ord b =>
MaybeRight a b -> MaybeRight a b -> MaybeRight a b
max :: MaybeRight a b -> MaybeRight a b -> MaybeRight a b
$cmax :: forall a b.
Ord b =>
MaybeRight a b -> MaybeRight a b -> MaybeRight a b
>= :: MaybeRight a b -> MaybeRight a b -> Bool
$c>= :: forall a b. Ord b => MaybeRight a b -> MaybeRight a b -> Bool
> :: MaybeRight a b -> MaybeRight a b -> Bool
$c> :: forall a b. Ord b => MaybeRight a b -> MaybeRight a b -> Bool
<= :: MaybeRight a b -> MaybeRight a b -> Bool
$c<= :: forall a b. Ord b => MaybeRight a b -> MaybeRight a b -> Bool
< :: MaybeRight a b -> MaybeRight a b -> Bool
$c< :: forall a b. Ord b => MaybeRight a b -> MaybeRight a b -> Bool
compare :: MaybeRight a b -> MaybeRight a b -> Ordering
$ccompare :: forall a b. Ord b => MaybeRight a b -> MaybeRight a b -> Ordering
$cp1Ord :: forall a b. Ord b => Eq (MaybeRight a b)
Ord, Int -> MaybeRight a b -> ShowS
[MaybeRight a b] -> ShowS
MaybeRight a b -> String
(Int -> MaybeRight a b -> ShowS)
-> (MaybeRight a b -> String)
-> ([MaybeRight a b] -> ShowS)
-> Show (MaybeRight a b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a b. Show b => Int -> MaybeRight a b -> ShowS
forall a b. Show b => [MaybeRight a b] -> ShowS
forall a b. Show b => MaybeRight a b -> String
showList :: [MaybeRight a b] -> ShowS
$cshowList :: forall a b. Show b => [MaybeRight a b] -> ShowS
show :: MaybeRight a b -> String
$cshow :: forall a b. Show b => MaybeRight a b -> String
showsPrec :: Int -> MaybeRight a b -> ShowS
$cshowsPrec :: forall a b. Show b => Int -> MaybeRight a b -> ShowS
Show, ReadPrec [MaybeRight a b]
ReadPrec (MaybeRight a b)
Int -> ReadS (MaybeRight a b)
ReadS [MaybeRight a b]
(Int -> ReadS (MaybeRight a b))
-> ReadS [MaybeRight a b]
-> ReadPrec (MaybeRight a b)
-> ReadPrec [MaybeRight a b]
-> Read (MaybeRight a b)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall a b. Read b => ReadPrec [MaybeRight a b]
forall a b. Read b => ReadPrec (MaybeRight a b)
forall a b. Read b => Int -> ReadS (MaybeRight a b)
forall a b. Read b => ReadS [MaybeRight a b]
readListPrec :: ReadPrec [MaybeRight a b]
$creadListPrec :: forall a b. Read b => ReadPrec [MaybeRight a b]
readPrec :: ReadPrec (MaybeRight a b)
$creadPrec :: forall a b. Read b => ReadPrec (MaybeRight a b)
readList :: ReadS [MaybeRight a b]
$creadList :: forall a b. Read b => ReadS [MaybeRight a b]
readsPrec :: Int -> ReadS (MaybeRight a b)
$creadsPrec :: forall a b. Read b => Int -> ReadS (MaybeRight a b)
Read, (forall x. MaybeRight a b -> Rep (MaybeRight a b) x)
-> (forall x. Rep (MaybeRight a b) x -> MaybeRight a b)
-> Generic (MaybeRight a b)
forall x. Rep (MaybeRight a b) x -> MaybeRight a b
forall x. MaybeRight a b -> Rep (MaybeRight a b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a b x. Rep (MaybeRight a b) x -> MaybeRight a b
forall a b x. MaybeRight a b -> Rep (MaybeRight a b) x
$cto :: forall a b x. Rep (MaybeRight a b) x -> MaybeRight a b
$cfrom :: forall a b x. MaybeRight a b -> Rep (MaybeRight a b) x
Generic)
instance Dichotomous MaybeRight where
dichotomy :: MaybeRight a b -> Maybe (These a b)
dichotomy = \case
MaybeRight a b
MRNothing -> Maybe (These a b)
forall a. Maybe a
Nothing
MRight b
b -> These a b -> Maybe (These a b)
forall a. a -> Maybe a
Just (b -> These a b
forall a b. b -> These a b
That b
b)
{-# INLINE dichotomy #-}
ymotohcid :: Maybe (These a b) -> Maybe (MaybeRight a b)
ymotohcid = MaybeRight a b -> Maybe (MaybeRight a b)
forall a. a -> Maybe a
Just (MaybeRight a b -> Maybe (MaybeRight a b))
-> (Maybe (These a b) -> MaybeRight a b)
-> Maybe (These a b)
-> Maybe (MaybeRight a b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. \case
Just (That b
b) -> b -> MaybeRight a b
forall a b. b -> MaybeRight a b
MRight b
b
Just (These a
_ b
b) -> b -> MaybeRight a b
forall a b. b -> MaybeRight a b
MRight b
b
Maybe (These a b)
_ -> MaybeRight a b
forall a b. MaybeRight a b
MRNothing
{-# INLINE ymotohcid #-}
data MaybeRightOrBoth a b = MRBNothing | MRBRight b | MRBoth a b
deriving (MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Bool
(MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Bool)
-> (MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Bool)
-> Eq (MaybeRightOrBoth a b)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a b.
(Eq b, Eq a) =>
MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Bool
/= :: MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Bool
$c/= :: forall a b.
(Eq b, Eq a) =>
MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Bool
== :: MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Bool
$c== :: forall a b.
(Eq b, Eq a) =>
MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Bool
Eq, Eq (MaybeRightOrBoth a b)
Eq (MaybeRightOrBoth a b)
-> (MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Ordering)
-> (MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Bool)
-> (MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Bool)
-> (MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Bool)
-> (MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Bool)
-> (MaybeRightOrBoth a b
-> MaybeRightOrBoth a b -> MaybeRightOrBoth a b)
-> (MaybeRightOrBoth a b
-> MaybeRightOrBoth a b -> MaybeRightOrBoth a b)
-> Ord (MaybeRightOrBoth a b)
MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Bool
MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Ordering
MaybeRightOrBoth a b
-> MaybeRightOrBoth a b -> MaybeRightOrBoth a b
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 b. (Ord b, Ord a) => Eq (MaybeRightOrBoth a b)
forall a b.
(Ord b, Ord a) =>
MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Bool
forall a b.
(Ord b, Ord a) =>
MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Ordering
forall a b.
(Ord b, Ord a) =>
MaybeRightOrBoth a b
-> MaybeRightOrBoth a b -> MaybeRightOrBoth a b
min :: MaybeRightOrBoth a b
-> MaybeRightOrBoth a b -> MaybeRightOrBoth a b
$cmin :: forall a b.
(Ord b, Ord a) =>
MaybeRightOrBoth a b
-> MaybeRightOrBoth a b -> MaybeRightOrBoth a b
max :: MaybeRightOrBoth a b
-> MaybeRightOrBoth a b -> MaybeRightOrBoth a b
$cmax :: forall a b.
(Ord b, Ord a) =>
MaybeRightOrBoth a b
-> MaybeRightOrBoth a b -> MaybeRightOrBoth a b
>= :: MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Bool
$c>= :: forall a b.
(Ord b, Ord a) =>
MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Bool
> :: MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Bool
$c> :: forall a b.
(Ord b, Ord a) =>
MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Bool
<= :: MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Bool
$c<= :: forall a b.
(Ord b, Ord a) =>
MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Bool
< :: MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Bool
$c< :: forall a b.
(Ord b, Ord a) =>
MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Bool
compare :: MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Ordering
$ccompare :: forall a b.
(Ord b, Ord a) =>
MaybeRightOrBoth a b -> MaybeRightOrBoth a b -> Ordering
$cp1Ord :: forall a b. (Ord b, Ord a) => Eq (MaybeRightOrBoth a b)
Ord, Int -> MaybeRightOrBoth a b -> ShowS
[MaybeRightOrBoth a b] -> ShowS
MaybeRightOrBoth a b -> String
(Int -> MaybeRightOrBoth a b -> ShowS)
-> (MaybeRightOrBoth a b -> String)
-> ([MaybeRightOrBoth a b] -> ShowS)
-> Show (MaybeRightOrBoth a b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a b.
(Show b, Show a) =>
Int -> MaybeRightOrBoth a b -> ShowS
forall a b. (Show b, Show a) => [MaybeRightOrBoth a b] -> ShowS
forall a b. (Show b, Show a) => MaybeRightOrBoth a b -> String
showList :: [MaybeRightOrBoth a b] -> ShowS
$cshowList :: forall a b. (Show b, Show a) => [MaybeRightOrBoth a b] -> ShowS
show :: MaybeRightOrBoth a b -> String
$cshow :: forall a b. (Show b, Show a) => MaybeRightOrBoth a b -> String
showsPrec :: Int -> MaybeRightOrBoth a b -> ShowS
$cshowsPrec :: forall a b.
(Show b, Show a) =>
Int -> MaybeRightOrBoth a b -> ShowS
Show, ReadPrec [MaybeRightOrBoth a b]
ReadPrec (MaybeRightOrBoth a b)
Int -> ReadS (MaybeRightOrBoth a b)
ReadS [MaybeRightOrBoth a b]
(Int -> ReadS (MaybeRightOrBoth a b))
-> ReadS [MaybeRightOrBoth a b]
-> ReadPrec (MaybeRightOrBoth a b)
-> ReadPrec [MaybeRightOrBoth a b]
-> Read (MaybeRightOrBoth a b)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall a b. (Read b, Read a) => ReadPrec [MaybeRightOrBoth a b]
forall a b. (Read b, Read a) => ReadPrec (MaybeRightOrBoth a b)
forall a b. (Read b, Read a) => Int -> ReadS (MaybeRightOrBoth a b)
forall a b. (Read b, Read a) => ReadS [MaybeRightOrBoth a b]
readListPrec :: ReadPrec [MaybeRightOrBoth a b]
$creadListPrec :: forall a b. (Read b, Read a) => ReadPrec [MaybeRightOrBoth a b]
readPrec :: ReadPrec (MaybeRightOrBoth a b)
$creadPrec :: forall a b. (Read b, Read a) => ReadPrec (MaybeRightOrBoth a b)
readList :: ReadS [MaybeRightOrBoth a b]
$creadList :: forall a b. (Read b, Read a) => ReadS [MaybeRightOrBoth a b]
readsPrec :: Int -> ReadS (MaybeRightOrBoth a b)
$creadsPrec :: forall a b. (Read b, Read a) => Int -> ReadS (MaybeRightOrBoth a b)
Read, (forall x. MaybeRightOrBoth a b -> Rep (MaybeRightOrBoth a b) x)
-> (forall x. Rep (MaybeRightOrBoth a b) x -> MaybeRightOrBoth a b)
-> Generic (MaybeRightOrBoth a b)
forall x. Rep (MaybeRightOrBoth a b) x -> MaybeRightOrBoth a b
forall x. MaybeRightOrBoth a b -> Rep (MaybeRightOrBoth a b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a b x. Rep (MaybeRightOrBoth a b) x -> MaybeRightOrBoth a b
forall a b x. MaybeRightOrBoth a b -> Rep (MaybeRightOrBoth a b) x
$cto :: forall a b x. Rep (MaybeRightOrBoth a b) x -> MaybeRightOrBoth a b
$cfrom :: forall a b x. MaybeRightOrBoth a b -> Rep (MaybeRightOrBoth a b) x
Generic)
instance Dichotomous MaybeRightOrBoth where
dichotomy :: MaybeRightOrBoth a b -> Maybe (These a b)
dichotomy = \case
MaybeRightOrBoth a b
MRBNothing -> Maybe (These a b)
forall a. Maybe a
Nothing
MRBRight b
b -> These a b -> Maybe (These a b)
forall a. a -> Maybe a
Just (b -> These a b
forall a b. b -> These a b
That b
b)
MRBoth a
a b
b -> These a b -> Maybe (These a b)
forall a. a -> Maybe a
Just (a -> b -> These a b
forall a b. a -> b -> These a b
These a
a b
b)
{-# INLINE dichotomy #-}
ymotohcid :: Maybe (These a b) -> Maybe (MaybeRightOrBoth a b)
ymotohcid = MaybeRightOrBoth a b -> Maybe (MaybeRightOrBoth a b)
forall a. a -> Maybe a
Just (MaybeRightOrBoth a b -> Maybe (MaybeRightOrBoth a b))
-> (Maybe (These a b) -> MaybeRightOrBoth a b)
-> Maybe (These a b)
-> Maybe (MaybeRightOrBoth a b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. \case
Just (That b
b) -> b -> MaybeRightOrBoth a b
forall a b. b -> MaybeRightOrBoth a b
MRBRight b
b
Just (These a
a b
b) -> a -> b -> MaybeRightOrBoth a b
forall a b. a -> b -> MaybeRightOrBoth a b
MRBoth a
a b
b
Maybe (These a b)
_ -> MaybeRightOrBoth a b
forall a b. MaybeRightOrBoth a b
MRBNothing
{-# INLINE ymotohcid #-}
data MaybeLeft a b = MLNothing | MLeft a
deriving (MaybeLeft a b -> MaybeLeft a b -> Bool
(MaybeLeft a b -> MaybeLeft a b -> Bool)
-> (MaybeLeft a b -> MaybeLeft a b -> Bool) -> Eq (MaybeLeft a b)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a b. Eq a => MaybeLeft a b -> MaybeLeft a b -> Bool
/= :: MaybeLeft a b -> MaybeLeft a b -> Bool
$c/= :: forall a b. Eq a => MaybeLeft a b -> MaybeLeft a b -> Bool
== :: MaybeLeft a b -> MaybeLeft a b -> Bool
$c== :: forall a b. Eq a => MaybeLeft a b -> MaybeLeft a b -> Bool
Eq, Eq (MaybeLeft a b)
Eq (MaybeLeft a b)
-> (MaybeLeft a b -> MaybeLeft a b -> Ordering)
-> (MaybeLeft a b -> MaybeLeft a b -> Bool)
-> (MaybeLeft a b -> MaybeLeft a b -> Bool)
-> (MaybeLeft a b -> MaybeLeft a b -> Bool)
-> (MaybeLeft a b -> MaybeLeft a b -> Bool)
-> (MaybeLeft a b -> MaybeLeft a b -> MaybeLeft a b)
-> (MaybeLeft a b -> MaybeLeft a b -> MaybeLeft a b)
-> Ord (MaybeLeft a b)
MaybeLeft a b -> MaybeLeft a b -> Bool
MaybeLeft a b -> MaybeLeft a b -> Ordering
MaybeLeft a b -> MaybeLeft a b -> MaybeLeft a b
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 b. Ord a => Eq (MaybeLeft a b)
forall a b. Ord a => MaybeLeft a b -> MaybeLeft a b -> Bool
forall a b. Ord a => MaybeLeft a b -> MaybeLeft a b -> Ordering
forall a b.
Ord a =>
MaybeLeft a b -> MaybeLeft a b -> MaybeLeft a b
min :: MaybeLeft a b -> MaybeLeft a b -> MaybeLeft a b
$cmin :: forall a b.
Ord a =>
MaybeLeft a b -> MaybeLeft a b -> MaybeLeft a b
max :: MaybeLeft a b -> MaybeLeft a b -> MaybeLeft a b
$cmax :: forall a b.
Ord a =>
MaybeLeft a b -> MaybeLeft a b -> MaybeLeft a b
>= :: MaybeLeft a b -> MaybeLeft a b -> Bool
$c>= :: forall a b. Ord a => MaybeLeft a b -> MaybeLeft a b -> Bool
> :: MaybeLeft a b -> MaybeLeft a b -> Bool
$c> :: forall a b. Ord a => MaybeLeft a b -> MaybeLeft a b -> Bool
<= :: MaybeLeft a b -> MaybeLeft a b -> Bool
$c<= :: forall a b. Ord a => MaybeLeft a b -> MaybeLeft a b -> Bool
< :: MaybeLeft a b -> MaybeLeft a b -> Bool
$c< :: forall a b. Ord a => MaybeLeft a b -> MaybeLeft a b -> Bool
compare :: MaybeLeft a b -> MaybeLeft a b -> Ordering
$ccompare :: forall a b. Ord a => MaybeLeft a b -> MaybeLeft a b -> Ordering
$cp1Ord :: forall a b. Ord a => Eq (MaybeLeft a b)
Ord, Int -> MaybeLeft a b -> ShowS
[MaybeLeft a b] -> ShowS
MaybeLeft a b -> String
(Int -> MaybeLeft a b -> ShowS)
-> (MaybeLeft a b -> String)
-> ([MaybeLeft a b] -> ShowS)
-> Show (MaybeLeft a b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a b. Show a => Int -> MaybeLeft a b -> ShowS
forall a b. Show a => [MaybeLeft a b] -> ShowS
forall a b. Show a => MaybeLeft a b -> String
showList :: [MaybeLeft a b] -> ShowS
$cshowList :: forall a b. Show a => [MaybeLeft a b] -> ShowS
show :: MaybeLeft a b -> String
$cshow :: forall a b. Show a => MaybeLeft a b -> String
showsPrec :: Int -> MaybeLeft a b -> ShowS
$cshowsPrec :: forall a b. Show a => Int -> MaybeLeft a b -> ShowS
Show, ReadPrec [MaybeLeft a b]
ReadPrec (MaybeLeft a b)
Int -> ReadS (MaybeLeft a b)
ReadS [MaybeLeft a b]
(Int -> ReadS (MaybeLeft a b))
-> ReadS [MaybeLeft a b]
-> ReadPrec (MaybeLeft a b)
-> ReadPrec [MaybeLeft a b]
-> Read (MaybeLeft a b)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall a b. Read a => ReadPrec [MaybeLeft a b]
forall a b. Read a => ReadPrec (MaybeLeft a b)
forall a b. Read a => Int -> ReadS (MaybeLeft a b)
forall a b. Read a => ReadS [MaybeLeft a b]
readListPrec :: ReadPrec [MaybeLeft a b]
$creadListPrec :: forall a b. Read a => ReadPrec [MaybeLeft a b]
readPrec :: ReadPrec (MaybeLeft a b)
$creadPrec :: forall a b. Read a => ReadPrec (MaybeLeft a b)
readList :: ReadS [MaybeLeft a b]
$creadList :: forall a b. Read a => ReadS [MaybeLeft a b]
readsPrec :: Int -> ReadS (MaybeLeft a b)
$creadsPrec :: forall a b. Read a => Int -> ReadS (MaybeLeft a b)
Read, (forall x. MaybeLeft a b -> Rep (MaybeLeft a b) x)
-> (forall x. Rep (MaybeLeft a b) x -> MaybeLeft a b)
-> Generic (MaybeLeft a b)
forall x. Rep (MaybeLeft a b) x -> MaybeLeft a b
forall x. MaybeLeft a b -> Rep (MaybeLeft a b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a b x. Rep (MaybeLeft a b) x -> MaybeLeft a b
forall a b x. MaybeLeft a b -> Rep (MaybeLeft a b) x
$cto :: forall a b x. Rep (MaybeLeft a b) x -> MaybeLeft a b
$cfrom :: forall a b x. MaybeLeft a b -> Rep (MaybeLeft a b) x
Generic)
instance Dichotomous MaybeLeft where
dichotomy :: MaybeLeft a b -> Maybe (These a b)
dichotomy = \case
MaybeLeft a b
MLNothing -> Maybe (These a b)
forall a. Maybe a
Nothing
MLeft a
b -> These a b -> Maybe (These a b)
forall a. a -> Maybe a
Just (a -> These a b
forall a b. a -> These a b
This a
b)
{-# INLINE dichotomy #-}
ymotohcid :: Maybe (These a b) -> Maybe (MaybeLeft a b)
ymotohcid = MaybeLeft a b -> Maybe (MaybeLeft a b)
forall a. a -> Maybe a
Just (MaybeLeft a b -> Maybe (MaybeLeft a b))
-> (Maybe (These a b) -> MaybeLeft a b)
-> Maybe (These a b)
-> Maybe (MaybeLeft a b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. \case
Just (This a
a) -> a -> MaybeLeft a b
forall a b. a -> MaybeLeft a b
MLeft a
a
Just (These a
a b
_) -> a -> MaybeLeft a b
forall a b. a -> MaybeLeft a b
MLeft a
a
Maybe (These a b)
_ -> MaybeLeft a b
forall a b. MaybeLeft a b
MLNothing
{-# INLINE ymotohcid #-}
data MaybeLeftOrBoth a b = MLBNothing | MLBLeft a | MLBoth a b
deriving (MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Bool
(MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Bool)
-> (MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Bool)
-> Eq (MaybeLeftOrBoth a b)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a b.
(Eq a, Eq b) =>
MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Bool
/= :: MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Bool
$c/= :: forall a b.
(Eq a, Eq b) =>
MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Bool
== :: MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Bool
$c== :: forall a b.
(Eq a, Eq b) =>
MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Bool
Eq, Eq (MaybeLeftOrBoth a b)
Eq (MaybeLeftOrBoth a b)
-> (MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Ordering)
-> (MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Bool)
-> (MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Bool)
-> (MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Bool)
-> (MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Bool)
-> (MaybeLeftOrBoth a b
-> MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b)
-> (MaybeLeftOrBoth a b
-> MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b)
-> Ord (MaybeLeftOrBoth a b)
MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Bool
MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Ordering
MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b
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 b. (Ord a, Ord b) => Eq (MaybeLeftOrBoth a b)
forall a b.
(Ord a, Ord b) =>
MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Bool
forall a b.
(Ord a, Ord b) =>
MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Ordering
forall a b.
(Ord a, Ord b) =>
MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b
min :: MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b
$cmin :: forall a b.
(Ord a, Ord b) =>
MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b
max :: MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b
$cmax :: forall a b.
(Ord a, Ord b) =>
MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b
>= :: MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Bool
$c>= :: forall a b.
(Ord a, Ord b) =>
MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Bool
> :: MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Bool
$c> :: forall a b.
(Ord a, Ord b) =>
MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Bool
<= :: MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Bool
$c<= :: forall a b.
(Ord a, Ord b) =>
MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Bool
< :: MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Bool
$c< :: forall a b.
(Ord a, Ord b) =>
MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Bool
compare :: MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Ordering
$ccompare :: forall a b.
(Ord a, Ord b) =>
MaybeLeftOrBoth a b -> MaybeLeftOrBoth a b -> Ordering
$cp1Ord :: forall a b. (Ord a, Ord b) => Eq (MaybeLeftOrBoth a b)
Ord, Int -> MaybeLeftOrBoth a b -> ShowS
[MaybeLeftOrBoth a b] -> ShowS
MaybeLeftOrBoth a b -> String
(Int -> MaybeLeftOrBoth a b -> ShowS)
-> (MaybeLeftOrBoth a b -> String)
-> ([MaybeLeftOrBoth a b] -> ShowS)
-> Show (MaybeLeftOrBoth a b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a b. (Show a, Show b) => Int -> MaybeLeftOrBoth a b -> ShowS
forall a b. (Show a, Show b) => [MaybeLeftOrBoth a b] -> ShowS
forall a b. (Show a, Show b) => MaybeLeftOrBoth a b -> String
showList :: [MaybeLeftOrBoth a b] -> ShowS
$cshowList :: forall a b. (Show a, Show b) => [MaybeLeftOrBoth a b] -> ShowS
show :: MaybeLeftOrBoth a b -> String
$cshow :: forall a b. (Show a, Show b) => MaybeLeftOrBoth a b -> String
showsPrec :: Int -> MaybeLeftOrBoth a b -> ShowS
$cshowsPrec :: forall a b. (Show a, Show b) => Int -> MaybeLeftOrBoth a b -> ShowS
Show, ReadPrec [MaybeLeftOrBoth a b]
ReadPrec (MaybeLeftOrBoth a b)
Int -> ReadS (MaybeLeftOrBoth a b)
ReadS [MaybeLeftOrBoth a b]
(Int -> ReadS (MaybeLeftOrBoth a b))
-> ReadS [MaybeLeftOrBoth a b]
-> ReadPrec (MaybeLeftOrBoth a b)
-> ReadPrec [MaybeLeftOrBoth a b]
-> Read (MaybeLeftOrBoth a b)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall a b. (Read a, Read b) => ReadPrec [MaybeLeftOrBoth a b]
forall a b. (Read a, Read b) => ReadPrec (MaybeLeftOrBoth a b)
forall a b. (Read a, Read b) => Int -> ReadS (MaybeLeftOrBoth a b)
forall a b. (Read a, Read b) => ReadS [MaybeLeftOrBoth a b]
readListPrec :: ReadPrec [MaybeLeftOrBoth a b]
$creadListPrec :: forall a b. (Read a, Read b) => ReadPrec [MaybeLeftOrBoth a b]
readPrec :: ReadPrec (MaybeLeftOrBoth a b)
$creadPrec :: forall a b. (Read a, Read b) => ReadPrec (MaybeLeftOrBoth a b)
readList :: ReadS [MaybeLeftOrBoth a b]
$creadList :: forall a b. (Read a, Read b) => ReadS [MaybeLeftOrBoth a b]
readsPrec :: Int -> ReadS (MaybeLeftOrBoth a b)
$creadsPrec :: forall a b. (Read a, Read b) => Int -> ReadS (MaybeLeftOrBoth a b)
Read, (forall x. MaybeLeftOrBoth a b -> Rep (MaybeLeftOrBoth a b) x)
-> (forall x. Rep (MaybeLeftOrBoth a b) x -> MaybeLeftOrBoth a b)
-> Generic (MaybeLeftOrBoth a b)
forall x. Rep (MaybeLeftOrBoth a b) x -> MaybeLeftOrBoth a b
forall x. MaybeLeftOrBoth a b -> Rep (MaybeLeftOrBoth a b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a b x. Rep (MaybeLeftOrBoth a b) x -> MaybeLeftOrBoth a b
forall a b x. MaybeLeftOrBoth a b -> Rep (MaybeLeftOrBoth a b) x
$cto :: forall a b x. Rep (MaybeLeftOrBoth a b) x -> MaybeLeftOrBoth a b
$cfrom :: forall a b x. MaybeLeftOrBoth a b -> Rep (MaybeLeftOrBoth a b) x
Generic)
instance Dichotomous MaybeLeftOrBoth where
dichotomy :: MaybeLeftOrBoth a b -> Maybe (These a b)
dichotomy = \case
MaybeLeftOrBoth a b
MLBNothing -> Maybe (These a b)
forall a. Maybe a
Nothing
MLBLeft a
a -> These a b -> Maybe (These a b)
forall a. a -> Maybe a
Just (a -> These a b
forall a b. a -> These a b
This a
a)
MLBoth a
a b
b -> These a b -> Maybe (These a b)
forall a. a -> Maybe a
Just (a -> b -> These a b
forall a b. a -> b -> These a b
These a
a b
b)
{-# INLINE dichotomy #-}
ymotohcid :: Maybe (These a b) -> Maybe (MaybeLeftOrBoth a b)
ymotohcid = MaybeLeftOrBoth a b -> Maybe (MaybeLeftOrBoth a b)
forall a. a -> Maybe a
Just (MaybeLeftOrBoth a b -> Maybe (MaybeLeftOrBoth a b))
-> (Maybe (These a b) -> MaybeLeftOrBoth a b)
-> Maybe (These a b)
-> Maybe (MaybeLeftOrBoth a b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. \case
Just (This a
a) -> a -> MaybeLeftOrBoth a b
forall a b. a -> MaybeLeftOrBoth a b
MLBLeft a
a
Just (These a
a b
b) -> a -> b -> MaybeLeftOrBoth a b
forall a b. a -> b -> MaybeLeftOrBoth a b
MLBoth a
a b
b
Maybe (These a b)
_ -> MaybeLeftOrBoth a b
forall a b. MaybeLeftOrBoth a b
MLBNothing
{-# INLINE ymotohcid #-}
data MaybeEither a b = MENothing | MELeft a | MERight b
deriving (MaybeEither a b -> MaybeEither a b -> Bool
(MaybeEither a b -> MaybeEither a b -> Bool)
-> (MaybeEither a b -> MaybeEither a b -> Bool)
-> Eq (MaybeEither a b)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a b.
(Eq a, Eq b) =>
MaybeEither a b -> MaybeEither a b -> Bool
/= :: MaybeEither a b -> MaybeEither a b -> Bool
$c/= :: forall a b.
(Eq a, Eq b) =>
MaybeEither a b -> MaybeEither a b -> Bool
== :: MaybeEither a b -> MaybeEither a b -> Bool
$c== :: forall a b.
(Eq a, Eq b) =>
MaybeEither a b -> MaybeEither a b -> Bool
Eq, Eq (MaybeEither a b)
Eq (MaybeEither a b)
-> (MaybeEither a b -> MaybeEither a b -> Ordering)
-> (MaybeEither a b -> MaybeEither a b -> Bool)
-> (MaybeEither a b -> MaybeEither a b -> Bool)
-> (MaybeEither a b -> MaybeEither a b -> Bool)
-> (MaybeEither a b -> MaybeEither a b -> Bool)
-> (MaybeEither a b -> MaybeEither a b -> MaybeEither a b)
-> (MaybeEither a b -> MaybeEither a b -> MaybeEither a b)
-> Ord (MaybeEither a b)
MaybeEither a b -> MaybeEither a b -> Bool
MaybeEither a b -> MaybeEither a b -> Ordering
MaybeEither a b -> MaybeEither a b -> MaybeEither a b
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 b. (Ord a, Ord b) => Eq (MaybeEither a b)
forall a b.
(Ord a, Ord b) =>
MaybeEither a b -> MaybeEither a b -> Bool
forall a b.
(Ord a, Ord b) =>
MaybeEither a b -> MaybeEither a b -> Ordering
forall a b.
(Ord a, Ord b) =>
MaybeEither a b -> MaybeEither a b -> MaybeEither a b
min :: MaybeEither a b -> MaybeEither a b -> MaybeEither a b
$cmin :: forall a b.
(Ord a, Ord b) =>
MaybeEither a b -> MaybeEither a b -> MaybeEither a b
max :: MaybeEither a b -> MaybeEither a b -> MaybeEither a b
$cmax :: forall a b.
(Ord a, Ord b) =>
MaybeEither a b -> MaybeEither a b -> MaybeEither a b
>= :: MaybeEither a b -> MaybeEither a b -> Bool
$c>= :: forall a b.
(Ord a, Ord b) =>
MaybeEither a b -> MaybeEither a b -> Bool
> :: MaybeEither a b -> MaybeEither a b -> Bool
$c> :: forall a b.
(Ord a, Ord b) =>
MaybeEither a b -> MaybeEither a b -> Bool
<= :: MaybeEither a b -> MaybeEither a b -> Bool
$c<= :: forall a b.
(Ord a, Ord b) =>
MaybeEither a b -> MaybeEither a b -> Bool
< :: MaybeEither a b -> MaybeEither a b -> Bool
$c< :: forall a b.
(Ord a, Ord b) =>
MaybeEither a b -> MaybeEither a b -> Bool
compare :: MaybeEither a b -> MaybeEither a b -> Ordering
$ccompare :: forall a b.
(Ord a, Ord b) =>
MaybeEither a b -> MaybeEither a b -> Ordering
$cp1Ord :: forall a b. (Ord a, Ord b) => Eq (MaybeEither a b)
Ord, Int -> MaybeEither a b -> ShowS
[MaybeEither a b] -> ShowS
MaybeEither a b -> String
(Int -> MaybeEither a b -> ShowS)
-> (MaybeEither a b -> String)
-> ([MaybeEither a b] -> ShowS)
-> Show (MaybeEither a b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a b. (Show a, Show b) => Int -> MaybeEither a b -> ShowS
forall a b. (Show a, Show b) => [MaybeEither a b] -> ShowS
forall a b. (Show a, Show b) => MaybeEither a b -> String
showList :: [MaybeEither a b] -> ShowS
$cshowList :: forall a b. (Show a, Show b) => [MaybeEither a b] -> ShowS
show :: MaybeEither a b -> String
$cshow :: forall a b. (Show a, Show b) => MaybeEither a b -> String
showsPrec :: Int -> MaybeEither a b -> ShowS
$cshowsPrec :: forall a b. (Show a, Show b) => Int -> MaybeEither a b -> ShowS
Show, ReadPrec [MaybeEither a b]
ReadPrec (MaybeEither a b)
Int -> ReadS (MaybeEither a b)
ReadS [MaybeEither a b]
(Int -> ReadS (MaybeEither a b))
-> ReadS [MaybeEither a b]
-> ReadPrec (MaybeEither a b)
-> ReadPrec [MaybeEither a b]
-> Read (MaybeEither a b)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall a b. (Read a, Read b) => ReadPrec [MaybeEither a b]
forall a b. (Read a, Read b) => ReadPrec (MaybeEither a b)
forall a b. (Read a, Read b) => Int -> ReadS (MaybeEither a b)
forall a b. (Read a, Read b) => ReadS [MaybeEither a b]
readListPrec :: ReadPrec [MaybeEither a b]
$creadListPrec :: forall a b. (Read a, Read b) => ReadPrec [MaybeEither a b]
readPrec :: ReadPrec (MaybeEither a b)
$creadPrec :: forall a b. (Read a, Read b) => ReadPrec (MaybeEither a b)
readList :: ReadS [MaybeEither a b]
$creadList :: forall a b. (Read a, Read b) => ReadS [MaybeEither a b]
readsPrec :: Int -> ReadS (MaybeEither a b)
$creadsPrec :: forall a b. (Read a, Read b) => Int -> ReadS (MaybeEither a b)
Read, (forall x. MaybeEither a b -> Rep (MaybeEither a b) x)
-> (forall x. Rep (MaybeEither a b) x -> MaybeEither a b)
-> Generic (MaybeEither a b)
forall x. Rep (MaybeEither a b) x -> MaybeEither a b
forall x. MaybeEither a b -> Rep (MaybeEither a b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a b x. Rep (MaybeEither a b) x -> MaybeEither a b
forall a b x. MaybeEither a b -> Rep (MaybeEither a b) x
$cto :: forall a b x. Rep (MaybeEither a b) x -> MaybeEither a b
$cfrom :: forall a b x. MaybeEither a b -> Rep (MaybeEither a b) x
Generic)
instance Dichotomous MaybeEither where
dichotomy :: MaybeEither a b -> Maybe (These a b)
dichotomy = \case
MELeft a
a -> These a b -> Maybe (These a b)
forall a. a -> Maybe a
Just (a -> These a b
forall a b. a -> These a b
This a
a)
MERight b
b -> These a b -> Maybe (These a b)
forall a. a -> Maybe a
Just (b -> These a b
forall a b. b -> These a b
That b
b)
MaybeEither a b
_ -> Maybe (These a b)
forall a. Maybe a
Nothing
{-# INLINE dichotomy #-}
ymotohcid :: Maybe (These a b) -> Maybe (MaybeEither a b)
ymotohcid = MaybeEither a b -> Maybe (MaybeEither a b)
forall a. a -> Maybe a
Just (MaybeEither a b -> Maybe (MaybeEither a b))
-> (Maybe (These a b) -> MaybeEither a b)
-> Maybe (These a b)
-> Maybe (MaybeEither a b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. \case
Just (This a
a) -> a -> MaybeEither a b
forall a b. a -> MaybeEither a b
MELeft a
a
Just (That b
a) -> b -> MaybeEither a b
forall a b. b -> MaybeEither a b
MERight b
a
Maybe (These a b)
_ -> MaybeEither a b
forall a b. MaybeEither a b
MENothing
{-# INLINE ymotohcid #-}
data TheseOrNot a b = This' a | That' b | These' a b | Not
deriving (TheseOrNot a b -> TheseOrNot a b -> Bool
(TheseOrNot a b -> TheseOrNot a b -> Bool)
-> (TheseOrNot a b -> TheseOrNot a b -> Bool)
-> Eq (TheseOrNot a b)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a b.
(Eq a, Eq b) =>
TheseOrNot a b -> TheseOrNot a b -> Bool
/= :: TheseOrNot a b -> TheseOrNot a b -> Bool
$c/= :: forall a b.
(Eq a, Eq b) =>
TheseOrNot a b -> TheseOrNot a b -> Bool
== :: TheseOrNot a b -> TheseOrNot a b -> Bool
$c== :: forall a b.
(Eq a, Eq b) =>
TheseOrNot a b -> TheseOrNot a b -> Bool
Eq, Eq (TheseOrNot a b)
Eq (TheseOrNot a b)
-> (TheseOrNot a b -> TheseOrNot a b -> Ordering)
-> (TheseOrNot a b -> TheseOrNot a b -> Bool)
-> (TheseOrNot a b -> TheseOrNot a b -> Bool)
-> (TheseOrNot a b -> TheseOrNot a b -> Bool)
-> (TheseOrNot a b -> TheseOrNot a b -> Bool)
-> (TheseOrNot a b -> TheseOrNot a b -> TheseOrNot a b)
-> (TheseOrNot a b -> TheseOrNot a b -> TheseOrNot a b)
-> Ord (TheseOrNot a b)
TheseOrNot a b -> TheseOrNot a b -> Bool
TheseOrNot a b -> TheseOrNot a b -> Ordering
TheseOrNot a b -> TheseOrNot a b -> TheseOrNot a b
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 b. (Ord a, Ord b) => Eq (TheseOrNot a b)
forall a b.
(Ord a, Ord b) =>
TheseOrNot a b -> TheseOrNot a b -> Bool
forall a b.
(Ord a, Ord b) =>
TheseOrNot a b -> TheseOrNot a b -> Ordering
forall a b.
(Ord a, Ord b) =>
TheseOrNot a b -> TheseOrNot a b -> TheseOrNot a b
min :: TheseOrNot a b -> TheseOrNot a b -> TheseOrNot a b
$cmin :: forall a b.
(Ord a, Ord b) =>
TheseOrNot a b -> TheseOrNot a b -> TheseOrNot a b
max :: TheseOrNot a b -> TheseOrNot a b -> TheseOrNot a b
$cmax :: forall a b.
(Ord a, Ord b) =>
TheseOrNot a b -> TheseOrNot a b -> TheseOrNot a b
>= :: TheseOrNot a b -> TheseOrNot a b -> Bool
$c>= :: forall a b.
(Ord a, Ord b) =>
TheseOrNot a b -> TheseOrNot a b -> Bool
> :: TheseOrNot a b -> TheseOrNot a b -> Bool
$c> :: forall a b.
(Ord a, Ord b) =>
TheseOrNot a b -> TheseOrNot a b -> Bool
<= :: TheseOrNot a b -> TheseOrNot a b -> Bool
$c<= :: forall a b.
(Ord a, Ord b) =>
TheseOrNot a b -> TheseOrNot a b -> Bool
< :: TheseOrNot a b -> TheseOrNot a b -> Bool
$c< :: forall a b.
(Ord a, Ord b) =>
TheseOrNot a b -> TheseOrNot a b -> Bool
compare :: TheseOrNot a b -> TheseOrNot a b -> Ordering
$ccompare :: forall a b.
(Ord a, Ord b) =>
TheseOrNot a b -> TheseOrNot a b -> Ordering
$cp1Ord :: forall a b. (Ord a, Ord b) => Eq (TheseOrNot a b)
Ord, Int -> TheseOrNot a b -> ShowS
[TheseOrNot a b] -> ShowS
TheseOrNot a b -> String
(Int -> TheseOrNot a b -> ShowS)
-> (TheseOrNot a b -> String)
-> ([TheseOrNot a b] -> ShowS)
-> Show (TheseOrNot a b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a b. (Show a, Show b) => Int -> TheseOrNot a b -> ShowS
forall a b. (Show a, Show b) => [TheseOrNot a b] -> ShowS
forall a b. (Show a, Show b) => TheseOrNot a b -> String
showList :: [TheseOrNot a b] -> ShowS
$cshowList :: forall a b. (Show a, Show b) => [TheseOrNot a b] -> ShowS
show :: TheseOrNot a b -> String
$cshow :: forall a b. (Show a, Show b) => TheseOrNot a b -> String
showsPrec :: Int -> TheseOrNot a b -> ShowS
$cshowsPrec :: forall a b. (Show a, Show b) => Int -> TheseOrNot a b -> ShowS
Show, ReadPrec [TheseOrNot a b]
ReadPrec (TheseOrNot a b)
Int -> ReadS (TheseOrNot a b)
ReadS [TheseOrNot a b]
(Int -> ReadS (TheseOrNot a b))
-> ReadS [TheseOrNot a b]
-> ReadPrec (TheseOrNot a b)
-> ReadPrec [TheseOrNot a b]
-> Read (TheseOrNot a b)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall a b. (Read a, Read b) => ReadPrec [TheseOrNot a b]
forall a b. (Read a, Read b) => ReadPrec (TheseOrNot a b)
forall a b. (Read a, Read b) => Int -> ReadS (TheseOrNot a b)
forall a b. (Read a, Read b) => ReadS [TheseOrNot a b]
readListPrec :: ReadPrec [TheseOrNot a b]
$creadListPrec :: forall a b. (Read a, Read b) => ReadPrec [TheseOrNot a b]
readPrec :: ReadPrec (TheseOrNot a b)
$creadPrec :: forall a b. (Read a, Read b) => ReadPrec (TheseOrNot a b)
readList :: ReadS [TheseOrNot a b]
$creadList :: forall a b. (Read a, Read b) => ReadS [TheseOrNot a b]
readsPrec :: Int -> ReadS (TheseOrNot a b)
$creadsPrec :: forall a b. (Read a, Read b) => Int -> ReadS (TheseOrNot a b)
Read, (forall x. TheseOrNot a b -> Rep (TheseOrNot a b) x)
-> (forall x. Rep (TheseOrNot a b) x -> TheseOrNot a b)
-> Generic (TheseOrNot a b)
forall x. Rep (TheseOrNot a b) x -> TheseOrNot a b
forall x. TheseOrNot a b -> Rep (TheseOrNot a b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a b x. Rep (TheseOrNot a b) x -> TheseOrNot a b
forall a b x. TheseOrNot a b -> Rep (TheseOrNot a b) x
$cto :: forall a b x. Rep (TheseOrNot a b) x -> TheseOrNot a b
$cfrom :: forall a b x. TheseOrNot a b -> Rep (TheseOrNot a b) x
Generic)
instance Dichotomous TheseOrNot where
dichotomy :: TheseOrNot a b -> Maybe (These a b)
dichotomy = \case
This' a
a -> These a b -> Maybe (These a b)
forall a. a -> Maybe a
Just (a -> These a b
forall a b. a -> These a b
This a
a)
That' b
b -> These a b -> Maybe (These a b)
forall a. a -> Maybe a
Just (b -> These a b
forall a b. b -> These a b
That b
b)
These' a
a b
b -> These a b -> Maybe (These a b)
forall a. a -> Maybe a
Just (a -> b -> These a b
forall a b. a -> b -> These a b
These a
a b
b)
TheseOrNot a b
Not -> Maybe (These a b)
forall a. Maybe a
Nothing
{-# INLINE dichotomy #-}
ymotohcid :: Maybe (These a b) -> Maybe (TheseOrNot a b)
ymotohcid = TheseOrNot a b -> Maybe (TheseOrNot a b)
forall a. a -> Maybe a
Just (TheseOrNot a b -> Maybe (TheseOrNot a b))
-> (Maybe (These a b) -> TheseOrNot a b)
-> Maybe (These a b)
-> Maybe (TheseOrNot a b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. \case
Maybe (These a b)
Nothing -> TheseOrNot a b
forall a b. TheseOrNot a b
Not
Just (This a
a) -> a -> TheseOrNot a b
forall a b. a -> TheseOrNot a b
This' a
a
Just (That b
a) -> b -> TheseOrNot a b
forall a b. b -> TheseOrNot a b
That' b
a
Just (These a
a b
b) -> a -> b -> TheseOrNot a b
forall a b. a -> b -> TheseOrNot a b
These' a
a b
b
{-# INLINE ymotohcid #-}
newtype AltSum f a = AltSum { AltSum f a -> f a
unAltSum :: f a }
deriving (a -> AltSum f b -> AltSum f a
(a -> b) -> AltSum f a -> AltSum f b
(forall a b. (a -> b) -> AltSum f a -> AltSum f b)
-> (forall a b. a -> AltSum f b -> AltSum f a)
-> Functor (AltSum f)
forall a b. a -> AltSum f b -> AltSum f a
forall a b. (a -> b) -> AltSum f a -> AltSum f b
forall (f :: * -> *) a b.
Functor f =>
a -> AltSum f b -> AltSum f a
forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> AltSum f a -> AltSum f b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> AltSum f b -> AltSum f a
$c<$ :: forall (f :: * -> *) a b.
Functor f =>
a -> AltSum f b -> AltSum f a
fmap :: (a -> b) -> AltSum f a -> AltSum f b
$cfmap :: forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> AltSum f a -> AltSum f b
Functor, Functor (AltSum f)
a -> AltSum f a
Functor (AltSum f)
-> (forall a. a -> AltSum f a)
-> (forall a b. AltSum f (a -> b) -> AltSum f a -> AltSum f b)
-> (forall a b c.
(a -> b -> c) -> AltSum f a -> AltSum f b -> AltSum f c)
-> (forall a b. AltSum f a -> AltSum f b -> AltSum f b)
-> (forall a b. AltSum f a -> AltSum f b -> AltSum f a)
-> Applicative (AltSum f)
AltSum f a -> AltSum f b -> AltSum f b
AltSum f a -> AltSum f b -> AltSum f a
AltSum f (a -> b) -> AltSum f a -> AltSum f b
(a -> b -> c) -> AltSum f a -> AltSum f b -> AltSum f c
forall a. a -> AltSum f a
forall a b. AltSum f a -> AltSum f b -> AltSum f a
forall a b. AltSum f a -> AltSum f b -> AltSum f b
forall a b. AltSum f (a -> b) -> AltSum f a -> AltSum f b
forall a b c.
(a -> b -> c) -> AltSum f a -> AltSum f b -> AltSum f c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
forall (f :: * -> *). Applicative f => Functor (AltSum f)
forall (f :: * -> *) a. Applicative f => a -> AltSum f a
forall (f :: * -> *) a b.
Applicative f =>
AltSum f a -> AltSum f b -> AltSum f a
forall (f :: * -> *) a b.
Applicative f =>
AltSum f a -> AltSum f b -> AltSum f b
forall (f :: * -> *) a b.
Applicative f =>
AltSum f (a -> b) -> AltSum f a -> AltSum f b
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> AltSum f a -> AltSum f b -> AltSum f c
<* :: AltSum f a -> AltSum f b -> AltSum f a
$c<* :: forall (f :: * -> *) a b.
Applicative f =>
AltSum f a -> AltSum f b -> AltSum f a
*> :: AltSum f a -> AltSum f b -> AltSum f b
$c*> :: forall (f :: * -> *) a b.
Applicative f =>
AltSum f a -> AltSum f b -> AltSum f b
liftA2 :: (a -> b -> c) -> AltSum f a -> AltSum f b -> AltSum f c
$cliftA2 :: forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> AltSum f a -> AltSum f b -> AltSum f c
<*> :: AltSum f (a -> b) -> AltSum f a -> AltSum f b
$c<*> :: forall (f :: * -> *) a b.
Applicative f =>
AltSum f (a -> b) -> AltSum f a -> AltSum f b
pure :: a -> AltSum f a
$cpure :: forall (f :: * -> *) a. Applicative f => a -> AltSum f a
$cp1Applicative :: forall (f :: * -> *). Applicative f => Functor (AltSum f)
Applicative, Applicative (AltSum f)
AltSum f a
Applicative (AltSum f)
-> (forall a. AltSum f a)
-> (forall a. AltSum f a -> AltSum f a -> AltSum f a)
-> (forall a. AltSum f a -> AltSum f [a])
-> (forall a. AltSum f a -> AltSum f [a])
-> Alternative (AltSum f)
AltSum f a -> AltSum f a -> AltSum f a
AltSum f a -> AltSum f [a]
AltSum f a -> AltSum f [a]
forall a. AltSum f a
forall a. AltSum f a -> AltSum f [a]
forall a. AltSum f a -> AltSum f a -> AltSum f a
forall (f :: * -> *).
Applicative f
-> (forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
forall (f :: * -> *). Alternative f => Applicative (AltSum f)
forall (f :: * -> *) a. Alternative f => AltSum f a
forall (f :: * -> *) a. Alternative f => AltSum f a -> AltSum f [a]
forall (f :: * -> *) a.
Alternative f =>
AltSum f a -> AltSum f a -> AltSum f a
many :: AltSum f a -> AltSum f [a]
$cmany :: forall (f :: * -> *) a. Alternative f => AltSum f a -> AltSum f [a]
some :: AltSum f a -> AltSum f [a]
$csome :: forall (f :: * -> *) a. Alternative f => AltSum f a -> AltSum f [a]
<|> :: AltSum f a -> AltSum f a -> AltSum f a
$c<|> :: forall (f :: * -> *) a.
Alternative f =>
AltSum f a -> AltSum f a -> AltSum f a
empty :: AltSum f a
$cempty :: forall (f :: * -> *) a. Alternative f => AltSum f a
$cp1Alternative :: forall (f :: * -> *). Alternative f => Applicative (AltSum f)
Alternative)
instance Alternative f => Semigroup (AltSum f a) where
AltSum f a
a <> :: AltSum f a -> AltSum f a -> AltSum f a
<> AltSum f a
b = f a -> AltSum f a
forall (f :: * -> *) a. f a -> AltSum f a
AltSum (f a
a f a -> f a -> f a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> f a
b)
instance Alternative f => Monoid (AltSum f a) where
mempty :: AltSum f a
mempty = AltSum f a
forall (f :: * -> *) a. Alternative f => f a
empty
AltSum f a
a mappend :: AltSum f a -> AltSum f a -> AltSum f a
`mappend` AltSum f a
b = f a -> AltSum f a
forall (f :: * -> *) a. f a -> AltSum f a
AltSum (f a
a f a -> f a -> f a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> f a
b)
mfold' :: (Foldable f, Alternative m) => f a -> m a
mfold' :: f a -> m a
mfold' = AltSum m a -> m a
forall (f :: * -> *) a. AltSum f a -> f a
unAltSum (AltSum m a -> m a) -> (f a -> AltSum m a) -> f a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> AltSum m a) -> f a -> AltSum m a
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (m a -> AltSum m a
forall (f :: * -> *) a. f a -> AltSum f a
AltSum (m a -> AltSum m a) -> (a -> m a) -> a -> AltSum m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure)
mlefts :: (Bifoldable f, Alternative m) => f a b -> m a
mlefts :: f a b -> m a
mlefts = AltSum m a -> m a
forall (f :: * -> *) a. AltSum f a -> f a
unAltSum (AltSum m a -> m a) -> (f a b -> AltSum m a) -> f a b -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> AltSum m a) -> (b -> AltSum m a) -> f a b -> AltSum m a
forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap (m a -> AltSum m a
forall (f :: * -> *) a. f a -> AltSum f a
AltSum (m a -> AltSum m a) -> (a -> m a) -> a -> AltSum m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure) (AltSum m a -> b -> AltSum m a
forall a b. a -> b -> a
const AltSum m a
forall a. Monoid a => a
mempty)
mrights :: (Bifoldable f, Alternative m) => f a b -> m b
mrights :: f a b -> m b
mrights = AltSum m b -> m b
forall (f :: * -> *) a. AltSum f a -> f a
unAltSum (AltSum m b -> m b) -> (f a b -> AltSum m b) -> f a b -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> AltSum m b) -> (b -> AltSum m b) -> f a b -> AltSum m b
forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap (AltSum m b -> a -> AltSum m b
forall a b. a -> b -> a
const AltSum m b
forall a. Monoid a => a
mempty) (m b -> AltSum m b
forall (f :: * -> *) a. f a -> AltSum f a
AltSum (m b -> AltSum m b) -> (b -> m b) -> b -> AltSum m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> m b
forall (f :: * -> *) a. Applicative f => a -> f a
pure)
hushRight :: Dichotomous g => g l r -> Maybe l
hushRight :: g l r -> Maybe l
hushRight g l r
d = case g l r -> Maybe (These l r)
forall (f :: * -> * -> *) a b.
Dichotomous f =>
f a b -> Maybe (These a b)
dichotomy g l r
d of
Just (This l
x) -> l -> Maybe l
forall a. a -> Maybe a
Just l
x
Just (These l
x r
_) -> l -> Maybe l
forall a. a -> Maybe a
Just l
x
Maybe (These l r)
_ -> Maybe l
forall a. Maybe a
Nothing
hushLeft :: Dichotomous g => g l r -> Maybe r
hushLeft :: g l r -> Maybe r
hushLeft g l r
d = case g l r -> Maybe (These l r)
forall (f :: * -> * -> *) a b.
Dichotomous f =>
f a b -> Maybe (These a b)
dichotomy g l r
d of
Just (That r
x) -> r -> Maybe r
forall a. a -> Maybe a
Just r
x
Just (These l
_ r
x) -> r -> Maybe r
forall a. a -> Maybe a
Just r
x
Maybe (These l r)
_ -> Maybe r
forall a. Maybe a
Nothing
flipThese :: These a b -> These b a
flipThese :: These a b -> These b a
flipThese = \case This a
x -> a -> These b a
forall a b. b -> These a b
That a
x; That b
x -> b -> These b a
forall a b. a -> These a b
This b
x; These a
x b
y -> b -> a -> These b a
forall a b. a -> b -> These a b
These b
y a
x
{-# INLINABLE flipThese #-}
swap :: Dichotomous g => g a b -> Maybe (g b a)
swap :: g a b -> Maybe (g b a)
swap g a b
g = Maybe (These b a) -> Maybe (g b a)
forall (f :: * -> * -> *) a b.
Dichotomous f =>
Maybe (These a b) -> Maybe (f a b)
ymotohcid (Maybe (These b a) -> Maybe (g b a))
-> Maybe (These b a) -> Maybe (g b a)
forall a b. (a -> b) -> a -> b
$ case g a b -> Maybe (These a b)
forall (f :: * -> * -> *) a b.
Dichotomous f =>
f a b -> Maybe (These a b)
dichotomy g a b
g of
Maybe (These a b)
Nothing -> Maybe (These b a)
forall a. Maybe a
Nothing
Just (This a
a) -> These b a -> Maybe (These b a)
forall a. a -> Maybe a
Just (a -> These b a
forall a b. b -> These a b
That a
a)
Just (That b
b) -> These b a -> Maybe (These b a)
forall a. a -> Maybe a
Just (b -> These b a
forall a b. a -> These a b
This b
b)
Just (These a
a b
b) -> These b a -> Maybe (These b a)
forall a. a -> Maybe a
Just (b -> a -> These b a
forall a b. a -> b -> These a b
These b
b a
a)
{-# INLINABLE swap #-}