{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_HADDOCK not-home #-}
module Servant.API.Alternative ((:<|>)(..)) where
import Control.Applicative (liftA2)
import Data.Biapplicative
(Biapplicative (..))
import Data.Bifoldable
(Bifoldable (..))
import Data.Bifunctor
(Bifunctor (..))
import Data.Bitraversable
(Bitraversable (..))
import Data.Typeable
(Typeable)
import Prelude ()
import Prelude.Compat
data a :<|> b = a :<|> b
deriving (Typeable, (a :<|> b) -> (a :<|> b) -> Bool
((a :<|> b) -> (a :<|> b) -> Bool)
-> ((a :<|> b) -> (a :<|> b) -> Bool) -> Eq (a :<|> b)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a b. (Eq a, Eq b) => (a :<|> b) -> (a :<|> b) -> Bool
$c== :: forall a b. (Eq a, Eq b) => (a :<|> b) -> (a :<|> b) -> Bool
== :: (a :<|> b) -> (a :<|> b) -> Bool
$c/= :: forall a b. (Eq a, Eq b) => (a :<|> b) -> (a :<|> b) -> Bool
/= :: (a :<|> b) -> (a :<|> b) -> Bool
Eq, Int -> (a :<|> b) -> ShowS
[a :<|> b] -> ShowS
(a :<|> b) -> String
(Int -> (a :<|> b) -> ShowS)
-> ((a :<|> b) -> String)
-> ([a :<|> b] -> ShowS)
-> Show (a :<|> b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a b. (Show a, Show b) => Int -> (a :<|> b) -> ShowS
forall a b. (Show a, Show b) => [a :<|> b] -> ShowS
forall a b. (Show a, Show b) => (a :<|> b) -> String
$cshowsPrec :: forall a b. (Show a, Show b) => Int -> (a :<|> b) -> ShowS
showsPrec :: Int -> (a :<|> b) -> ShowS
$cshow :: forall a b. (Show a, Show b) => (a :<|> b) -> String
show :: (a :<|> b) -> String
$cshowList :: forall a b. (Show a, Show b) => [a :<|> b] -> ShowS
showList :: [a :<|> b] -> ShowS
Show, (forall a b. (a -> b) -> (a :<|> a) -> a :<|> b)
-> (forall a b. a -> (a :<|> b) -> a :<|> a) -> Functor ((:<|>) a)
forall a b. a -> (a :<|> b) -> a :<|> a
forall a b. (a -> b) -> (a :<|> a) -> a :<|> b
forall a a b. a -> (a :<|> b) -> a :<|> a
forall a a b. (a -> b) -> (a :<|> a) -> a :<|> b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a a b. (a -> b) -> (a :<|> a) -> a :<|> b
fmap :: forall a b. (a -> b) -> (a :<|> a) -> a :<|> b
$c<$ :: forall a a b. a -> (a :<|> b) -> a :<|> a
<$ :: forall a b. a -> (a :<|> b) -> a :<|> a
Functor, Functor ((:<|>) a)
Foldable ((:<|>) a)
(Functor ((:<|>) a), Foldable ((:<|>) a)) =>
(forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> (a :<|> a) -> f (a :<|> b))
-> (forall (f :: * -> *) a.
Applicative f =>
(a :<|> f a) -> f (a :<|> a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> (a :<|> a) -> m (a :<|> b))
-> (forall (m :: * -> *) a.
Monad m =>
(a :<|> m a) -> m (a :<|> a))
-> Traversable ((:<|>) a)
forall a. Functor ((:<|>) a)
forall a. Foldable ((:<|>) a)
forall a (m :: * -> *) a. Monad m => (a :<|> m a) -> m (a :<|> a)
forall a (f :: * -> *) a.
Applicative f =>
(a :<|> f a) -> f (a :<|> a)
forall a (m :: * -> *) a b.
Monad m =>
(a -> m b) -> (a :<|> a) -> m (a :<|> b)
forall a (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> (a :<|> a) -> f (a :<|> b)
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => (a :<|> m a) -> m (a :<|> a)
forall (f :: * -> *) a.
Applicative f =>
(a :<|> f a) -> f (a :<|> a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> (a :<|> a) -> m (a :<|> b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> (a :<|> a) -> f (a :<|> b)
$ctraverse :: forall a (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> (a :<|> a) -> f (a :<|> b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> (a :<|> a) -> f (a :<|> b)
$csequenceA :: forall a (f :: * -> *) a.
Applicative f =>
(a :<|> f a) -> f (a :<|> a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
(a :<|> f a) -> f (a :<|> a)
$cmapM :: forall a (m :: * -> *) a b.
Monad m =>
(a -> m b) -> (a :<|> a) -> m (a :<|> b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> (a :<|> a) -> m (a :<|> b)
$csequence :: forall a (m :: * -> *) a. Monad m => (a :<|> m a) -> m (a :<|> a)
sequence :: forall (m :: * -> *) a. Monad m => (a :<|> m a) -> m (a :<|> a)
Traversable, (forall m. Monoid m => (a :<|> m) -> m)
-> (forall m a. Monoid m => (a -> m) -> (a :<|> a) -> m)
-> (forall m a. Monoid m => (a -> m) -> (a :<|> a) -> m)
-> (forall a b. (a -> b -> b) -> b -> (a :<|> a) -> b)
-> (forall a b. (a -> b -> b) -> b -> (a :<|> a) -> b)
-> (forall b a. (b -> a -> b) -> b -> (a :<|> a) -> b)
-> (forall b a. (b -> a -> b) -> b -> (a :<|> a) -> b)
-> (forall a. (a -> a -> a) -> (a :<|> a) -> a)
-> (forall a. (a -> a -> a) -> (a :<|> a) -> a)
-> (forall a. (a :<|> a) -> [a])
-> (forall a. (a :<|> a) -> Bool)
-> (forall a. (a :<|> a) -> Int)
-> (forall a. Eq a => a -> (a :<|> a) -> Bool)
-> (forall a. Ord a => (a :<|> a) -> a)
-> (forall a. Ord a => (a :<|> a) -> a)
-> (forall a. Num a => (a :<|> a) -> a)
-> (forall a. Num a => (a :<|> a) -> a)
-> Foldable ((:<|>) a)
forall a. Eq a => a -> (a :<|> a) -> Bool
forall a. Num a => (a :<|> a) -> a
forall a. Ord a => (a :<|> a) -> a
forall m. Monoid m => (a :<|> m) -> m
forall a. (a :<|> a) -> Bool
forall a. (a :<|> a) -> Int
forall a. (a :<|> a) -> [a]
forall a. (a -> a -> a) -> (a :<|> a) -> a
forall a a. Eq a => a -> (a :<|> a) -> Bool
forall a a. Num a => (a :<|> a) -> a
forall a a. Ord a => (a :<|> a) -> a
forall m a. Monoid m => (a -> m) -> (a :<|> a) -> m
forall a m. Monoid m => (a :<|> m) -> m
forall a a. (a :<|> a) -> Bool
forall a a. (a :<|> a) -> Int
forall a a. (a :<|> a) -> [a]
forall b a. (b -> a -> b) -> b -> (a :<|> a) -> b
forall a b. (a -> b -> b) -> b -> (a :<|> a) -> b
forall a a. (a -> a -> a) -> (a :<|> a) -> a
forall a m a. Monoid m => (a -> m) -> (a :<|> a) -> m
forall a b a. (b -> a -> b) -> b -> (a :<|> a) -> b
forall a a b. (a -> b -> b) -> b -> (a :<|> a) -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall a m. Monoid m => (a :<|> m) -> m
fold :: forall m. Monoid m => (a :<|> m) -> m
$cfoldMap :: forall a m a. Monoid m => (a -> m) -> (a :<|> a) -> m
foldMap :: forall m a. Monoid m => (a -> m) -> (a :<|> a) -> m
$cfoldMap' :: forall a m a. Monoid m => (a -> m) -> (a :<|> a) -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> (a :<|> a) -> m
$cfoldr :: forall a a b. (a -> b -> b) -> b -> (a :<|> a) -> b
foldr :: forall a b. (a -> b -> b) -> b -> (a :<|> a) -> b
$cfoldr' :: forall a a b. (a -> b -> b) -> b -> (a :<|> a) -> b
foldr' :: forall a b. (a -> b -> b) -> b -> (a :<|> a) -> b
$cfoldl :: forall a b a. (b -> a -> b) -> b -> (a :<|> a) -> b
foldl :: forall b a. (b -> a -> b) -> b -> (a :<|> a) -> b
$cfoldl' :: forall a b a. (b -> a -> b) -> b -> (a :<|> a) -> b
foldl' :: forall b a. (b -> a -> b) -> b -> (a :<|> a) -> b
$cfoldr1 :: forall a a. (a -> a -> a) -> (a :<|> a) -> a
foldr1 :: forall a. (a -> a -> a) -> (a :<|> a) -> a
$cfoldl1 :: forall a a. (a -> a -> a) -> (a :<|> a) -> a
foldl1 :: forall a. (a -> a -> a) -> (a :<|> a) -> a
$ctoList :: forall a a. (a :<|> a) -> [a]
toList :: forall a. (a :<|> a) -> [a]
$cnull :: forall a a. (a :<|> a) -> Bool
null :: forall a. (a :<|> a) -> Bool
$clength :: forall a a. (a :<|> a) -> Int
length :: forall a. (a :<|> a) -> Int
$celem :: forall a a. Eq a => a -> (a :<|> a) -> Bool
elem :: forall a. Eq a => a -> (a :<|> a) -> Bool
$cmaximum :: forall a a. Ord a => (a :<|> a) -> a
maximum :: forall a. Ord a => (a :<|> a) -> a
$cminimum :: forall a a. Ord a => (a :<|> a) -> a
minimum :: forall a. Ord a => (a :<|> a) -> a
$csum :: forall a a. Num a => (a :<|> a) -> a
sum :: forall a. Num a => (a :<|> a) -> a
$cproduct :: forall a a. Num a => (a :<|> a) -> a
product :: forall a. Num a => (a :<|> a) -> a
Foldable, a :<|> b
(a :<|> b) -> (a :<|> b) -> Bounded (a :<|> b)
forall a. a -> a -> Bounded a
forall a b. (Bounded a, Bounded b) => a :<|> b
$cminBound :: forall a b. (Bounded a, Bounded b) => a :<|> b
minBound :: a :<|> b
$cmaxBound :: forall a b. (Bounded a, Bounded b) => a :<|> b
maxBound :: a :<|> b
Bounded)
infixr 3 :<|>
instance (Semigroup a, Semigroup b) => Semigroup (a :<|> b) where
(a
a :<|> b
b) <> :: (a :<|> b) -> (a :<|> b) -> a :<|> b
<> (a
a' :<|> b
b') = (a
a a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
a') a -> b -> a :<|> b
forall a b. a -> b -> a :<|> b
:<|> (b
b b -> b -> b
forall a. Semigroup a => a -> a -> a
<> b
b')
instance (Monoid a, Monoid b) => Monoid (a :<|> b) where
mempty :: a :<|> b
mempty = a
forall a. Monoid a => a
mempty a -> b -> a :<|> b
forall a b. a -> b -> a :<|> b
:<|> b
forall a. Monoid a => a
mempty
(a
a :<|> b
b) mappend :: (a :<|> b) -> (a :<|> b) -> a :<|> b
`mappend` (a
a' :<|> b
b') = (a
a a -> a -> a
forall a. Monoid a => a -> a -> a
`mappend` a
a') a -> b -> a :<|> b
forall a b. a -> b -> a :<|> b
:<|> (b
b b -> b -> b
forall a. Monoid a => a -> a -> a
`mappend` b
b')
instance Bifoldable (:<|>) where
bifoldMap :: forall m a b. Monoid m => (a -> m) -> (b -> m) -> (a :<|> b) -> m
bifoldMap a -> m
f b -> m
g ~(a
a :<|> b
b) = a -> m
f a
a m -> m -> m
forall a. Monoid a => a -> a -> a
`mappend` b -> m
g b
b
instance Bifunctor (:<|>) where
bimap :: forall a b c d. (a -> b) -> (c -> d) -> (a :<|> c) -> b :<|> d
bimap a -> b
f c -> d
g ~(a
a :<|> c
b) = a -> b
f a
a b -> d -> b :<|> d
forall a b. a -> b -> a :<|> b
:<|> c -> d
g c
b
instance Biapplicative (:<|>) where
bipure :: forall a b. a -> b -> a :<|> b
bipure = a -> b -> a :<|> b
forall a b. a -> b -> a :<|> b
(:<|>)
(a -> b
f :<|> c -> d
g) <<*>> :: forall a b c d. ((a -> b) :<|> (c -> d)) -> (a :<|> c) -> b :<|> d
<<*>> (a
a :<|> c
b) = a -> b
f a
a b -> d -> b :<|> d
forall a b. a -> b -> a :<|> b
:<|> c -> d
g c
b
instance Bitraversable (:<|>) where
bitraverse :: forall (f :: * -> *) a c b d.
Applicative f =>
(a -> f c) -> (b -> f d) -> (a :<|> b) -> f (c :<|> d)
bitraverse a -> f c
f b -> f d
g ~(a
a :<|> b
b) = (c -> d -> c :<|> d) -> f c -> f d -> f (c :<|> d)
forall a b c. (a -> b -> c) -> f a -> f b -> f c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 c -> d -> c :<|> d
forall a b. a -> b -> a :<|> b
(:<|>) (a -> f c
f a
a) (b -> f d
g b
b)