module Optics.Fold
(
Fold
, foldVL
, foldOf
, foldMapOf
, foldrOf
, foldlOf'
, toListOf
, sequenceOf_
, traverseOf_
, forOf_
, folded
, folding
, foldring
, unfolded
, has
, hasn't
, headOf
, lastOf
, andOf
, orOf
, allOf
, anyOf
, noneOf
, productOf
, sumOf
, asumOf
, msumOf
, elemOf
, notElemOf
, lengthOf
, maximumOf
, minimumOf
, maximumByOf
, minimumByOf
, findOf
, findMOf
, lookupOf
, universeOf
, cosmosOf
, paraOf
, pre
, backwards_
, summing
, failing
, A_Fold
)
where
import Control.Applicative
import Control.Applicative.Backwards
import Control.Monad
import Data.Foldable
import Data.Function
import Data.Monoid
import Data.Profunctor.Indexed
import Optics.AffineFold
import Optics.Internal.Bi
import Optics.Internal.Fold
import Optics.Internal.Optic
import Optics.Internal.Utils
type Fold s a = Optic' A_Fold NoIx s a
foldVL
:: (forall f. Applicative f => (a -> f u) -> s -> f v)
-> Fold s a
foldVL :: forall a u s v.
(forall (f :: * -> *). Applicative f => (a -> f u) -> s -> f v)
-> Fold s a
foldVL forall (f :: * -> *). Applicative f => (a -> f u) -> s -> f v
f = forall k (is :: IxList) s t a b.
(forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ k p i (Curry is i) s t a b)
-> Optic k is s t a b
Optic (forall (p :: * -> * -> * -> *) a u s v i t b.
(Bicontravariant p, Traversing p) =>
(forall (f :: * -> *). Applicative f => (a -> f u) -> s -> f v)
-> Optic__ p i i s t a b
foldVL__ forall (f :: * -> *). Applicative f => (a -> f u) -> s -> f v
f)
{-# INLINE foldVL #-}
foldOf :: (Is k A_Fold, Monoid a) => Optic' k is s a -> s -> a
foldOf :: forall k a (is :: IxList) s.
(Is k A_Fold, Monoid a) =>
Optic' k is s a -> s -> a
foldOf Optic' k is s a
o = forall k m (is :: IxList) s a.
(Is k A_Fold, Monoid m) =>
Optic' k is s a -> (a -> m) -> s -> m
foldMapOf Optic' k is s a
o forall a. a -> a
id
{-# INLINE foldOf #-}
foldMapOf :: (Is k A_Fold, Monoid m) => Optic' k is s a -> (a -> m) -> s -> m
foldMapOf :: forall k m (is :: IxList) s a.
(Is k A_Fold, Monoid m) =>
Optic' k is s a -> (a -> m) -> s -> m
foldMapOf Optic' k is s a
o = forall r i a b. Forget r i a b -> a -> r
runForget forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. forall (p :: * -> * -> * -> *) k (is :: IxList) s t a b i.
Profunctor p =>
Optic k is s t a b -> Optic_ k p i (Curry is i) s t a b
getOptic (forall destKind srcKind (is :: IxList) s t a b.
Is srcKind destKind =>
Optic srcKind is s t a b -> Optic destKind is s t a b
castOptic @A_Fold Optic' k is s a
o) forall a b c. Coercible a b => (b -> c) -> (a -> b) -> a -> c
.# forall r i a b. (a -> r) -> Forget r i a b
Forget
{-# INLINE foldMapOf #-}
foldrOf :: Is k A_Fold => Optic' k is s a -> (a -> r -> r) -> r -> s -> r
foldrOf :: forall k (is :: IxList) s a r.
Is k A_Fold =>
Optic' k is s a -> (a -> r -> r) -> r -> s -> r
foldrOf Optic' k is s a
o = \a -> r -> r
arr r
r s
s -> (\Endo r
e -> forall a. Endo a -> a -> a
appEndo Endo r
e r
r) forall a b. (a -> b) -> a -> b
$ forall k m (is :: IxList) s a.
(Is k A_Fold, Monoid m) =>
Optic' k is s a -> (a -> m) -> s -> m
foldMapOf Optic' k is s a
o (forall a. (a -> a) -> Endo a
Endo forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. a -> r -> r
arr) s
s
{-# INLINE foldrOf #-}
foldlOf' :: Is k A_Fold => Optic' k is s a -> (r -> a -> r) -> r -> s -> r
foldlOf' :: forall k (is :: IxList) s a r.
Is k A_Fold =>
Optic' k is s a -> (r -> a -> r) -> r -> s -> r
foldlOf' Optic' k is s a
o = \r -> a -> r
rar r
r0 s
s -> forall k (is :: IxList) s a r.
Is k A_Fold =>
Optic' k is s a -> (a -> r -> r) -> r -> s -> r
foldrOf Optic' k is s a
o (\a
a r -> r
rr r
r -> r -> r
rr forall a b. (a -> b) -> a -> b
$! r -> a -> r
rar r
r a
a) forall a. a -> a
id s
s r
r0
{-# INLINE foldlOf' #-}
toListOf :: Is k A_Fold => Optic' k is s a -> s -> [a]
toListOf :: forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> s -> [a]
toListOf Optic' k is s a
o = forall k (is :: IxList) s a r.
Is k A_Fold =>
Optic' k is s a -> (a -> r -> r) -> r -> s -> r
foldrOf Optic' k is s a
o (:) []
{-# INLINE toListOf #-}
traverseOf_
:: (Is k A_Fold, Applicative f)
=> Optic' k is s a
-> (a -> f r) -> s -> f ()
traverseOf_ :: forall k (f :: * -> *) (is :: IxList) s a r.
(Is k A_Fold, Applicative f) =>
Optic' k is s a -> (a -> f r) -> s -> f ()
traverseOf_ Optic' k is s a
o = \a -> f r
f -> forall (f :: * -> *) a. Functor f => Traversed f a -> f ()
runTraversed forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k m (is :: IxList) s a.
(Is k A_Fold, Monoid m) =>
Optic' k is s a -> (a -> m) -> s -> m
foldMapOf Optic' k is s a
o (forall (f :: * -> *) a. f a -> Traversed f a
Traversed forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. a -> f r
f)
{-# INLINE traverseOf_ #-}
forOf_
:: (Is k A_Fold, Applicative f)
=> Optic' k is s a
-> s -> (a -> f r) -> f ()
forOf_ :: forall k (f :: * -> *) (is :: IxList) s a r.
(Is k A_Fold, Applicative f) =>
Optic' k is s a -> s -> (a -> f r) -> f ()
forOf_ = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (f :: * -> *) (is :: IxList) s a r.
(Is k A_Fold, Applicative f) =>
Optic' k is s a -> (a -> f r) -> s -> f ()
traverseOf_
{-# INLINE forOf_ #-}
sequenceOf_
:: (Is k A_Fold, Applicative f)
=> Optic' k is s (f a)
-> s -> f ()
sequenceOf_ :: forall k (f :: * -> *) (is :: IxList) s a.
(Is k A_Fold, Applicative f) =>
Optic' k is s (f a) -> s -> f ()
sequenceOf_ Optic' k is s (f a)
o = forall (f :: * -> *) a. Functor f => Traversed f a -> f ()
runTraversed forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k m (is :: IxList) s a.
(Is k A_Fold, Monoid m) =>
Optic' k is s a -> (a -> m) -> s -> m
foldMapOf Optic' k is s (f a)
o forall (f :: * -> *) a. f a -> Traversed f a
Traversed
{-# INLINE sequenceOf_ #-}
folded :: Foldable f => Fold (f a) a
folded :: forall (f :: * -> *) a. Foldable f => Fold (f a) a
folded = forall k (is :: IxList) s t a b.
(forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ k p i (Curry is i) s t a b)
-> Optic k is s t a b
Optic forall (p :: * -> * -> * -> *) (f :: * -> *) i a b.
(Bicontravariant p, Traversing p, Foldable f) =>
Optic__ p i i (f a) (f b) a b
folded__
{-# INLINE folded #-}
folding :: Foldable f => (s -> f a) -> Fold s a
folding :: forall (f :: * -> *) s a. Foldable f => (s -> f a) -> Fold s a
folding s -> f a
f = forall k (is :: IxList) s t a b.
(forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ k p i (Curry is i) s t a b)
-> Optic k is s t a b
Optic (forall (p :: * -> * -> * -> *) b a i c.
Bicontravariant p =>
(b -> a) -> p i a c -> p i b c
contrafirst s -> f a
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> * -> *) a u s v i t b.
(Bicontravariant p, Traversing p) =>
(forall (f :: * -> *). Applicative f => (a -> f u) -> s -> f v)
-> Optic__ p i i s t a b
foldVL__ forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_)
{-# INLINE folding #-}
foldring
:: (forall f. Applicative f => (a -> f u -> f u) -> f v -> s -> f w)
-> Fold s a
foldring :: forall a u v s w.
(forall (f :: * -> *).
Applicative f =>
(a -> f u -> f u) -> f v -> s -> f w)
-> Fold s a
foldring forall (f :: * -> *).
Applicative f =>
(a -> f u -> f u) -> f v -> s -> f w
fr = forall k (is :: IxList) s t a b.
(forall (p :: * -> * -> * -> *) i.
Profunctor p =>
Optic_ k p i (Curry is i) s t a b)
-> Optic k is s t a b
Optic (forall (p :: * -> * -> * -> *) a u v s w i t b.
(Bicontravariant p, Traversing p) =>
(forall (f :: * -> *).
Applicative f =>
(a -> f u -> f u) -> f v -> s -> f w)
-> Optic__ p i i s t a b
foldring__ forall (f :: * -> *).
Applicative f =>
(a -> f u -> f u) -> f v -> s -> f w
fr)
{-# INLINE foldring #-}
unfolded :: (s -> Maybe (a, s)) -> Fold s a
unfolded :: forall s a. (s -> Maybe (a, s)) -> Fold s a
unfolded s -> Maybe (a, s)
step = forall a u s v.
(forall (f :: * -> *). Applicative f => (a -> f u) -> s -> f v)
-> Fold s a
foldVL forall a b. (a -> b) -> a -> b
$ \a -> f Any
f -> forall a. (a -> a) -> a
fix forall a b. (a -> b) -> a -> b
$ \s -> f ()
loop s
b ->
case s -> Maybe (a, s)
step s
b of
Just (a
a, s
b') -> a -> f Any
f a
a forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> s -> f ()
loop s
b'
Maybe (a, s)
Nothing -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
{-# INLINE unfolded #-}
pre :: Is k A_Fold => Optic' k is s a -> AffineFold s a
pre :: forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> AffineFold s a
pre = forall s a. (s -> Maybe a) -> AffineFold s a
afolding forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> s -> Maybe a
headOf
{-# INLINE pre #-}
backwards_
:: Is k A_Fold
=> Optic' k is s a
-> Fold s a
backwards_ :: forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> Fold s a
backwards_ Optic' k is s a
o = forall a u s v.
(forall (f :: * -> *). Applicative f => (a -> f u) -> s -> f v)
-> Fold s a
foldVL forall a b. (a -> b) -> a -> b
$ \a -> f Any
f -> forall {k} (f :: k -> *) (a :: k). Backwards f a -> f a
forwards forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. forall k (f :: * -> *) (is :: IxList) s a r.
(Is k A_Fold, Applicative f) =>
Optic' k is s a -> (a -> f r) -> s -> f ()
traverseOf_ Optic' k is s a
o (forall {k} (f :: k -> *) (a :: k). f a -> Backwards f a
Backwards forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. a -> f Any
f)
{-# INLINE backwards_ #-}
summing
:: (Is k A_Fold, Is l A_Fold)
=> Optic' k is s a
-> Optic' l js s a
-> Fold s a
summing :: forall k l (is :: IxList) s a (js :: IxList).
(Is k A_Fold, Is l A_Fold) =>
Optic' k is s a -> Optic' l js s a -> Fold s a
summing Optic' k is s a
a Optic' l js s a
b = forall a u s v.
(forall (f :: * -> *). Applicative f => (a -> f u) -> s -> f v)
-> Fold s a
foldVL forall a b. (a -> b) -> a -> b
$ \a -> f Any
f s
s -> forall k (f :: * -> *) (is :: IxList) s a r.
(Is k A_Fold, Applicative f) =>
Optic' k is s a -> (a -> f r) -> s -> f ()
traverseOf_ Optic' k is s a
a a -> f Any
f s
s forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall k (f :: * -> *) (is :: IxList) s a r.
(Is k A_Fold, Applicative f) =>
Optic' k is s a -> (a -> f r) -> s -> f ()
traverseOf_ Optic' l js s a
b a -> f Any
f s
s
infixr 6 `summing`
{-# INLINE summing #-}
failing
:: (Is k A_Fold, Is l A_Fold)
=> Optic' k is s a
-> Optic' l js s a
-> Fold s a
failing :: forall k l (is :: IxList) s a (js :: IxList).
(Is k A_Fold, Is l A_Fold) =>
Optic' k is s a -> Optic' l js s a -> Fold s a
failing Optic' k is s a
a Optic' l js s a
b = forall a u s v.
(forall (f :: * -> *). Applicative f => (a -> f u) -> s -> f v)
-> Fold s a
foldVL forall a b. (a -> b) -> a -> b
$ \a -> f Any
f s
s ->
let OrT Bool
visited f ()
fu = forall k (f :: * -> *) (is :: IxList) s a r.
(Is k A_Fold, Applicative f) =>
Optic' k is s a -> (a -> f r) -> s -> f ()
traverseOf_ Optic' k is s a
a (forall (f :: * -> *) a. f a -> OrT f a
wrapOrT forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> f Any
f) s
s
in if Bool
visited
then f ()
fu
else forall k (f :: * -> *) (is :: IxList) s a r.
(Is k A_Fold, Applicative f) =>
Optic' k is s a -> (a -> f r) -> s -> f ()
traverseOf_ Optic' l js s a
b a -> f Any
f s
s
infixl 3 `failing`
{-# INLINE failing #-}
has :: Is k A_Fold => Optic' k is s a -> s -> Bool
has :: forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> s -> Bool
has Optic' k is s a
o = Any -> Bool
getAny forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. forall k m (is :: IxList) s a.
(Is k A_Fold, Monoid m) =>
Optic' k is s a -> (a -> m) -> s -> m
foldMapOf Optic' k is s a
o (\a
_ -> Bool -> Any
Any Bool
True)
{-# INLINE has #-}
hasn't :: Is k A_Fold => Optic' k is s a -> s -> Bool
hasn't :: forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> s -> Bool
hasn't Optic' k is s a
o = All -> Bool
getAll forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. forall k m (is :: IxList) s a.
(Is k A_Fold, Monoid m) =>
Optic' k is s a -> (a -> m) -> s -> m
foldMapOf Optic' k is s a
o (\a
_ -> Bool -> All
All Bool
False)
{-# INLINE hasn't #-}
headOf :: Is k A_Fold => Optic' k is s a -> s -> Maybe a
headOf :: forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> s -> Maybe a
headOf Optic' k is s a
o = forall a. Leftmost a -> Maybe a
getLeftmost forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k m (is :: IxList) s a.
(Is k A_Fold, Monoid m) =>
Optic' k is s a -> (a -> m) -> s -> m
foldMapOf Optic' k is s a
o forall a. a -> Leftmost a
LLeaf
{-# INLINE headOf #-}
lastOf :: Is k A_Fold => Optic' k is s a -> s -> Maybe a
lastOf :: forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> s -> Maybe a
lastOf Optic' k is s a
o = forall a. Rightmost a -> Maybe a
getRightmost forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k m (is :: IxList) s a.
(Is k A_Fold, Monoid m) =>
Optic' k is s a -> (a -> m) -> s -> m
foldMapOf Optic' k is s a
o forall a. a -> Rightmost a
RLeaf
{-# INLINE lastOf #-}
andOf :: Is k A_Fold => Optic' k is s Bool -> s -> Bool
andOf :: forall k (is :: IxList) s.
Is k A_Fold =>
Optic' k is s Bool -> s -> Bool
andOf Optic' k is s Bool
o = All -> Bool
getAll forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. forall k m (is :: IxList) s a.
(Is k A_Fold, Monoid m) =>
Optic' k is s a -> (a -> m) -> s -> m
foldMapOf Optic' k is s Bool
o Bool -> All
All
{-# INLINE andOf #-}
orOf :: Is k A_Fold => Optic' k is s Bool -> s -> Bool
orOf :: forall k (is :: IxList) s.
Is k A_Fold =>
Optic' k is s Bool -> s -> Bool
orOf Optic' k is s Bool
o = Any -> Bool
getAny forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. forall k m (is :: IxList) s a.
(Is k A_Fold, Monoid m) =>
Optic' k is s a -> (a -> m) -> s -> m
foldMapOf Optic' k is s Bool
o Bool -> Any
Any
{-# INLINE orOf #-}
anyOf :: Is k A_Fold => Optic' k is s a -> (a -> Bool) -> s -> Bool
anyOf :: forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> (a -> Bool) -> s -> Bool
anyOf Optic' k is s a
o = \a -> Bool
f -> Any -> Bool
getAny forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. forall k m (is :: IxList) s a.
(Is k A_Fold, Monoid m) =>
Optic' k is s a -> (a -> m) -> s -> m
foldMapOf Optic' k is s a
o (Bool -> Any
Any forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. a -> Bool
f)
{-# INLINE anyOf #-}
allOf :: Is k A_Fold => Optic' k is s a -> (a -> Bool) -> s -> Bool
allOf :: forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> (a -> Bool) -> s -> Bool
allOf Optic' k is s a
o = \a -> Bool
f -> All -> Bool
getAll forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. forall k m (is :: IxList) s a.
(Is k A_Fold, Monoid m) =>
Optic' k is s a -> (a -> m) -> s -> m
foldMapOf Optic' k is s a
o (Bool -> All
All forall b c a. Coercible b c => (b -> c) -> (a -> b) -> a -> c
#. a -> Bool
f)
{-# INLINE allOf #-}
noneOf :: Is k A_Fold => Optic' k is s a -> (a -> Bool) -> s -> Bool
noneOf :: forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> (a -> Bool) -> s -> Bool
noneOf Optic' k is s a
o = \a -> Bool
f -> Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> (a -> Bool) -> s -> Bool
anyOf Optic' k is s a
o a -> Bool
f
{-# INLINE noneOf #-}
productOf :: (Is k A_Fold, Num a) => Optic' k is s a -> s -> a
productOf :: forall k a (is :: IxList) s.
(Is k A_Fold, Num a) =>
Optic' k is s a -> s -> a
productOf Optic' k is s a
o = forall k (is :: IxList) s a r.
Is k A_Fold =>
Optic' k is s a -> (r -> a -> r) -> r -> s -> r
foldlOf' Optic' k is s a
o forall a. Num a => a -> a -> a
(*) a
1
{-# INLINE productOf #-}
sumOf :: (Is k A_Fold, Num a) => Optic' k is s a -> s -> a
sumOf :: forall k a (is :: IxList) s.
(Is k A_Fold, Num a) =>
Optic' k is s a -> s -> a
sumOf Optic' k is s a
o = forall k (is :: IxList) s a r.
Is k A_Fold =>
Optic' k is s a -> (r -> a -> r) -> r -> s -> r
foldlOf' Optic' k is s a
o forall a. Num a => a -> a -> a
(+) a
0
{-# INLINE sumOf #-}
asumOf :: (Is k A_Fold, Alternative f) => Optic' k is s (f a) -> s -> f a
asumOf :: forall k (f :: * -> *) (is :: IxList) s a.
(Is k A_Fold, Alternative f) =>
Optic' k is s (f a) -> s -> f a
asumOf Optic' k is s (f a)
o = forall k (is :: IxList) s a r.
Is k A_Fold =>
Optic' k is s a -> (a -> r -> r) -> r -> s -> r
foldrOf Optic' k is s (f a)
o forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
(<|>) forall (f :: * -> *) a. Alternative f => f a
empty
{-# INLINE asumOf #-}
msumOf :: (Is k A_Fold, MonadPlus m) => Optic' k is s (m a) -> s -> m a
msumOf :: forall k (m :: * -> *) (is :: IxList) s a.
(Is k A_Fold, MonadPlus m) =>
Optic' k is s (m a) -> s -> m a
msumOf Optic' k is s (m a)
o = forall k (is :: IxList) s a r.
Is k A_Fold =>
Optic' k is s a -> (a -> r -> r) -> r -> s -> r
foldrOf Optic' k is s (m a)
o forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
mplus forall (m :: * -> *) a. MonadPlus m => m a
mzero
{-# INLINE msumOf #-}
elemOf :: (Is k A_Fold, Eq a) => Optic' k is s a -> a -> s -> Bool
elemOf :: forall k a (is :: IxList) s.
(Is k A_Fold, Eq a) =>
Optic' k is s a -> a -> s -> Bool
elemOf Optic' k is s a
o = forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> (a -> Bool) -> s -> Bool
anyOf Optic' k is s a
o forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Eq a => a -> a -> Bool
(==)
{-# INLINE elemOf #-}
notElemOf :: (Is k A_Fold, Eq a) => Optic' k is s a -> a -> s -> Bool
notElemOf :: forall k a (is :: IxList) s.
(Is k A_Fold, Eq a) =>
Optic' k is s a -> a -> s -> Bool
notElemOf Optic' k is s a
o = forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> (a -> Bool) -> s -> Bool
allOf Optic' k is s a
o forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Eq a => a -> a -> Bool
(/=)
{-# INLINE notElemOf #-}
lengthOf :: Is k A_Fold => Optic' k is s a -> s -> Int
lengthOf :: forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> s -> Int
lengthOf Optic' k is s a
o = forall k (is :: IxList) s a r.
Is k A_Fold =>
Optic' k is s a -> (r -> a -> r) -> r -> s -> r
foldlOf' Optic' k is s a
o (\ Int
n a
_ -> Int
1 forall a. Num a => a -> a -> a
+ Int
n) Int
0
{-# INLINE lengthOf #-}
maximumOf :: (Is k A_Fold, Ord a) => Optic' k is s a -> s -> Maybe a
maximumOf :: forall k a (is :: IxList) s.
(Is k A_Fold, Ord a) =>
Optic' k is s a -> s -> Maybe a
maximumOf Optic' k is s a
o = forall k (is :: IxList) s a r.
Is k A_Fold =>
Optic' k is s a -> (r -> a -> r) -> r -> s -> r
foldlOf' Optic' k is s a
o forall {a}. Ord a => Maybe a -> a -> Maybe a
mf forall a. Maybe a
Nothing where
mf :: Maybe a -> a -> Maybe a
mf Maybe a
Nothing a
y = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! a
y
mf (Just a
x) a
y = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! forall a. Ord a => a -> a -> a
max a
x a
y
{-# INLINE maximumOf #-}
minimumOf :: (Is k A_Fold, Ord a) => Optic' k is s a -> s -> Maybe a
minimumOf :: forall k a (is :: IxList) s.
(Is k A_Fold, Ord a) =>
Optic' k is s a -> s -> Maybe a
minimumOf Optic' k is s a
o = forall k (is :: IxList) s a r.
Is k A_Fold =>
Optic' k is s a -> (r -> a -> r) -> r -> s -> r
foldlOf' Optic' k is s a
o forall {a}. Ord a => Maybe a -> a -> Maybe a
mf forall a. Maybe a
Nothing where
mf :: Maybe a -> a -> Maybe a
mf Maybe a
Nothing a
y = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! a
y
mf (Just a
x) a
y = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! forall a. Ord a => a -> a -> a
min a
x a
y
{-# INLINE minimumOf #-}
maximumByOf :: Is k A_Fold => Optic' k is s a -> (a -> a -> Ordering) -> s -> Maybe a
maximumByOf :: forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> (a -> a -> Ordering) -> s -> Maybe a
maximumByOf Optic' k is s a
o = \a -> a -> Ordering
cmp ->
let mf :: Maybe a -> a -> Maybe a
mf Maybe a
Nothing a
y = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! a
y
mf (Just a
x) a
y = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! if a -> a -> Ordering
cmp a
x a
y forall a. Eq a => a -> a -> Bool
== Ordering
GT then a
x else a
y
in forall k (is :: IxList) s a r.
Is k A_Fold =>
Optic' k is s a -> (r -> a -> r) -> r -> s -> r
foldlOf' Optic' k is s a
o Maybe a -> a -> Maybe a
mf forall a. Maybe a
Nothing
{-# INLINE maximumByOf #-}
minimumByOf :: Is k A_Fold => Optic' k is s a -> (a -> a -> Ordering) -> s -> Maybe a
minimumByOf :: forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> (a -> a -> Ordering) -> s -> Maybe a
minimumByOf Optic' k is s a
o = \a -> a -> Ordering
cmp ->
let mf :: Maybe a -> a -> Maybe a
mf Maybe a
Nothing a
y = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! a
y
mf (Just a
x) a
y = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! if a -> a -> Ordering
cmp a
x a
y forall a. Eq a => a -> a -> Bool
== Ordering
GT then a
y else a
x
in forall k (is :: IxList) s a r.
Is k A_Fold =>
Optic' k is s a -> (r -> a -> r) -> r -> s -> r
foldlOf' Optic' k is s a
o Maybe a -> a -> Maybe a
mf forall a. Maybe a
Nothing
{-# INLINE minimumByOf #-}
findOf :: Is k A_Fold => Optic' k is s a -> (a -> Bool) -> s -> Maybe a
findOf :: forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> (a -> Bool) -> s -> Maybe a
findOf Optic' k is s a
o = \a -> Bool
f -> forall k (is :: IxList) s a r.
Is k A_Fold =>
Optic' k is s a -> (a -> r -> r) -> r -> s -> r
foldrOf Optic' k is s a
o (\a
a Maybe a
y -> if a -> Bool
f a
a then forall a. a -> Maybe a
Just a
a else Maybe a
y) forall a. Maybe a
Nothing
{-# INLINE findOf #-}
findMOf :: (Is k A_Fold, Monad m) => Optic' k is s a -> (a -> m Bool) -> s -> m (Maybe a)
findMOf :: forall k (m :: * -> *) (is :: IxList) s a.
(Is k A_Fold, Monad m) =>
Optic' k is s a -> (a -> m Bool) -> s -> m (Maybe a)
findMOf Optic' k is s a
o = \a -> m Bool
f -> forall k (is :: IxList) s a r.
Is k A_Fold =>
Optic' k is s a -> (a -> r -> r) -> r -> s -> r
foldrOf Optic' k is s a
o
(\a
a m (Maybe a)
y -> a -> m Bool
f a
a forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
r -> if Bool
r then forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall a. a -> Maybe a
Just a
a) else m (Maybe a)
y)
(forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Maybe a
Nothing)
{-# INLINE findMOf #-}
lookupOf :: (Is k A_Fold, Eq a) => Optic' k is s (a, v) -> a -> s -> Maybe v
lookupOf :: forall k a (is :: IxList) s v.
(Is k A_Fold, Eq a) =>
Optic' k is s (a, v) -> a -> s -> Maybe v
lookupOf Optic' k is s (a, v)
o a
a = forall k (is :: IxList) s a r.
Is k A_Fold =>
Optic' k is s a -> (a -> r -> r) -> r -> s -> r
foldrOf Optic' k is s (a, v)
o (\(a
a', v
v) Maybe v
next -> if a
a forall a. Eq a => a -> a -> Bool
== a
a' then forall a. a -> Maybe a
Just v
v else Maybe v
next) forall a. Maybe a
Nothing
{-# INLINE lookupOf #-}
universeOf :: Is k A_Fold => Optic' k is a a -> a -> [a]
universeOf :: forall k (is :: IxList) a.
Is k A_Fold =>
Optic' k is a a -> a -> [a]
universeOf Optic' k is a a
o = (forall a. Endo a -> a -> a
`appEndo` []) forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Endo [a]
go
where
go :: a -> Endo [a]
go a
a = forall a. (a -> a) -> Endo a
Endo (a
a forall a. a -> [a] -> [a]
:) forall a. Semigroup a => a -> a -> a
<> forall k m (is :: IxList) s a.
(Is k A_Fold, Monoid m) =>
Optic' k is s a -> (a -> m) -> s -> m
foldMapOf Optic' k is a a
o a -> Endo [a]
go a
a
{-# INLINE universeOf #-}
cosmosOf :: forall k is a. Is k A_Fold => Optic' k is a a -> Fold a a
cosmosOf :: forall k (is :: IxList) a.
Is k A_Fold =>
Optic' k is a a -> Fold a a
cosmosOf Optic' k is a a
o = forall a u s v.
(forall (f :: * -> *). Applicative f => (a -> f u) -> s -> f v)
-> Fold s a
foldVL forall (f :: * -> *). Applicative f => (a -> f ()) -> a -> f ()
go
where
go :: Applicative f => (a -> f ()) -> a -> f ()
go :: forall (f :: * -> *). Applicative f => (a -> f ()) -> a -> f ()
go a -> f ()
f a
a = a -> f ()
f a
a forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall k (f :: * -> *) (is :: IxList) s a r.
(Is k A_Fold, Applicative f) =>
Optic' k is s a -> (a -> f r) -> s -> f ()
traverseOf_ Optic' k is a a
o (forall (f :: * -> *). Applicative f => (a -> f ()) -> a -> f ()
go a -> f ()
f) a
a
{-# INLINE cosmosOf #-}
paraOf :: Is k A_Fold => Optic' k is a a -> (a -> [r] -> r) -> a -> r
paraOf :: forall k (is :: IxList) a r.
Is k A_Fold =>
Optic' k is a a -> (a -> [r] -> r) -> a -> r
paraOf Optic' k is a a
o a -> [r] -> r
f = a -> r
go
where
go :: a -> r
go a
a = a -> [r] -> r
f a
a (a -> r
go forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall k (is :: IxList) s a.
Is k A_Fold =>
Optic' k is s a -> s -> [a]
toListOf Optic' k is a a
o a
a)
{-# INLINE paraOf #-}