{-# LANGUAGE Safe #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Data.Bifoldable
( Bifoldable(..)
, bifoldr'
, bifoldr1
, bifoldrM
, bifoldl'
, bifoldl1
, bifoldlM
, bitraverse_
, bifor_
, bimapM_
, biforM_
, bimsum
, bisequenceA_
, bisequence_
, biasum
, biList
, binull
, bilength
, bielem
, bimaximum
, biminimum
, bisum
, biproduct
, biconcat
, biconcatMap
, biand
, bior
, biany
, biall
, bimaximumBy
, biminimumBy
, binotElem
, bifind
) where
import Control.Applicative
import Data.Functor.Utils (Max(..), Min(..), (#.))
import Data.Maybe (fromMaybe)
import Data.Monoid
import GHC.Generics (K1(..))
class Bifoldable p where
{-# MINIMAL bifoldr | bifoldMap #-}
bifold :: Monoid m => p m m -> m
bifold = forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap forall a. a -> a
id forall a. a -> a
id
bifoldMap :: Monoid m => (a -> m) -> (b -> m) -> p a b -> m
bifoldMap a -> m
f b -> m
g = forall (p :: * -> * -> *) a c b.
Bifoldable p =>
(a -> c -> c) -> (b -> c -> c) -> c -> p a b -> c
bifoldr (forall a. Monoid a => a -> a -> a
mappend forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m
f) (forall a. Monoid a => a -> a -> a
mappend forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> m
g) forall a. Monoid a => a
mempty
bifoldr :: (a -> c -> c) -> (b -> c -> c) -> c -> p a b -> c
bifoldr a -> c -> c
f b -> c -> c
g c
z p a b
t = forall a. Endo a -> a -> a
appEndo (forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap (forall a. (a -> a) -> Endo a
Endo forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. a -> c -> c
f) (forall a. (a -> a) -> Endo a
Endo forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. b -> c -> c
g) p a b
t) c
z
bifoldl :: (c -> a -> c) -> (c -> b -> c) -> c -> p a b -> c
bifoldl c -> a -> c
f c -> b -> c
g c
z p a b
t = forall a. Endo a -> a -> a
appEndo (forall a. Dual a -> a
getDual (forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap (forall a. a -> Dual a
Dual forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (a -> a) -> Endo a
Endo forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b c. (a -> b -> c) -> b -> a -> c
flip c -> a -> c
f)
(forall a. a -> Dual a
Dual forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (a -> a) -> Endo a
Endo forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b c. (a -> b -> c) -> b -> a -> c
flip c -> b -> c
g) p a b
t)) c
z
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 forall a. Monoid a => a -> a -> a
`mappend` b -> m
g b
b
instance Bifoldable Const where
bifoldMap :: forall m a b. Monoid m => (a -> m) -> (b -> m) -> Const a b -> m
bifoldMap a -> m
f b -> m
_ (Const a
a) = a -> m
f a
a
instance Bifoldable (K1 i) where
bifoldMap :: forall m a b. Monoid m => (a -> m) -> (b -> m) -> K1 i a b -> m
bifoldMap a -> m
f b -> m
_ (K1 a
c) = a -> m
f a
c
instance Bifoldable ((,,) x) where
bifoldMap :: forall m a b. Monoid m => (a -> m) -> (b -> m) -> (x, a, b) -> m
bifoldMap a -> m
f b -> m
g ~(x
_,a
a,b
b) = a -> m
f a
a forall a. Monoid a => a -> a -> a
`mappend` b -> m
g b
b
instance Bifoldable ((,,,) x y) where
bifoldMap :: forall m a b. Monoid m => (a -> m) -> (b -> m) -> (x, y, a, b) -> m
bifoldMap a -> m
f b -> m
g ~(x
_,y
_,a
a,b
b) = a -> m
f a
a forall a. Monoid a => a -> a -> a
`mappend` b -> m
g b
b
instance Bifoldable ((,,,,) x y z) where
bifoldMap :: forall m a b.
Monoid m =>
(a -> m) -> (b -> m) -> (x, y, z, a, b) -> m
bifoldMap a -> m
f b -> m
g ~(x
_,y
_,z
_,a
a,b
b) = a -> m
f a
a forall a. Monoid a => a -> a -> a
`mappend` b -> m
g b
b
instance Bifoldable ((,,,,,) x y z w) where
bifoldMap :: forall m a b.
Monoid m =>
(a -> m) -> (b -> m) -> (x, y, z, w, a, b) -> m
bifoldMap a -> m
f b -> m
g ~(x
_,y
_,z
_,w
_,a
a,b
b) = a -> m
f a
a forall a. Monoid a => a -> a -> a
`mappend` b -> m
g b
b
instance Bifoldable ((,,,,,,) x y z w v) where
bifoldMap :: forall m a b.
Monoid m =>
(a -> m) -> (b -> m) -> (x, y, z, w, v, a, b) -> m
bifoldMap a -> m
f b -> m
g ~(x
_,y
_,z
_,w
_,v
_,a
a,b
b) = a -> m
f a
a forall a. Monoid a => a -> a -> a
`mappend` b -> m
g b
b
instance Bifoldable Either where
bifoldMap :: forall m a b. Monoid m => (a -> m) -> (b -> m) -> Either a b -> m
bifoldMap a -> m
f b -> m
_ (Left a
a) = a -> m
f a
a
bifoldMap a -> m
_ b -> m
g (Right b
b) = b -> m
g b
b
bifoldr' :: Bifoldable t => (a -> c -> c) -> (b -> c -> c) -> c -> t a b -> c
bifoldr' :: forall (t :: * -> * -> *) a c b.
Bifoldable t =>
(a -> c -> c) -> (b -> c -> c) -> c -> t a b -> c
bifoldr' a -> c -> c
f b -> c -> c
g c
z0 t a b
xs = forall (p :: * -> * -> *) c a b.
Bifoldable p =>
(c -> a -> c) -> (c -> b -> c) -> c -> p a b -> c
bifoldl forall {b}. (c -> b) -> a -> c -> b
f' forall {b}. (c -> b) -> b -> c -> b
g' forall a. a -> a
id t a b
xs c
z0 where
f' :: (c -> b) -> a -> c -> b
f' c -> b
k a
x c
z = c -> b
k forall a b. (a -> b) -> a -> b
$! a -> c -> c
f a
x c
z
g' :: (c -> b) -> b -> c -> b
g' c -> b
k b
x c
z = c -> b
k forall a b. (a -> b) -> a -> b
$! b -> c -> c
g b
x c
z
bifoldr1 :: Bifoldable t => (a -> a -> a) -> t a a -> a
bifoldr1 :: forall (t :: * -> * -> *) a.
Bifoldable t =>
(a -> a -> a) -> t a a -> a
bifoldr1 a -> a -> a
f t a a
xs = forall a. a -> Maybe a -> a
fromMaybe (forall a. HasCallStack => [Char] -> a
error [Char]
"bifoldr1: empty structure")
(forall (p :: * -> * -> *) a c b.
Bifoldable p =>
(a -> c -> c) -> (b -> c -> c) -> c -> p a b -> c
bifoldr a -> Maybe a -> Maybe a
mbf a -> Maybe a -> Maybe a
mbf forall a. Maybe a
Nothing t a a
xs)
where
mbf :: a -> Maybe a -> Maybe a
mbf a
x Maybe a
m = forall a. a -> Maybe a
Just (case Maybe a
m of
Maybe a
Nothing -> a
x
Just a
y -> a -> a -> a
f a
x a
y)
bifoldrM :: (Bifoldable t, Monad m)
=> (a -> c -> m c) -> (b -> c -> m c) -> c -> t a b -> m c
bifoldrM :: forall (t :: * -> * -> *) (m :: * -> *) a c b.
(Bifoldable t, Monad m) =>
(a -> c -> m c) -> (b -> c -> m c) -> c -> t a b -> m c
bifoldrM a -> c -> m c
f b -> c -> m c
g c
z0 t a b
xs = forall (p :: * -> * -> *) c a b.
Bifoldable p =>
(c -> a -> c) -> (c -> b -> c) -> c -> p a b -> c
bifoldl forall {b}. (c -> m b) -> a -> c -> m b
f' forall {b}. (c -> m b) -> b -> c -> m b
g' forall (m :: * -> *) a. Monad m => a -> m a
return t a b
xs c
z0 where
f' :: (c -> m b) -> a -> c -> m b
f' c -> m b
k a
x c
z = a -> c -> m c
f a
x c
z forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= c -> m b
k
g' :: (c -> m b) -> b -> c -> m b
g' c -> m b
k b
x c
z = b -> c -> m c
g b
x c
z forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= c -> m b
k
bifoldl':: Bifoldable t => (a -> b -> a) -> (a -> c -> a) -> a -> t b c -> a
bifoldl' :: forall (t :: * -> * -> *) a b c.
Bifoldable t =>
(a -> b -> a) -> (a -> c -> a) -> a -> t b c -> a
bifoldl' a -> b -> a
f a -> c -> a
g a
z0 t b c
xs = forall (p :: * -> * -> *) a c b.
Bifoldable p =>
(a -> c -> c) -> (b -> c -> c) -> c -> p a b -> c
bifoldr forall {b}. b -> (a -> b) -> a -> b
f' forall {b}. c -> (a -> b) -> a -> b
g' forall a. a -> a
id t b c
xs a
z0 where
f' :: b -> (a -> b) -> a -> b
f' b
x a -> b
k a
z = a -> b
k forall a b. (a -> b) -> a -> b
$! a -> b -> a
f a
z b
x
g' :: c -> (a -> b) -> a -> b
g' c
x a -> b
k a
z = a -> b
k forall a b. (a -> b) -> a -> b
$! a -> c -> a
g a
z c
x
bifoldl1 :: Bifoldable t => (a -> a -> a) -> t a a -> a
bifoldl1 :: forall (t :: * -> * -> *) a.
Bifoldable t =>
(a -> a -> a) -> t a a -> a
bifoldl1 a -> a -> a
f t a a
xs = forall a. a -> Maybe a -> a
fromMaybe (forall a. HasCallStack => [Char] -> a
error [Char]
"bifoldl1: empty structure")
(forall (p :: * -> * -> *) c a b.
Bifoldable p =>
(c -> a -> c) -> (c -> b -> c) -> c -> p a b -> c
bifoldl Maybe a -> a -> Maybe a
mbf Maybe a -> a -> Maybe a
mbf forall a. Maybe a
Nothing t a a
xs)
where
mbf :: Maybe a -> a -> Maybe a
mbf Maybe a
m a
y = forall a. a -> Maybe a
Just (case Maybe a
m of
Maybe a
Nothing -> a
y
Just a
x -> a -> a -> a
f a
x a
y)
bifoldlM :: (Bifoldable t, Monad m)
=> (a -> b -> m a) -> (a -> c -> m a) -> a -> t b c -> m a
bifoldlM :: forall (t :: * -> * -> *) (m :: * -> *) a b c.
(Bifoldable t, Monad m) =>
(a -> b -> m a) -> (a -> c -> m a) -> a -> t b c -> m a
bifoldlM a -> b -> m a
f a -> c -> m a
g a
z0 t b c
xs = forall (p :: * -> * -> *) a c b.
Bifoldable p =>
(a -> c -> c) -> (b -> c -> c) -> c -> p a b -> c
bifoldr forall {b}. b -> (a -> m b) -> a -> m b
f' forall {b}. c -> (a -> m b) -> a -> m b
g' forall (m :: * -> *) a. Monad m => a -> m a
return t b c
xs a
z0 where
f' :: b -> (a -> m b) -> a -> m b
f' b
x a -> m b
k a
z = a -> b -> m a
f a
z b
x forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> m b
k
g' :: c -> (a -> m b) -> a -> m b
g' c
x a -> m b
k a
z = a -> c -> m a
g a
z c
x forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> m b
k
bitraverse_ :: (Bifoldable t, Applicative f)
=> (a -> f c) -> (b -> f d) -> t a b -> f ()
bitraverse_ :: forall (t :: * -> * -> *) (f :: * -> *) a c b d.
(Bifoldable t, Applicative f) =>
(a -> f c) -> (b -> f d) -> t a b -> f ()
bitraverse_ a -> f c
f b -> f d
g = forall (p :: * -> * -> *) a c b.
Bifoldable p =>
(a -> c -> c) -> (b -> c -> c) -> c -> p a b -> c
bifoldr (forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
(*>) forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> f c
f) (forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
(*>) forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> f d
g) (forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
bifor_ :: (Bifoldable t, Applicative f)
=> t a b -> (a -> f c) -> (b -> f d) -> f ()
bifor_ :: forall (t :: * -> * -> *) (f :: * -> *) a b c d.
(Bifoldable t, Applicative f) =>
t a b -> (a -> f c) -> (b -> f d) -> f ()
bifor_ t a b
t a -> f c
f b -> f d
g = forall (t :: * -> * -> *) (f :: * -> *) a c b d.
(Bifoldable t, Applicative f) =>
(a -> f c) -> (b -> f d) -> t a b -> f ()
bitraverse_ a -> f c
f b -> f d
g t a b
t
bimapM_ :: (Bifoldable t, Applicative f)
=> (a -> f c) -> (b -> f d) -> t a b -> f ()
bimapM_ :: forall (t :: * -> * -> *) (f :: * -> *) a c b d.
(Bifoldable t, Applicative f) =>
(a -> f c) -> (b -> f d) -> t a b -> f ()
bimapM_ = forall (t :: * -> * -> *) (f :: * -> *) a c b d.
(Bifoldable t, Applicative f) =>
(a -> f c) -> (b -> f d) -> t a b -> f ()
bitraverse_
biforM_ :: (Bifoldable t, Applicative f)
=> t a b -> (a -> f c) -> (b -> f d) -> f ()
biforM_ :: forall (t :: * -> * -> *) (f :: * -> *) a b c d.
(Bifoldable t, Applicative f) =>
t a b -> (a -> f c) -> (b -> f d) -> f ()
biforM_ = forall (t :: * -> * -> *) (f :: * -> *) a b c d.
(Bifoldable t, Applicative f) =>
t a b -> (a -> f c) -> (b -> f d) -> f ()
bifor_
bisequenceA_ :: (Bifoldable t, Applicative f) => t (f a) (f b) -> f ()
bisequenceA_ :: forall (t :: * -> * -> *) (f :: * -> *) a b.
(Bifoldable t, Applicative f) =>
t (f a) (f b) -> f ()
bisequenceA_ = forall (t :: * -> * -> *) (f :: * -> *) a b.
(Bifoldable t, Applicative f) =>
t (f a) (f b) -> f ()
bisequence_
bisequence_ :: (Bifoldable t, Applicative f) => t (f a) (f b) -> f ()
bisequence_ :: forall (t :: * -> * -> *) (f :: * -> *) a b.
(Bifoldable t, Applicative f) =>
t (f a) (f b) -> f ()
bisequence_ = forall (p :: * -> * -> *) a c b.
Bifoldable p =>
(a -> c -> c) -> (b -> c -> c) -> c -> p a b -> c
bifoldr forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
(*>) forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
(*>) (forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
biasum :: (Bifoldable t, Alternative f) => t (f a) (f a) -> f a
biasum :: forall (t :: * -> * -> *) (f :: * -> *) a.
(Bifoldable t, Alternative f) =>
t (f a) (f a) -> f a
biasum = forall (p :: * -> * -> *) a c b.
Bifoldable p =>
(a -> c -> c) -> (b -> c -> c) -> c -> p a b -> c
bifoldr forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
(<|>) forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
(<|>) forall (f :: * -> *) a. Alternative f => f a
empty
bimsum :: (Bifoldable t, Alternative f) => t (f a) (f a) -> f a
bimsum :: forall (t :: * -> * -> *) (f :: * -> *) a.
(Bifoldable t, Alternative f) =>
t (f a) (f a) -> f a
bimsum = forall (t :: * -> * -> *) (f :: * -> *) a.
(Bifoldable t, Alternative f) =>
t (f a) (f a) -> f a
biasum
biList :: Bifoldable t => t a a -> [a]
biList :: forall (t :: * -> * -> *) a. Bifoldable t => t a a -> [a]
biList = forall (p :: * -> * -> *) a c b.
Bifoldable p =>
(a -> c -> c) -> (b -> c -> c) -> c -> p a b -> c
bifoldr (:) (:) []
binull :: Bifoldable t => t a b -> Bool
binull :: forall (t :: * -> * -> *) a b. Bifoldable t => t a b -> Bool
binull = forall (p :: * -> * -> *) a c b.
Bifoldable p =>
(a -> c -> c) -> (b -> c -> c) -> c -> p a b -> c
bifoldr (\a
_ Bool
_ -> Bool
False) (\b
_ Bool
_ -> Bool
False) Bool
True
bilength :: Bifoldable t => t a b -> Int
bilength :: forall (t :: * -> * -> *) a b. Bifoldable t => t a b -> Int
bilength = forall (t :: * -> * -> *) a b c.
Bifoldable t =>
(a -> b -> a) -> (a -> c -> a) -> a -> t b c -> a
bifoldl' (\Int
c a
_ -> Int
cforall a. Num a => a -> a -> a
+Int
1) (\Int
c b
_ -> Int
cforall a. Num a => a -> a -> a
+Int
1) Int
0
bielem :: (Bifoldable t, Eq a) => a -> t a a -> Bool
bielem :: forall (t :: * -> * -> *) a.
(Bifoldable t, Eq a) =>
a -> t a a -> Bool
bielem a
x = forall (t :: * -> * -> *) a b.
Bifoldable t =>
(a -> Bool) -> (b -> Bool) -> t a b -> Bool
biany (forall a. Eq a => a -> a -> Bool
== a
x) (forall a. Eq a => a -> a -> Bool
== a
x)
biconcat :: Bifoldable t => t [a] [a] -> [a]
biconcat :: forall (t :: * -> * -> *) a. Bifoldable t => t [a] [a] -> [a]
biconcat = forall (p :: * -> * -> *) m. (Bifoldable p, Monoid m) => p m m -> m
bifold
bimaximum :: forall t a. (Bifoldable t, Ord a) => t a a -> a
bimaximum :: forall (t :: * -> * -> *) a. (Bifoldable t, Ord a) => t a a -> a
bimaximum = forall a. a -> Maybe a -> a
fromMaybe (forall a. HasCallStack => [Char] -> a
error [Char]
"bimaximum: empty structure") forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall a. Max a -> Maybe a
getMax forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap a -> Max a
mj a -> Max a
mj
where mj :: a -> Max a
mj = forall a. Maybe a -> Max a
Max forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. (forall a. a -> Maybe a
Just :: a -> Maybe a)
biminimum :: forall t a. (Bifoldable t, Ord a) => t a a -> a
biminimum :: forall (t :: * -> * -> *) a. (Bifoldable t, Ord a) => t a a -> a
biminimum = forall a. a -> Maybe a -> a
fromMaybe (forall a. HasCallStack => [Char] -> a
error [Char]
"biminimum: empty structure") forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall a. Min a -> Maybe a
getMin forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap a -> Min a
mj a -> Min a
mj
where mj :: a -> Min a
mj = forall a. Maybe a -> Min a
Min forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. (forall a. a -> Maybe a
Just :: a -> Maybe a)
bisum :: (Bifoldable t, Num a) => t a a -> a
bisum :: forall (t :: * -> * -> *) a. (Bifoldable t, Num a) => t a a -> a
bisum = forall a. Sum a -> a
getSum forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap forall a. a -> Sum a
Sum forall a. a -> Sum a
Sum
biproduct :: (Bifoldable t, Num a) => t a a -> a
biproduct :: forall (t :: * -> * -> *) a. (Bifoldable t, Num a) => t a a -> a
biproduct = forall a. Product a -> a
getProduct forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap forall a. a -> Product a
Product forall a. a -> Product a
Product
biconcatMap :: Bifoldable t => (a -> [c]) -> (b -> [c]) -> t a b -> [c]
biconcatMap :: forall (t :: * -> * -> *) a c b.
Bifoldable t =>
(a -> [c]) -> (b -> [c]) -> t a b -> [c]
biconcatMap = forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap
biand :: Bifoldable t => t Bool Bool -> Bool
biand :: forall (t :: * -> * -> *). Bifoldable t => t Bool Bool -> Bool
biand = All -> Bool
getAll forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap Bool -> All
All Bool -> All
All
bior :: Bifoldable t => t Bool Bool -> Bool
bior :: forall (t :: * -> * -> *). Bifoldable t => t Bool Bool -> Bool
bior = Any -> Bool
getAny forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap Bool -> Any
Any Bool -> Any
Any
biany :: Bifoldable t => (a -> Bool) -> (b -> Bool) -> t a b -> Bool
biany :: forall (t :: * -> * -> *) a b.
Bifoldable t =>
(a -> Bool) -> (b -> Bool) -> t a b -> Bool
biany a -> Bool
p b -> Bool
q = Any -> Bool
getAny forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap (Bool -> Any
Any forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Bool
p) (Bool -> Any
Any forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> Bool
q)
biall :: Bifoldable t => (a -> Bool) -> (b -> Bool) -> t a b -> Bool
biall :: forall (t :: * -> * -> *) a b.
Bifoldable t =>
(a -> Bool) -> (b -> Bool) -> t a b -> Bool
biall a -> Bool
p b -> Bool
q = All -> Bool
getAll forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap (Bool -> All
All forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Bool
p) (Bool -> All
All forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> Bool
q)
bimaximumBy :: Bifoldable t => (a -> a -> Ordering) -> t a a -> a
bimaximumBy :: forall (t :: * -> * -> *) a.
Bifoldable t =>
(a -> a -> Ordering) -> t a a -> a
bimaximumBy a -> a -> Ordering
cmp = forall (t :: * -> * -> *) a.
Bifoldable t =>
(a -> a -> a) -> t a a -> a
bifoldr1 a -> a -> a
max'
where max' :: a -> a -> a
max' a
x a
y = case a -> a -> Ordering
cmp a
x a
y of
Ordering
GT -> a
x
Ordering
_ -> a
y
biminimumBy :: Bifoldable t => (a -> a -> Ordering) -> t a a -> a
biminimumBy :: forall (t :: * -> * -> *) a.
Bifoldable t =>
(a -> a -> Ordering) -> t a a -> a
biminimumBy a -> a -> Ordering
cmp = forall (t :: * -> * -> *) a.
Bifoldable t =>
(a -> a -> a) -> t a a -> a
bifoldr1 a -> a -> a
min'
where min' :: a -> a -> a
min' a
x a
y = case a -> a -> Ordering
cmp a
x a
y of
Ordering
GT -> a
y
Ordering
_ -> a
x
binotElem :: (Bifoldable t, Eq a) => a -> t a a-> Bool
binotElem :: forall (t :: * -> * -> *) a.
(Bifoldable t, Eq a) =>
a -> t a a -> Bool
binotElem a
x = Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> * -> *) a.
(Bifoldable t, Eq a) =>
a -> t a a -> Bool
bielem a
x
bifind :: Bifoldable t => (a -> Bool) -> t a a -> Maybe a
bifind :: forall (t :: * -> * -> *) a.
Bifoldable t =>
(a -> Bool) -> t a a -> Maybe a
bifind a -> Bool
p = forall a. First a -> Maybe a
getFirst forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap a -> First a
finder a -> First a
finder
where finder :: a -> First a
finder a
x = forall a. Maybe a -> First a
First (if a -> Bool
p a
x then forall a. a -> Maybe a
Just a
x else forall a. Maybe a
Nothing)