{-# 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 = (m -> m) -> (m -> m) -> p m m -> m
forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap m -> m
forall a. a -> a
id m -> m
forall a. a -> a
id
bifoldMap :: Monoid m => (a -> m) -> (b -> m) -> p a b -> m
bifoldMap a -> m
f b -> m
g = (a -> m -> m) -> (b -> m -> m) -> m -> p a b -> m
forall (p :: * -> * -> *) a c b.
Bifoldable p =>
(a -> c -> c) -> (b -> c -> c) -> c -> p a b -> c
bifoldr (m -> m -> m
forall a. Monoid a => a -> a -> a
mappend (m -> m -> m) -> (a -> m) -> a -> m -> m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m
f) (m -> m -> m
forall a. Monoid a => a -> a -> a
mappend (m -> m -> m) -> (b -> m) -> b -> m -> m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> m
g) m
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 = Endo c -> c -> c
forall a. Endo a -> a -> a
appEndo ((a -> Endo c) -> (b -> Endo c) -> p a b -> Endo c
forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap ((c -> c) -> Endo c
forall a. (a -> a) -> Endo a
Endo ((c -> c) -> Endo c) -> (a -> c -> c) -> a -> Endo c
forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. a -> c -> c
f) ((c -> c) -> Endo c
forall a. (a -> a) -> Endo a
Endo ((c -> c) -> Endo c) -> (b -> c -> c) -> b -> Endo c
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 = Endo c -> c -> c
forall a. Endo a -> a -> a
appEndo (Dual (Endo c) -> Endo c
forall a. Dual a -> a
getDual ((a -> Dual (Endo c))
-> (b -> Dual (Endo c)) -> p a b -> Dual (Endo c)
forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap (Endo c -> Dual (Endo c)
forall a. a -> Dual a
Dual (Endo c -> Dual (Endo c)) -> (a -> Endo c) -> a -> Dual (Endo c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c -> c) -> Endo c
forall a. (a -> a) -> Endo a
Endo ((c -> c) -> Endo c) -> (a -> c -> c) -> a -> Endo c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c -> a -> c) -> a -> c -> c
forall a b c. (a -> b -> c) -> b -> a -> c
flip c -> a -> c
f)
(Endo c -> Dual (Endo c)
forall a. a -> Dual a
Dual (Endo c -> Dual (Endo c)) -> (b -> Endo c) -> b -> Dual (Endo c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c -> c) -> Endo c
forall a. (a -> a) -> Endo a
Endo ((c -> c) -> Endo c) -> (b -> c -> c) -> b -> Endo c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (c -> b -> c) -> b -> c -> 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 :: (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 Bifoldable Const where
bifoldMap :: (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 :: (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 :: (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 m -> m -> m
forall a. Monoid a => a -> a -> a
`mappend` b -> m
g b
b
instance Bifoldable ((,,,) x y) where
bifoldMap :: (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 m -> m -> m
forall a. Monoid a => a -> a -> a
`mappend` b -> m
g b
b
instance Bifoldable ((,,,,) x y z) where
bifoldMap :: (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 m -> m -> m
forall a. Monoid a => a -> a -> a
`mappend` b -> m
g b
b
instance Bifoldable ((,,,,,) x y z w) where
bifoldMap :: (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 m -> m -> m
forall a. Monoid a => a -> a -> a
`mappend` b -> m
g b
b
instance Bifoldable ((,,,,,,) x y z w v) where
bifoldMap :: (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 m -> m -> m
forall a. Monoid a => a -> a -> a
`mappend` b -> m
g b
b
instance Bifoldable Either where
bifoldMap :: (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' :: (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 = ((c -> c) -> a -> c -> c)
-> ((c -> c) -> b -> c -> c) -> (c -> c) -> t a b -> c -> c
forall (p :: * -> * -> *) c a b.
Bifoldable p =>
(c -> a -> c) -> (c -> b -> c) -> c -> p a b -> c
bifoldl (c -> c) -> a -> c -> c
forall b. (c -> b) -> a -> c -> b
f' (c -> c) -> b -> c -> c
forall b. (c -> b) -> b -> c -> b
g' c -> c
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 (c -> b) -> c -> b
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 (c -> b) -> c -> b
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 :: (a -> a -> a) -> t a a -> a
bifoldr1 a -> a -> a
f t a a
xs = a -> Maybe a -> a
forall a. a -> Maybe a -> a
fromMaybe ([Char] -> a
forall a. HasCallStack => [Char] -> a
error [Char]
"bifoldr1: empty structure")
((a -> Maybe a -> Maybe a)
-> (a -> Maybe a -> Maybe a) -> Maybe a -> t a a -> Maybe a
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 Maybe a
forall a. Maybe a
Nothing t a a
xs)
where
mbf :: a -> Maybe a -> Maybe a
mbf a
x Maybe a
m = a -> Maybe a
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 :: (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 = ((c -> m c) -> a -> c -> m c)
-> ((c -> m c) -> b -> c -> m c) -> (c -> m c) -> t a b -> c -> m c
forall (p :: * -> * -> *) c a b.
Bifoldable p =>
(c -> a -> c) -> (c -> b -> c) -> c -> p a b -> c
bifoldl (c -> m c) -> a -> c -> m c
forall b. (c -> m b) -> a -> c -> m b
f' (c -> m c) -> b -> c -> m c
forall b. (c -> m b) -> b -> c -> m b
g' c -> m c
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 m c -> (c -> m b) -> m b
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 m c -> (c -> m b) -> m b
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' :: (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 = (b -> (a -> a) -> a -> a)
-> (c -> (a -> a) -> a -> a) -> (a -> a) -> t b c -> a -> a
forall (p :: * -> * -> *) a c b.
Bifoldable p =>
(a -> c -> c) -> (b -> c -> c) -> c -> p a b -> c
bifoldr b -> (a -> a) -> a -> a
forall b. b -> (a -> b) -> a -> b
f' c -> (a -> a) -> a -> a
forall b. c -> (a -> b) -> a -> b
g' a -> a
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 (a -> b) -> a -> b
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 (a -> b) -> a -> b
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 :: (a -> a -> a) -> t a a -> a
bifoldl1 a -> a -> a
f t a a
xs = a -> Maybe a -> a
forall a. a -> Maybe a -> a
fromMaybe ([Char] -> a
forall a. HasCallStack => [Char] -> a
error [Char]
"bifoldl1: empty structure")
((Maybe a -> a -> Maybe a)
-> (Maybe a -> a -> Maybe a) -> Maybe a -> t a a -> Maybe a
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 Maybe a
forall a. Maybe a
Nothing t a a
xs)
where
mbf :: Maybe a -> a -> Maybe a
mbf Maybe a
m a
y = a -> Maybe a
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 :: (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 = (b -> (a -> m a) -> a -> m a)
-> (c -> (a -> m a) -> a -> m a) -> (a -> m a) -> t b c -> a -> m a
forall (p :: * -> * -> *) a c b.
Bifoldable p =>
(a -> c -> c) -> (b -> c -> c) -> c -> p a b -> c
bifoldr b -> (a -> m a) -> a -> m a
forall b. b -> (a -> m b) -> a -> m b
f' c -> (a -> m a) -> a -> m a
forall b. c -> (a -> m b) -> a -> m b
g' a -> m a
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 m a -> (a -> m b) -> m b
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 m a -> (a -> m b) -> m b
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_ :: (a -> f c) -> (b -> f d) -> t a b -> f ()
bitraverse_ a -> f c
f b -> f d
g = (a -> f () -> f ()) -> (b -> f () -> f ()) -> f () -> t a b -> f ()
forall (p :: * -> * -> *) a c b.
Bifoldable p =>
(a -> c -> c) -> (b -> c -> c) -> c -> p a b -> c
bifoldr (f c -> f () -> f ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
(*>) (f c -> f () -> f ()) -> (a -> f c) -> a -> f () -> f ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> f c
f) (f d -> f () -> f ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
(*>) (f d -> f () -> f ()) -> (b -> f d) -> b -> f () -> f ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> f d
g) (() -> f ()
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_ :: t a b -> (a -> f c) -> (b -> f d) -> f ()
bifor_ t a b
t a -> f c
f b -> f d
g = (a -> f c) -> (b -> f d) -> t a b -> f ()
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_ :: (a -> f c) -> (b -> f d) -> t a b -> f ()
bimapM_ = (a -> f c) -> (b -> f d) -> t a b -> f ()
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_ :: t a b -> (a -> f c) -> (b -> f d) -> f ()
biforM_ = t a b -> (a -> f c) -> (b -> f d) -> f ()
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_ :: t (f a) (f b) -> f ()
bisequenceA_ = t (f a) (f b) -> f ()
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_ :: t (f a) (f b) -> f ()
bisequence_ = (f a -> f () -> f ())
-> (f b -> f () -> f ()) -> f () -> t (f a) (f b) -> f ()
forall (p :: * -> * -> *) a c b.
Bifoldable p =>
(a -> c -> c) -> (b -> c -> c) -> c -> p a b -> c
bifoldr f a -> f () -> f ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
(*>) f b -> f () -> f ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
(*>) (() -> f ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
biasum :: (Bifoldable t, Alternative f) => t (f a) (f a) -> f a
biasum :: t (f a) (f a) -> f a
biasum = (f a -> f a -> f a)
-> (f a -> f a -> f a) -> f a -> t (f a) (f a) -> f a
forall (p :: * -> * -> *) a c b.
Bifoldable p =>
(a -> c -> c) -> (b -> c -> c) -> c -> p a b -> c
bifoldr f a -> f a -> f a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
(<|>) f a -> f a -> f a
forall (f :: * -> *) a. Alternative f => f a -> 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 :: t (f a) (f a) -> f a
bimsum = t (f a) (f a) -> f a
forall (t :: * -> * -> *) (f :: * -> *) a.
(Bifoldable t, Alternative f) =>
t (f a) (f a) -> f a
biasum
biList :: Bifoldable t => t a a -> [a]
biList :: t a a -> [a]
biList = (a -> [a] -> [a]) -> (a -> [a] -> [a]) -> [a] -> t a a -> [a]
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 :: t a b -> Bool
binull = (a -> Bool -> Bool) -> (b -> Bool -> Bool) -> Bool -> t a b -> Bool
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 :: t a b -> Int
bilength = (Int -> a -> Int) -> (Int -> b -> Int) -> Int -> t a b -> Int
forall (t :: * -> * -> *) a b c.
Bifoldable t =>
(a -> b -> a) -> (a -> c -> a) -> a -> t b c -> a
bifoldl' (\Int
c a
_ -> Int
cInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) (\Int
c b
_ -> Int
cInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) Int
0
bielem :: (Bifoldable t, Eq a) => a -> t a a -> Bool
bielem :: a -> t a a -> Bool
bielem a
x = (a -> Bool) -> (a -> Bool) -> t a a -> Bool
forall (t :: * -> * -> *) a b.
Bifoldable t =>
(a -> Bool) -> (b -> Bool) -> t a b -> Bool
biany (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
x) (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
x)
biconcat :: Bifoldable t => t [a] [a] -> [a]
biconcat :: t [a] [a] -> [a]
biconcat = t [a] [a] -> [a]
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 :: t a a -> a
bimaximum = a -> Maybe a -> a
forall a. a -> Maybe a -> a
fromMaybe ([Char] -> a
forall a. HasCallStack => [Char] -> a
error [Char]
"bimaximum: empty structure") (Maybe a -> a) -> (t a a -> Maybe a) -> t a a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Max a -> Maybe a
forall a. Max a -> Maybe a
getMax (Max a -> Maybe a) -> (t a a -> Max a) -> t a a -> Maybe a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Max a) -> (a -> Max a) -> t a a -> Max a
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 = Maybe a -> Max a
forall a. Maybe a -> Max a
Max (Maybe a -> Max a) -> (a -> Maybe a) -> a -> Max a
forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. (a -> Maybe a
forall a. a -> Maybe a
Just :: a -> Maybe a)
biminimum :: forall t a. (Bifoldable t, Ord a) => t a a -> a
biminimum :: t a a -> a
biminimum = a -> Maybe a -> a
forall a. a -> Maybe a -> a
fromMaybe ([Char] -> a
forall a. HasCallStack => [Char] -> a
error [Char]
"biminimum: empty structure") (Maybe a -> a) -> (t a a -> Maybe a) -> t a a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Min a -> Maybe a
forall a. Min a -> Maybe a
getMin (Min a -> Maybe a) -> (t a a -> Min a) -> t a a -> Maybe a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Min a) -> (a -> Min a) -> t a a -> Min a
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 = Maybe a -> Min a
forall a. Maybe a -> Min a
Min (Maybe a -> Min a) -> (a -> Maybe a) -> a -> Min a
forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. (a -> Maybe a
forall a. a -> Maybe a
Just :: a -> Maybe a)
bisum :: (Bifoldable t, Num a) => t a a -> a
bisum :: t a a -> a
bisum = Sum a -> a
forall a. Sum a -> a
getSum (Sum a -> a) -> (t a a -> Sum a) -> t a a -> a
forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. (a -> Sum a) -> (a -> Sum a) -> t a a -> Sum a
forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap a -> Sum a
forall a. a -> Sum a
Sum a -> Sum a
forall a. a -> Sum a
Sum
biproduct :: (Bifoldable t, Num a) => t a a -> a
biproduct :: t a a -> a
biproduct = Product a -> a
forall a. Product a -> a
getProduct (Product a -> a) -> (t a a -> Product a) -> t a a -> a
forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. (a -> Product a) -> (a -> Product a) -> t a a -> Product a
forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap a -> Product a
forall a. a -> Product a
Product a -> Product a
forall a. a -> Product a
Product
biconcatMap :: Bifoldable t => (a -> [c]) -> (b -> [c]) -> t a b -> [c]
biconcatMap :: (a -> [c]) -> (b -> [c]) -> t a b -> [c]
biconcatMap = (a -> [c]) -> (b -> [c]) -> t a b -> [c]
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 :: t Bool Bool -> Bool
biand = All -> Bool
getAll (All -> Bool) -> (t Bool Bool -> All) -> t Bool Bool -> Bool
forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. (Bool -> All) -> (Bool -> All) -> t Bool Bool -> All
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 :: t Bool Bool -> Bool
bior = Any -> Bool
getAny (Any -> Bool) -> (t Bool Bool -> Any) -> t Bool Bool -> Bool
forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. (Bool -> Any) -> (Bool -> Any) -> t Bool Bool -> Any
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 :: (a -> Bool) -> (b -> Bool) -> t a b -> Bool
biany a -> Bool
p b -> Bool
q = Any -> Bool
getAny (Any -> Bool) -> (t a b -> Any) -> t a b -> Bool
forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. (a -> Any) -> (b -> Any) -> t a b -> Any
forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap (Bool -> Any
Any (Bool -> Any) -> (a -> Bool) -> a -> Any
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Bool
p) (Bool -> Any
Any (Bool -> Any) -> (b -> Bool) -> b -> 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 :: (a -> Bool) -> (b -> Bool) -> t a b -> Bool
biall a -> Bool
p b -> Bool
q = All -> Bool
getAll (All -> Bool) -> (t a b -> All) -> t a b -> Bool
forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. (a -> All) -> (b -> All) -> t a b -> All
forall (p :: * -> * -> *) m a b.
(Bifoldable p, Monoid m) =>
(a -> m) -> (b -> m) -> p a b -> m
bifoldMap (Bool -> All
All (Bool -> All) -> (a -> Bool) -> a -> All
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Bool
p) (Bool -> All
All (Bool -> All) -> (b -> Bool) -> b -> 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 :: (a -> a -> Ordering) -> t a a -> a
bimaximumBy a -> a -> Ordering
cmp = (a -> a -> a) -> t a a -> a
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 :: (a -> a -> Ordering) -> t a a -> a
biminimumBy a -> a -> Ordering
cmp = (a -> a -> a) -> t a a -> a
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 :: a -> t a a -> Bool
binotElem a
x = Bool -> Bool
not (Bool -> Bool) -> (t a a -> Bool) -> t a a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> t a a -> Bool
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 :: (a -> Bool) -> t a a -> Maybe a
bifind a -> Bool
p = First a -> Maybe a
forall a. First a -> Maybe a
getFirst (First a -> Maybe a) -> (t a a -> First a) -> t a a -> Maybe a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> First a) -> (a -> First a) -> t a a -> First a
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 = Maybe a -> First a
forall a. Maybe a -> First a
First (if a -> Bool
p a
x then a -> Maybe a
forall a. a -> Maybe a
Just a
x else Maybe a
forall a. Maybe a
Nothing)