{-# LANGUAGE CPP #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE ConstraintKinds #-}
#include "lens-common.h"
module Control.Lens.Traversal
(
Traversal, Traversal'
, Traversal1, Traversal1'
, IndexedTraversal, IndexedTraversal'
, IndexedTraversal1, IndexedTraversal1'
, ATraversal, ATraversal'
, ATraversal1, ATraversal1'
, AnIndexedTraversal, AnIndexedTraversal'
, AnIndexedTraversal1, AnIndexedTraversal1'
, Traversing, Traversing'
, Traversing1, Traversing1'
, traversal
, traverseOf, forOf, sequenceAOf
, mapMOf, forMOf, sequenceOf
, transposeOf
, mapAccumLOf, mapAccumROf
, scanr1Of, scanl1Of
, failover, ifailover
, cloneTraversal
, cloneIndexPreservingTraversal
, cloneIndexedTraversal
, cloneTraversal1
, cloneIndexPreservingTraversal1
, cloneIndexedTraversal1
, partsOf, partsOf'
, unsafePartsOf, unsafePartsOf'
, holesOf, holes1Of
, singular, unsafeSingular
, Traversable(traverse)
, Traversable1(traverse1)
, both, both1
, beside
, taking
, dropping
, failing
, deepOf
, ignored
, TraverseMin(..)
, TraverseMax(..)
, traversed
, traversed1
, traversed64
, elementOf
, element
, elementsOf
, elements
, ipartsOf
, ipartsOf'
, iunsafePartsOf
, iunsafePartsOf'
, itraverseOf
, iforOf
, imapMOf
, iforMOf
, imapAccumROf
, imapAccumLOf
, traverseBy
, traverseByOf
, sequenceBy
, sequenceByOf
, Bazaar(..), Bazaar'
, Bazaar1(..), Bazaar1'
, loci
, iloci
, confusing
) where
import Prelude ()
import Control.Applicative.Backwards
import qualified Control.Category as C
import Control.Comonad
import Control.Lens.Fold
import Control.Lens.Getter (Getting, IndexedGetting, getting)
import Control.Lens.Internal.Bazaar
import Control.Lens.Internal.Context
import Control.Lens.Internal.Fold
import Control.Lens.Internal.Indexed
import Control.Lens.Internal.Prelude
import Control.Lens.Lens
import Control.Lens.Setter (ASetter, AnIndexedSetter, isets, sets)
import Control.Lens.Type
import Control.Monad.Trans.State.Lazy
import Data.Bitraversable
import Data.CallStack
import Data.Functor.Apply
import Data.Functor.Day.Curried
import Data.Functor.Yoneda
import Data.Int
import qualified Data.IntMap as IntMap
import qualified Data.Map as Map
import Data.Map (Map)
import Data.Monoid (Any (..))
import Data.Sequence (Seq, mapWithIndex)
import Data.Vector as Vector (Vector, imap)
import Data.Profunctor.Rep (Representable (..))
import Data.Reflection
import Data.Semigroup.Traversable
import Data.Semigroup.Bitraversable
import Data.Tuple (swap)
import GHC.Magic (inline)
type ATraversal s t a b = LensLike (Bazaar (->) a b) s t a b
type ATraversal' s a = ATraversal s s a a
type ATraversal1 s t a b = LensLike (Bazaar1 (->) a b) s t a b
type ATraversal1' s a = ATraversal1 s s a a
type AnIndexedTraversal i s t a b = Over (Indexed i) (Bazaar (Indexed i) a b) s t a b
type AnIndexedTraversal1 i s t a b = Over (Indexed i) (Bazaar1 (Indexed i) a b) s t a b
type AnIndexedTraversal' i s a = AnIndexedTraversal i s s a a
type AnIndexedTraversal1' i s a = AnIndexedTraversal1 i s s a a
type Traversing p f s t a b = Over p (BazaarT p f a b) s t a b
type Traversing1 p f s t a b = Over p (BazaarT1 p f a b) s t a b
type Traversing' p f s a = Traversing p f s s a a
type Traversing1' p f s a = Traversing1 p f s s a a
traversal :: ((a -> f b) -> s -> f t) -> LensLike f s t a b
traversal :: forall a (f :: * -> *) b s t.
((a -> f b) -> s -> f t) -> (a -> f b) -> s -> f t
traversal = forall a. a -> a
id
{-# INLINE traversal #-}
traverseOf :: LensLike f s t a b -> (a -> f b) -> s -> f t
traverseOf :: forall (f :: * -> *) s t a b.
LensLike f s t a b -> LensLike f s t a b
traverseOf = forall a. a -> a
id
{-# INLINE traverseOf #-}
forOf :: LensLike f s t a b -> s -> (a -> f b) -> f t
forOf :: forall (f :: * -> *) s t a b.
LensLike f s t a b -> s -> (a -> f b) -> f t
forOf = forall a b c. (a -> b -> c) -> b -> a -> c
flip
{-# INLINE forOf #-}
sequenceAOf :: LensLike f s t (f b) b -> s -> f t
sequenceAOf :: forall (f :: * -> *) s t b. LensLike f s t (f b) b -> s -> f t
sequenceAOf LensLike f s t (f b) b
l = LensLike f s t (f b) b
l forall a. a -> a
id
{-# INLINE sequenceAOf #-}
mapMOf :: LensLike (WrappedMonad m) s t a b -> (a -> m b) -> s -> m t
mapMOf :: forall (m :: * -> *) s t a b.
LensLike (WrappedMonad m) s t a b -> (a -> m b) -> s -> m t
mapMOf = coerce :: forall a b. Coercible a b => a -> b
coerce
{-# INLINE mapMOf #-}
forMOf :: LensLike (WrappedMonad m) s t a b -> s -> (a -> m b) -> m t
forMOf :: forall (m :: * -> *) s t a b.
LensLike (WrappedMonad m) s t a b -> s -> (a -> m b) -> m t
forMOf LensLike (WrappedMonad m) s t a b
l s
a a -> m b
cmd = forall (m :: * -> *) a. WrappedMonad m a -> m a
unwrapMonad (LensLike (WrappedMonad m) s t a b
l (forall (m :: * -> *) a. m a -> WrappedMonad m a
WrapMonad forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. a -> m b
cmd) s
a)
{-# INLINE forMOf #-}
sequenceOf :: LensLike (WrappedMonad m) s t (m b) b -> s -> m t
sequenceOf :: forall (m :: * -> *) s t b.
LensLike (WrappedMonad m) s t (m b) b -> s -> m t
sequenceOf LensLike (WrappedMonad m) s t (m b) b
l = forall (m :: * -> *) a. WrappedMonad m a -> m a
unwrapMonad forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. LensLike (WrappedMonad m) s t (m b) b
l forall (m :: * -> *) a. m a -> WrappedMonad m a
WrapMonad
{-# INLINE sequenceOf #-}
transposeOf :: LensLike ZipList s t [a] a -> s -> [t]
transposeOf :: forall s t a. LensLike ZipList s t [a] a -> s -> [t]
transposeOf LensLike ZipList s t [a] a
l = forall a. ZipList a -> [a]
getZipList forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. LensLike ZipList s t [a] a
l forall a. [a] -> ZipList a
ZipList
{-# INLINE transposeOf #-}
mapAccumROf :: LensLike (Backwards (State acc)) s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
mapAccumROf :: forall acc s t a b.
LensLike (Backwards (State acc)) s t a b
-> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
mapAccumROf = forall acc s t a b.
LensLike (State acc) s t a b
-> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
mapAccumLOf forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) (q :: * -> * -> *) (f :: * -> *) s t a b.
(Profunctor p, Profunctor q) =>
Optical p q (Backwards f) s t a b -> Optical p q f s t a b
backwards
{-# INLINE mapAccumROf #-}
mapAccumLOf :: LensLike (State acc) s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
mapAccumLOf :: forall acc s t a b.
LensLike (State acc) s t a b
-> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
mapAccumLOf LensLike (State acc) s t a b
l acc -> a -> (acc, b)
f acc
acc0 s
s = forall a b. (a, b) -> (b, a)
swap (forall s a. State s a -> s -> (a, s)
runState (LensLike (State acc) s t a b
l a -> StateT acc Identity b
g s
s) acc
acc0) where
g :: a -> StateT acc Identity b
g a
a = forall (m :: * -> *) s a. Monad m => (s -> (a, s)) -> StateT s m a
state forall a b. (a -> b) -> a -> b
$ \acc
acc -> forall a b. (a, b) -> (b, a)
swap (acc -> a -> (acc, b)
f acc
acc a
a)
{-# INLINE mapAccumLOf #-}
scanr1Of :: LensLike (Backwards (State (Maybe a))) s t a a -> (a -> a -> a) -> s -> t
scanr1Of :: forall a s t.
LensLike (Backwards (State (Maybe a))) s t a a
-> (a -> a -> a) -> s -> t
scanr1Of LensLike (Backwards (State (Maybe a))) s t a a
l a -> a -> a
f = forall a b. (a, b) -> b
snd forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall acc s t a b.
LensLike (Backwards (State acc)) s t a b
-> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
mapAccumROf LensLike (Backwards (State (Maybe a))) s t a a
l Maybe a -> a -> (Maybe a, a)
step forall a. Maybe a
Nothing where
step :: Maybe a -> a -> (Maybe a, a)
step Maybe a
Nothing a
a = (forall a. a -> Maybe a
Just a
a, a
a)
step (Just a
s) a
a = (forall a. a -> Maybe a
Just a
r, a
r) where r :: a
r = a -> a -> a
f a
a a
s
{-# INLINE scanr1Of #-}
scanl1Of :: LensLike (State (Maybe a)) s t a a -> (a -> a -> a) -> s -> t
scanl1Of :: forall a s t.
LensLike (State (Maybe a)) s t a a -> (a -> a -> a) -> s -> t
scanl1Of LensLike (State (Maybe a)) s t a a
l a -> a -> a
f = forall a b. (a, b) -> b
snd forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall acc s t a b.
LensLike (State acc) s t a b
-> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
mapAccumLOf LensLike (State (Maybe a)) s t a a
l Maybe a -> a -> (Maybe a, a)
step forall a. Maybe a
Nothing where
step :: Maybe a -> a -> (Maybe a, a)
step Maybe a
Nothing a
a = (forall a. a -> Maybe a
Just a
a, a
a)
step (Just a
s) a
a = (forall a. a -> Maybe a
Just a
r, a
r) where r :: a
r = a -> a -> a
f a
s a
a
{-# INLINE scanl1Of #-}
loci :: Traversal (Bazaar (->) a c s) (Bazaar (->) b c s) a b
loci :: forall a c s b.
Traversal (Bazaar (->) a c s) (Bazaar (->) b c s) a b
loci a -> f b
f Bazaar (->) a c s
w = forall {k1} {k2} (f :: k1 -> *) (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose (forall (p :: * -> * -> *) a b t.
Bazaar p a b t
-> forall (f :: * -> *). Applicative f => p a (f b) -> f t
runBazaar Bazaar (->) a c s
w (forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> f b
f))
{-# INLINE loci #-}
iloci :: IndexedTraversal i (Bazaar (Indexed i) a c s) (Bazaar (Indexed i) b c s) a b
iloci :: forall i a c s b.
IndexedTraversal
i (Bazaar (Indexed i) a c s) (Bazaar (Indexed i) b c s) a b
iloci p a (f b)
f Bazaar (Indexed i) a c s
w = forall {k1} {k2} (f :: k1 -> *) (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose (forall (p :: * -> * -> *) a b t.
Bazaar p a b t
-> forall (f :: * -> *). Applicative f => p a (f b) -> f t
runBazaar Bazaar (Indexed i) a c s
w (forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. forall i a b. (i -> a -> b) -> Indexed i a b
Indexed (\i
i -> forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall i (p :: * -> * -> *) a b.
Indexable i p =>
p a b -> i -> a -> b
indexed forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell i
i) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall i (p :: * -> * -> *) a b.
Indexable i p =>
p a b -> i -> a -> b
indexed p a (f b)
f i
i)))
{-# INLINE iloci #-}
partsOf :: Functor f => Traversing (->) f s t a a -> LensLike f s t [a] [a]
partsOf :: forall (f :: * -> *) s t a.
Functor f =>
Traversing (->) f s t a a -> LensLike f s t [a] [a]
partsOf Traversing (->) f s t a a
l [a] -> f [a]
f s
s = forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a t.
(Bizarre p w, Category p) =>
w a a t -> [a] -> t
outs BazaarT (->) f a a t
b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [a] -> f [a]
f (forall (w :: * -> * -> * -> *) a b t.
Bizarre (->) w =>
w a b t -> [a]
ins BazaarT (->) f a a t
b) where b :: BazaarT (->) f a a t
b = Traversing (->) f s t a a
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s
{-# INLINE partsOf #-}
ipartsOf :: forall i p f s t a. (Indexable [i] p, Functor f) => Traversing (Indexed i) f s t a a -> Over p f s t [a] [a]
ipartsOf :: forall i (p :: * -> * -> *) (f :: * -> *) s t a.
(Indexable [i] p, Functor f) =>
Traversing (Indexed i) f s t a a -> Over p f s t [a] [a]
ipartsOf Traversing (Indexed i) f s t a a
l = forall (p :: * -> * -> *) (q :: * -> * -> *) a b r.
Conjoined p =>
((p ~ (->)) => q (a -> b) r) -> q (p a b) r -> q (p a b) r
conjoined
(\[a] -> f [a]
f s
s -> let b :: BazaarT (Indexed i) f a a t
b = forall a. a -> a
inline Traversing (Indexed i) f s t a a
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s in forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a t.
(Bizarre p w, Category p) =>
w a a t -> [a] -> t
outs BazaarT (Indexed i) f a a t
b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [a] -> f [a]
f (forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p, Comonad (Corep p)) =>
w a b t -> [a]
wins BazaarT (Indexed i) f a a t
b))
(\p [a] (f [a])
f s
s -> let b :: BazaarT (Indexed i) f a a t
b = forall a. a -> a
inline Traversing (Indexed i) f s t a a
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s; ([i]
is, [a]
as) = forall a b. [(a, b)] -> ([a], [b])
unzip (forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p) =>
w a b t -> [Corep p a]
pins BazaarT (Indexed i) f a a t
b) in forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a t.
(Bizarre p w, Category p) =>
w a a t -> [a] -> t
outs BazaarT (Indexed i) f a a t
b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall i (p :: * -> * -> *) a b.
Indexable i p =>
p a b -> i -> a -> b
indexed p [a] (f [a])
f ([i]
is :: [i]) [a]
as)
{-# INLINE ipartsOf #-}
partsOf' :: ATraversal s t a a -> Lens s t [a] [a]
partsOf' :: forall s t a. ATraversal s t a a -> Lens s t [a] [a]
partsOf' ATraversal s t a a
l [a] -> f [a]
f s
s = forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a t.
(Bizarre p w, Category p) =>
w a a t -> [a] -> t
outs Bazaar (->) a a t
b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [a] -> f [a]
f (forall (w :: * -> * -> * -> *) a b t.
Bizarre (->) w =>
w a b t -> [a]
ins Bazaar (->) a a t
b) where b :: Bazaar (->) a a t
b = ATraversal s t a a
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s
{-# INLINE partsOf' #-}
ipartsOf' :: forall i p f s t a. (Indexable [i] p, Functor f) => Over (Indexed i) (Bazaar' (Indexed i) a) s t a a -> Over p f s t [a] [a]
ipartsOf' :: forall i (p :: * -> * -> *) (f :: * -> *) s t a.
(Indexable [i] p, Functor f) =>
Over (Indexed i) (Bazaar' (Indexed i) a) s t a a
-> Over p f s t [a] [a]
ipartsOf' Over (Indexed i) (Bazaar' (Indexed i) a) s t a a
l = forall (p :: * -> * -> *) (q :: * -> * -> *) a b r.
Conjoined p =>
((p ~ (->)) => q (a -> b) r) -> q (p a b) r -> q (p a b) r
conjoined
(\[a] -> f [a]
f s
s -> let b :: Bazaar' (Indexed i) a t
b = forall a. a -> a
inline Over (Indexed i) (Bazaar' (Indexed i) a) s t a a
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s in forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a t.
(Bizarre p w, Category p) =>
w a a t -> [a] -> t
outs Bazaar' (Indexed i) a t
b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [a] -> f [a]
f (forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p, Comonad (Corep p)) =>
w a b t -> [a]
wins Bazaar' (Indexed i) a t
b))
(\p [a] (f [a])
f s
s -> let b :: Bazaar' (Indexed i) a t
b = forall a. a -> a
inline Over (Indexed i) (Bazaar' (Indexed i) a) s t a a
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s; ([i]
is, [a]
as) = forall a b. [(a, b)] -> ([a], [b])
unzip (forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p) =>
w a b t -> [Corep p a]
pins Bazaar' (Indexed i) a t
b) in forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a t.
(Bizarre p w, Category p) =>
w a a t -> [a] -> t
outs Bazaar' (Indexed i) a t
b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall i (p :: * -> * -> *) a b.
Indexable i p =>
p a b -> i -> a -> b
indexed p [a] (f [a])
f ([i]
is :: [i]) [a]
as)
{-# INLINE ipartsOf' #-}
unsafePartsOf :: Functor f => Traversing (->) f s t a b -> LensLike f s t [a] [b]
unsafePartsOf :: forall (f :: * -> *) s t a b.
Functor f =>
Traversing (->) f s t a b -> LensLike f s t [a] [b]
unsafePartsOf Traversing (->) f s t a b
l [a] -> f [b]
f s
s = forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p) =>
w a b t -> [b] -> t
unsafeOuts BazaarT (->) f a b t
b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [a] -> f [b]
f (forall (w :: * -> * -> * -> *) a b t.
Bizarre (->) w =>
w a b t -> [a]
ins BazaarT (->) f a b t
b) where b :: BazaarT (->) f a b t
b = Traversing (->) f s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s
{-# INLINE unsafePartsOf #-}
iunsafePartsOf :: forall i p f s t a b. (Indexable [i] p, Functor f) => Traversing (Indexed i) f s t a b -> Over p f s t [a] [b]
iunsafePartsOf :: forall i (p :: * -> * -> *) (f :: * -> *) s t a b.
(Indexable [i] p, Functor f) =>
Traversing (Indexed i) f s t a b -> Over p f s t [a] [b]
iunsafePartsOf Traversing (Indexed i) f s t a b
l = forall (p :: * -> * -> *) (q :: * -> * -> *) a b r.
Conjoined p =>
((p ~ (->)) => q (a -> b) r) -> q (p a b) r -> q (p a b) r
conjoined
(\[a] -> f [b]
f s
s -> let b :: BazaarT (Indexed i) f a b t
b = forall a. a -> a
inline Traversing (Indexed i) f s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s in forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p) =>
w a b t -> [b] -> t
unsafeOuts BazaarT (Indexed i) f a b t
b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [a] -> f [b]
f (forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p, Comonad (Corep p)) =>
w a b t -> [a]
wins BazaarT (Indexed i) f a b t
b))
(\p [a] (f [b])
f s
s -> let b :: BazaarT (Indexed i) f a b t
b = forall a. a -> a
inline Traversing (Indexed i) f s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s; ([i]
is,[a]
as) = forall a b. [(a, b)] -> ([a], [b])
unzip (forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p) =>
w a b t -> [Corep p a]
pins BazaarT (Indexed i) f a b t
b) in forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p) =>
w a b t -> [b] -> t
unsafeOuts BazaarT (Indexed i) f a b t
b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall i (p :: * -> * -> *) a b.
Indexable i p =>
p a b -> i -> a -> b
indexed p [a] (f [b])
f ([i]
is :: [i]) [a]
as)
{-# INLINE iunsafePartsOf #-}
unsafePartsOf' :: ATraversal s t a b -> Lens s t [a] [b]
unsafePartsOf' :: forall s t a b. ATraversal s t a b -> Lens s t [a] [b]
unsafePartsOf' ATraversal s t a b
l [a] -> f [b]
f s
s = forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p) =>
w a b t -> [b] -> t
unsafeOuts Bazaar (->) a b t
b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [a] -> f [b]
f (forall (w :: * -> * -> * -> *) a b t.
Bizarre (->) w =>
w a b t -> [a]
ins Bazaar (->) a b t
b) where b :: Bazaar (->) a b t
b = ATraversal s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s
{-# INLINE unsafePartsOf' #-}
iunsafePartsOf' :: forall i s t a b. Over (Indexed i) (Bazaar (Indexed i) a b) s t a b -> IndexedLens [i] s t [a] [b]
iunsafePartsOf' :: forall i s t a b.
Over (Indexed i) (Bazaar (Indexed i) a b) s t a b
-> IndexedLens [i] s t [a] [b]
iunsafePartsOf' Over (Indexed i) (Bazaar (Indexed i) a b) s t a b
l = forall (p :: * -> * -> *) (q :: * -> * -> *) a b r.
Conjoined p =>
((p ~ (->)) => q (a -> b) r) -> q (p a b) r -> q (p a b) r
conjoined
(\[a] -> f [b]
f s
s -> let b :: Bazaar (Indexed i) a b t
b = forall a. a -> a
inline Over (Indexed i) (Bazaar (Indexed i) a b) s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s in forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p) =>
w a b t -> [b] -> t
unsafeOuts Bazaar (Indexed i) a b t
b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [a] -> f [b]
f (forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p, Comonad (Corep p)) =>
w a b t -> [a]
wins Bazaar (Indexed i) a b t
b))
(\p [a] (f [b])
f s
s -> let b :: Bazaar (Indexed i) a b t
b = forall a. a -> a
inline Over (Indexed i) (Bazaar (Indexed i) a b) s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s; ([i]
is, [a]
as) = forall a b. [(a, b)] -> ([a], [b])
unzip (forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p) =>
w a b t -> [Corep p a]
pins Bazaar (Indexed i) a b t
b) in forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p) =>
w a b t -> [b] -> t
unsafeOuts Bazaar (Indexed i) a b t
b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall i (p :: * -> * -> *) a b.
Indexable i p =>
p a b -> i -> a -> b
indexed p [a] (f [b])
f ([i]
is :: [i]) [a]
as)
{-# INLINE iunsafePartsOf' #-}
singular :: (HasCallStack, Conjoined p, Functor f)
=> Traversing p f s t a a
-> Over p f s t a a
singular :: forall (p :: * -> * -> *) (f :: * -> *) s t a.
(HasCallStack, Conjoined p, Functor f) =>
Traversing p f s t a a -> Over p f s t a a
singular Traversing p f s t a a
l = forall (p :: * -> * -> *) (q :: * -> * -> *) a b r.
Conjoined p =>
((p ~ (->)) => q (a -> b) r) -> q (p a b) r -> q (p a b) r
conjoined
(\a -> f a
afb s
s -> let b :: BazaarT p f a a t
b = Traversing p f s t a a
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s in case forall (w :: * -> * -> * -> *) a b t.
Bizarre (->) w =>
w a b t -> [a]
ins BazaarT p f a a t
b of
(a
w:[a]
ws) -> forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p) =>
w a b t -> [b] -> t
unsafeOuts BazaarT p f a a t
b forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. a -> [a] -> [a]
:[a]
ws) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f a
afb a
w
[] -> forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p) =>
w a b t -> [b] -> t
unsafeOuts BazaarT p f a a t
b forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Monad m => a -> m a
return forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f a
afb (forall a. HasCallStack => [Char] -> a
error [Char]
"singular: empty traversal"))
(\p a (f a)
pafb s
s -> let b :: BazaarT p f a a t
b = Traversing p f s t a a
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s in case forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p) =>
w a b t -> [Corep p a]
pins BazaarT p f a a t
b of
(Corep p a
w:[Corep p a]
ws) -> forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p) =>
w a b t -> [b] -> t
unsafeOuts BazaarT p f a a t
b forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. a -> [a] -> [a]
:forall a b. (a -> b) -> [a] -> [b]
map forall (w :: * -> *) a. Comonad w => w a -> a
extract [Corep p a]
ws) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
cosieve p a (f a)
pafb Corep p a
w
[] -> forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p) =>
w a b t -> [b] -> t
unsafeOuts BazaarT p f a a t
b forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Monad m => a -> m a
return forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
cosieve p a (f a)
pafb (forall a. HasCallStack => [Char] -> a
error [Char]
"singular: empty traversal"))
{-# INLINE singular #-}
unsafeSingular :: (HasCallStack, Conjoined p, Functor f)
=> Traversing p f s t a b
-> Over p f s t a b
unsafeSingular :: forall (p :: * -> * -> *) (f :: * -> *) s t a b.
(HasCallStack, Conjoined p, Functor f) =>
Traversing p f s t a b -> Over p f s t a b
unsafeSingular Traversing p f s t a b
l = forall (p :: * -> * -> *) (q :: * -> * -> *) a b r.
Conjoined p =>
((p ~ (->)) => q (a -> b) r) -> q (p a b) r -> q (p a b) r
conjoined
(\a -> f b
afb s
s -> let b :: BazaarT p f a b t
b = forall a. a -> a
inline Traversing p f s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s in case forall (w :: * -> * -> * -> *) a b t.
Bizarre (->) w =>
w a b t -> [a]
ins BazaarT p f a b t
b of
[a
w] -> forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p) =>
w a b t -> [b] -> t
unsafeOuts BazaarT p f a b t
b forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Monad m => a -> m a
return forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
afb a
w
[] -> forall a. HasCallStack => [Char] -> a
error [Char]
"unsafeSingular: empty traversal"
[a]
_ -> forall a. HasCallStack => [Char] -> a
error [Char]
"unsafeSingular: traversing multiple results")
(\p a (f b)
pafb s
s -> let b :: BazaarT p f a b t
b = forall a. a -> a
inline Traversing p f s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s in case forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p) =>
w a b t -> [Corep p a]
pins BazaarT p f a b t
b of
[Corep p a
w] -> forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p) =>
w a b t -> [b] -> t
unsafeOuts BazaarT p f a b t
b forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Monad m => a -> m a
return forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
cosieve p a (f b)
pafb Corep p a
w
[] -> forall a. HasCallStack => [Char] -> a
error [Char]
"unsafeSingular: empty traversal"
[Corep p a]
_ -> forall a. HasCallStack => [Char] -> a
error [Char]
"unsafeSingular: traversing multiple results")
{-# INLINE unsafeSingular #-}
ins :: Bizarre (->) w => w a b t -> [a]
ins :: forall (w :: * -> * -> * -> *) a b t.
Bizarre (->) w =>
w a b t -> [a]
ins = forall a s. Getting (Endo [a]) s a -> s -> [a]
toListOf (forall (p :: * -> * -> *) (q :: * -> * -> *) (f :: * -> *) s t a b.
(Profunctor p, Profunctor q, Functor f, Contravariant f) =>
Optical p q f s t a b -> Optical' p q f s a
getting forall (p :: * -> * -> *) (w :: * -> * -> * -> *) (f :: * -> *) a b
t.
(Bizarre p w, Applicative f) =>
p a (f b) -> w a b t -> f t
bazaar)
{-# INLINE ins #-}
wins :: (Bizarre p w, Corepresentable p, Comonad (Corep p)) => w a b t -> [a]
wins :: forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p, Comonad (Corep p)) =>
w a b t -> [a]
wins = forall {k} a (b :: k). Const a b -> a
getConst forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. forall (p :: * -> * -> *) (w :: * -> * -> * -> *) (f :: * -> *) a b
t.
(Bizarre p w, Applicative f) =>
p a (f b) -> w a b t -> f t
bazaar (forall (p :: * -> * -> *) d c.
Corepresentable p =>
(Corep p d -> c) -> p d c
cotabulate forall a b. (a -> b) -> a -> b
$ \Corep p a
ra -> forall {k} a (b :: k). a -> Const a b
Const [forall (w :: * -> *) a. Comonad w => w a -> a
extract Corep p a
ra])
{-# INLINE wins #-}
pins :: (Bizarre p w, Corepresentable p) => w a b t -> [Corep p a]
pins :: forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p) =>
w a b t -> [Corep p a]
pins = forall {k} a (b :: k). Const a b -> a
getConst forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. forall (p :: * -> * -> *) (w :: * -> * -> * -> *) (f :: * -> *) a b
t.
(Bizarre p w, Applicative f) =>
p a (f b) -> w a b t -> f t
bazaar (forall (p :: * -> * -> *) d c.
Corepresentable p =>
(Corep p d -> c) -> p d c
cotabulate forall a b. (a -> b) -> a -> b
$ \Corep p a
ra -> forall {k} a (b :: k). a -> Const a b
Const [Corep p a
ra])
{-# INLINE pins #-}
parr :: (Profunctor p, C.Category p) => (a -> b) -> p a b
parr :: forall (p :: * -> * -> *) a b.
(Profunctor p, Category p) =>
(a -> b) -> p a b
parr a -> b
f = forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap a -> b
f forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
C.id
{-# INLINE parr #-}
outs :: (Bizarre p w, C.Category p) => w a a t -> [a] -> t
outs :: forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a t.
(Bizarre p w, Category p) =>
w a a t -> [a] -> t
outs = forall s a. State s a -> s -> a
evalState forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
`rmap` forall (p :: * -> * -> *) (w :: * -> * -> * -> *) (f :: * -> *) a b
t.
(Bizarre p w, Applicative f) =>
p a (f b) -> w a b t -> f t
bazaar (forall (p :: * -> * -> *) a b.
(Profunctor p, Category p) =>
(a -> b) -> p a b
parr (forall (m :: * -> *) s a. Monad m => (s -> (a, s)) -> StateT s m a
state forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> [a] -> (a, [a])
unconsWithDefault))
{-# INLINE outs #-}
unsafeOuts :: (Bizarre p w, Corepresentable p) => w a b t -> [b] -> t
unsafeOuts :: forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p) =>
w a b t -> [b] -> t
unsafeOuts = forall s a. State s a -> s -> a
evalState forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
`rmap` forall (p :: * -> * -> *) (w :: * -> * -> * -> *) (f :: * -> *) a b
t.
(Bizarre p w, Applicative f) =>
p a (f b) -> w a b t -> f t
bazaar (forall (p :: * -> * -> *) d c.
Corepresentable p =>
(Corep p d -> c) -> p d c
cotabulate (\Corep p a
_ -> forall (m :: * -> *) s a. Monad m => (s -> (a, s)) -> StateT s m a
state (forall a. a -> [a] -> (a, [a])
unconsWithDefault forall {a}. a
fakeVal)))
where fakeVal :: a
fakeVal = forall a. HasCallStack => [Char] -> a
error [Char]
"unsafePartsOf': not enough elements were supplied"
{-# INLINE unsafeOuts #-}
unconsWithDefault :: a -> [a] -> (a,[a])
unconsWithDefault :: forall a. a -> [a] -> (a, [a])
unconsWithDefault a
d [] = (a
d,[])
unconsWithDefault a
_ (a
x:[a]
xs) = (a
x,[a]
xs)
{-# INLINE unconsWithDefault #-}
holesOf :: Conjoined p
=> Over p (Bazaar p a a) s t a a -> s -> [Pretext p a a t]
holesOf :: forall (p :: * -> * -> *) a s t.
Conjoined p =>
Over p (Bazaar p a a) s t a a -> s -> [Pretext p a a t]
holesOf Over p (Bazaar p a a) s t a a
f s
xs = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Endo a -> a -> a
appEndo [] forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$
forall t m x. Holes t m x -> (x -> t) -> (m, x)
runHoles (forall (p :: * -> * -> *) a b t.
Bazaar p a b t
-> forall (f :: * -> *). Applicative f => p a (f b) -> f t
runBazaar (Over p (Bazaar p a a) s t a a
f forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
xs) (forall (p :: * -> * -> *) d c.
Corepresentable p =>
(Corep p d -> c) -> p d c
cotabulate forall (p :: * -> * -> *) a t.
(Corepresentable p, Comonad (Corep p)) =>
Corep p a -> Holes t (Endo [Pretext p a a t]) a
holeInOne)) forall a. a -> a
id
{-# INLINE holesOf #-}
holeInOne :: (Corepresentable p, Comonad (Corep p))
=> Corep p a -> Holes t (Endo [Pretext p a a t]) a
holeInOne :: forall (p :: * -> * -> *) a t.
(Corepresentable p, Comonad (Corep p)) =>
Corep p a -> Holes t (Endo [Pretext p a a t]) a
holeInOne Corep p a
x = forall t m x. ((x -> t) -> (m, x)) -> Holes t m x
Holes forall a b. (a -> b) -> a -> b
$ \a -> t
xt ->
( forall a. (a -> a) -> Endo a
Endo (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> t
xt (forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
cosieve forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell Corep p a
x) forall a. a -> [a] -> [a]
:)
, forall (w :: * -> *) a. Comonad w => w a -> a
extract Corep p a
x)
{-# INLINABLE holeInOne #-}
holes1Of :: Conjoined p
=> Over p (Bazaar1 p a a) s t a a -> s -> NonEmpty (Pretext p a a t)
holes1Of :: forall (p :: * -> * -> *) a s t.
Conjoined p =>
Over p (Bazaar1 p a a) s t a a -> s -> NonEmpty (Pretext p a a t)
holes1Of Over p (Bazaar1 p a a) s t a a
f s
xs = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. NonEmptyDList a -> [a] -> NonEmpty a
getNonEmptyDList [] forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$
forall t m x. Holes t m x -> (x -> t) -> (m, x)
runHoles (forall (p :: * -> * -> *) a b t.
Bazaar1 p a b t
-> forall (f :: * -> *). Apply f => p a (f b) -> f t
runBazaar1 (Over p (Bazaar1 p a a) s t a a
f forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
xs) (forall (p :: * -> * -> *) d c.
Corepresentable p =>
(Corep p d -> c) -> p d c
cotabulate forall (p :: * -> * -> *) a t.
(Corepresentable p, Category p) =>
Corep p a -> Holes t (NonEmptyDList (Pretext p a a t)) a
holeInOne1)) forall a. a -> a
id
{-# INLINE holes1Of #-}
holeInOne1 :: forall p a t. (Corepresentable p, C.Category p)
=> Corep p a -> Holes t (NonEmptyDList (Pretext p a a t)) a
holeInOne1 :: forall (p :: * -> * -> *) a t.
(Corepresentable p, Category p) =>
Corep p a -> Holes t (NonEmptyDList (Pretext p a a t)) a
holeInOne1 Corep p a
x = forall t m x. ((x -> t) -> (m, x)) -> Holes t m x
Holes forall a b. (a -> b) -> a -> b
$ \a -> t
xt ->
( forall a. ([a] -> NonEmpty a) -> NonEmptyDList a
NonEmptyDList (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> t
xt (forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
cosieve forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell Corep p a
x) forall a. a -> [a] -> NonEmpty a
:|)
, forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
cosieve (forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
C.id :: p a a) Corep p a
x)
newtype Holes t m x = Holes { forall t m x. Holes t m x -> (x -> t) -> (m, x)
runHoles :: (x -> t) -> (m, x) }
instance Functor (Holes t m) where
fmap :: forall a b. (a -> b) -> Holes t m a -> Holes t m b
fmap a -> b
f Holes t m a
xs = forall t m x. ((x -> t) -> (m, x)) -> Holes t m x
Holes forall a b. (a -> b) -> a -> b
$ \b -> t
xt ->
let
(m
qf, a
qv) = forall t m x. Holes t m x -> (x -> t) -> (m, x)
runHoles Holes t m a
xs (b -> t
xt forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f)
in (m
qf, a -> b
f a
qv)
instance Semigroup m => Apply (Holes t m) where
Holes t m (a -> b)
fs <.> :: forall a b. Holes t m (a -> b) -> Holes t m a -> Holes t m b
<.> Holes t m a
xs = forall t m x. ((x -> t) -> (m, x)) -> Holes t m x
Holes forall a b. (a -> b) -> a -> b
$ \b -> t
xt ->
let
(m
pf, a -> b
pv) = forall t m x. Holes t m x -> (x -> t) -> (m, x)
runHoles Holes t m (a -> b)
fs (b -> t
xt forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. (a -> b) -> a -> b
$ a
qv))
(m
qf, a
qv) = forall t m x. Holes t m x -> (x -> t) -> (m, x)
runHoles Holes t m a
xs (b -> t
xt forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
pv)
in (m
pf forall a. Semigroup a => a -> a -> a
<> m
qf, a -> b
pv a
qv)
instance Monoid m => Applicative (Holes t m) where
pure :: forall a. a -> Holes t m a
pure a
x = forall t m x. ((x -> t) -> (m, x)) -> Holes t m x
Holes forall a b. (a -> b) -> a -> b
$ \a -> t
_ -> (forall a. Monoid a => a
mempty, a
x)
Holes t m (a -> b)
fs <*> :: forall a b. Holes t m (a -> b) -> Holes t m a -> Holes t m b
<*> Holes t m a
xs = forall t m x. ((x -> t) -> (m, x)) -> Holes t m x
Holes forall a b. (a -> b) -> a -> b
$ \b -> t
xt ->
let
(m
pf, a -> b
pv) = forall t m x. Holes t m x -> (x -> t) -> (m, x)
runHoles Holes t m (a -> b)
fs (b -> t
xt forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. (a -> b) -> a -> b
$ a
qv))
(m
qf, a
qv) = forall t m x. Holes t m x -> (x -> t) -> (m, x)
runHoles Holes t m a
xs (b -> t
xt forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
pv)
in (m
pf forall a. Monoid a => a -> a -> a
`mappend` m
qf, a -> b
pv a
qv)
#if MIN_VERSION_base(4,10,0)
liftA2 :: forall a b c.
(a -> b -> c) -> Holes t m a -> Holes t m b -> Holes t m c
liftA2 a -> b -> c
f Holes t m a
xs Holes t m b
ys = forall t m x. ((x -> t) -> (m, x)) -> Holes t m x
Holes forall a b. (a -> b) -> a -> b
$ \c -> t
xt ->
let
(m
pf, a
pv) = forall t m x. Holes t m x -> (x -> t) -> (m, x)
runHoles Holes t m a
xs (c -> t
xt forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b c. (a -> b -> c) -> b -> a -> c
flip a -> b -> c
f b
qv)
(m
qf, b
qv) = forall t m x. Holes t m x -> (x -> t) -> (m, x)
runHoles Holes t m b
ys (c -> t
xt forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b -> c
f a
pv)
in (m
pf forall a. Monoid a => a -> a -> a
`mappend` m
qf, a -> b -> c
f a
pv b
qv)
#endif
both :: Bitraversable r => Traversal (r a a) (r b b) a b
both :: forall (r :: * -> * -> *) a b.
Bitraversable r =>
Traversal (r a a) (r b b) a b
both a -> f b
f = forall (t :: * -> * -> *) (f :: * -> *) a c b d.
(Bitraversable t, Applicative f) =>
(a -> f c) -> (b -> f d) -> t a b -> f (t c d)
bitraverse a -> f b
f a -> f b
f
{-# INLINE both #-}
both1 :: Bitraversable1 r => Traversal1 (r a a) (r b b) a b
both1 :: forall (r :: * -> * -> *) a b.
Bitraversable1 r =>
Traversal1 (r a a) (r b b) a b
both1 a -> f b
f = forall (t :: * -> * -> *) (f :: * -> *) a b c d.
(Bitraversable1 t, Apply f) =>
(a -> f b) -> (c -> f d) -> t a c -> f (t b d)
bitraverse1 a -> f b
f a -> f b
f
{-# INLINE both1 #-}
beside :: (Representable q, Applicative (Rep q), Applicative f, Bitraversable r)
=> Optical p q f s t a b
-> Optical p q f s' t' a b
-> Optical p q f (r s s') (r t t') a b
beside :: forall (q :: * -> * -> *) (f :: * -> *) (r :: * -> * -> *)
(p :: * -> * -> *) s t a b s' t'.
(Representable q, Applicative (Rep q), Applicative f,
Bitraversable r) =>
Optical p q f s t a b
-> Optical p q f s' t' a b -> Optical p q f (r s s') (r t t') a b
beside Optical p q f s t a b
l Optical p q f s' t' a b
r p a (f b)
f = forall (p :: * -> * -> *) d c.
Representable p =>
(d -> Rep p c) -> p d c
tabulate forall a b. (a -> b) -> a -> b
$ forall {k1} {k2} (f :: k1 -> *) (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. forall (t :: * -> * -> *) (f :: * -> *) a c b d.
(Bitraversable t, Applicative f) =>
(a -> f c) -> (b -> f d) -> t a b -> f (t c d)
bitraverse (forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. forall (p :: * -> * -> *) (f :: * -> *) a b.
Sieve p f =>
p a b -> a -> f b
sieve (Optical p q f s t a b
l p a (f b)
f)) (forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. forall (p :: * -> * -> *) (f :: * -> *) a b.
Sieve p f =>
p a b -> a -> f b
sieve (Optical p q f s' t' a b
r p a (f b)
f))
{-# INLINE beside #-}
taking :: (Conjoined p, Applicative f)
=> Int
-> Traversing p f s t a a
-> Over p f s t a a
taking :: forall (p :: * -> * -> *) (f :: * -> *) s t a.
(Conjoined p, Applicative f) =>
Int -> Traversing p f s t a a -> Over p f s t a a
taking Int
n Traversing p f s t a a
l = forall (p :: * -> * -> *) (q :: * -> * -> *) a b r.
Conjoined p =>
((p ~ (->)) => q (a -> b) r) -> q (p a b) r -> q (p a b) r
conjoined
(\ a -> f a
afb s
s -> let b :: BazaarT p f a a t
b = forall a. a -> a
inline Traversing p f s t a a
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s in forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a t.
(Bizarre p w, Category p) =>
w a a t -> [a] -> t
outs BazaarT p f a a t
b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse a -> f a
afb (forall a. Int -> [a] -> [a]
take Int
n forall a b. (a -> b) -> a -> b
$ forall (w :: * -> * -> * -> *) a b t.
Bizarre (->) w =>
w a b t -> [a]
ins BazaarT p f a a t
b))
(\ p a (f a)
pafb s
s -> let b :: BazaarT p f a a t
b = forall a. a -> a
inline Traversing p f s t a a
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s in forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a t.
(Bizarre p w, Category p) =>
w a a t -> [a] -> t
outs BazaarT p f a a t
b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
cosieve p a (f a)
pafb) (forall a. Int -> [a] -> [a]
take Int
n forall a b. (a -> b) -> a -> b
$ forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p) =>
w a b t -> [Corep p a]
pins BazaarT p f a a t
b))
{-# INLINE taking #-}
dropping :: (Conjoined p, Applicative f) => Int -> Over p (Indexing f) s t a a -> Over p f s t a a
dropping :: forall (p :: * -> * -> *) (f :: * -> *) s t a.
(Conjoined p, Applicative f) =>
Int -> Over p (Indexing f) s t a a -> Over p f s t a a
dropping Int
n Over p (Indexing f) s t a a
l p a (f a)
pafb s
s = forall a b. (a, b) -> b
snd forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Indexing f a -> Int -> (Int, f a)
runIndexing (Over p (Indexing f) s t a a
l p a (Indexing f a)
paifb s
s) Int
0 where
paifb :: p a (Indexing f a)
paifb = forall (p :: * -> * -> *) d c.
Corepresentable p =>
(Corep p d -> c) -> p d c
cotabulate forall a b. (a -> b) -> a -> b
$ \Corep p a
wa -> forall (f :: * -> *) a. (Int -> (Int, f a)) -> Indexing f a
Indexing forall a b. (a -> b) -> a -> b
$ \Int
i -> let i' :: Int
i' = Int
i forall a. Num a => a -> a -> a
+ Int
1 in Int
i' seq :: forall a b. a -> b -> b
`seq` (Int
i', if Int
i forall a. Ord a => a -> a -> Bool
< Int
n then forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall (w :: * -> *) a. Comonad w => w a -> a
extract Corep p a
wa) else forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
cosieve p a (f a)
pafb Corep p a
wa)
{-# INLINE dropping #-}
cloneTraversal :: ATraversal s t a b -> Traversal s t a b
cloneTraversal :: forall s t a b. ATraversal s t a b -> Traversal s t a b
cloneTraversal ATraversal s t a b
l a -> f b
f = forall (p :: * -> * -> *) (w :: * -> * -> * -> *) (f :: * -> *) a b
t.
(Bizarre p w, Applicative f) =>
p a (f b) -> w a b t -> f t
bazaar a -> f b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. ATraversal s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell
{-# INLINE cloneTraversal #-}
cloneIndexPreservingTraversal :: ATraversal s t a b -> IndexPreservingTraversal s t a b
cloneIndexPreservingTraversal :: forall s t a b.
ATraversal s t a b -> IndexPreservingTraversal s t a b
cloneIndexPreservingTraversal ATraversal s t a b
l p a (f b)
pafb = forall (p :: * -> * -> *) d c.
Corepresentable p =>
(Corep p d -> c) -> p d c
cotabulate forall a b. (a -> b) -> a -> b
$ \Corep p s
ws -> forall (p :: * -> * -> *) a b t.
Bazaar p a b t
-> forall (f :: * -> *). Applicative f => p a (f b) -> f t
runBazaar (ATraversal s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell (forall (w :: * -> *) a. Comonad w => w a -> a
extract Corep p s
ws)) forall a b. (a -> b) -> a -> b
$ \a
a -> forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
cosieve p a (f b)
pafb (a
a forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Corep p s
ws)
{-# INLINE cloneIndexPreservingTraversal #-}
cloneIndexedTraversal :: AnIndexedTraversal i s t a b -> IndexedTraversal i s t a b
cloneIndexedTraversal :: forall i s t a b.
AnIndexedTraversal i s t a b -> IndexedTraversal i s t a b
cloneIndexedTraversal AnIndexedTraversal i s t a b
l p a (f b)
f = forall (p :: * -> * -> *) (w :: * -> * -> * -> *) (f :: * -> *) a b
t.
(Bizarre p w, Applicative f) =>
p a (f b) -> w a b t -> f t
bazaar (forall i a b. (i -> a -> b) -> Indexed i a b
Indexed (forall i (p :: * -> * -> *) a b.
Indexable i p =>
p a b -> i -> a -> b
indexed p a (f b)
f)) forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnIndexedTraversal i s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell
{-# INLINE cloneIndexedTraversal #-}
cloneTraversal1 :: ATraversal1 s t a b -> Traversal1 s t a b
cloneTraversal1 :: forall s t a b. ATraversal1 s t a b -> Traversal1 s t a b
cloneTraversal1 ATraversal1 s t a b
l a -> f b
f = forall (p :: * -> * -> *) (w :: * -> * -> * -> *) (f :: * -> *) a b
t.
(Bizarre1 p w, Apply f) =>
p a (f b) -> w a b t -> f t
bazaar1 a -> f b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. ATraversal1 s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell
{-# INLINE cloneTraversal1 #-}
cloneIndexPreservingTraversal1 :: ATraversal1 s t a b -> IndexPreservingTraversal1 s t a b
cloneIndexPreservingTraversal1 :: forall s t a b.
ATraversal1 s t a b -> IndexPreservingTraversal1 s t a b
cloneIndexPreservingTraversal1 ATraversal1 s t a b
l p a (f b)
pafb = forall (p :: * -> * -> *) d c.
Corepresentable p =>
(Corep p d -> c) -> p d c
cotabulate forall a b. (a -> b) -> a -> b
$ \Corep p s
ws -> forall (p :: * -> * -> *) a b t.
Bazaar1 p a b t
-> forall (f :: * -> *). Apply f => p a (f b) -> f t
runBazaar1 (ATraversal1 s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell (forall (w :: * -> *) a. Comonad w => w a -> a
extract Corep p s
ws)) forall a b. (a -> b) -> a -> b
$ \a
a -> forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
cosieve p a (f b)
pafb (a
a forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Corep p s
ws)
{-# INLINE cloneIndexPreservingTraversal1 #-}
cloneIndexedTraversal1 :: AnIndexedTraversal1 i s t a b -> IndexedTraversal1 i s t a b
cloneIndexedTraversal1 :: forall i s t a b.
AnIndexedTraversal1 i s t a b -> IndexedTraversal1 i s t a b
cloneIndexedTraversal1 AnIndexedTraversal1 i s t a b
l p a (f b)
f = forall (p :: * -> * -> *) (w :: * -> * -> * -> *) (f :: * -> *) a b
t.
(Bizarre1 p w, Apply f) =>
p a (f b) -> w a b t -> f t
bazaar1 (forall i a b. (i -> a -> b) -> Indexed i a b
Indexed (forall i (p :: * -> * -> *) a b.
Indexable i p =>
p a b -> i -> a -> b
indexed p a (f b)
f)) forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnIndexedTraversal1 i s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell
{-# INLINE cloneIndexedTraversal1 #-}
itraverseOf :: (Indexed i a (f b) -> s -> f t) -> (i -> a -> f b) -> s -> f t
itraverseOf :: forall i a (f :: * -> *) b s t.
(Indexed i a (f b) -> s -> f t) -> (i -> a -> f b) -> s -> f t
itraverseOf Indexed i a (f b) -> s -> f t
l = Indexed i a (f b) -> s -> f t
l forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# forall i a b. (i -> a -> b) -> Indexed i a b
Indexed
{-# INLINE itraverseOf #-}
iforOf :: (Indexed i a (f b) -> s -> f t) -> s -> (i -> a -> f b) -> f t
iforOf :: forall i a (f :: * -> *) b s t.
(Indexed i a (f b) -> s -> f t) -> s -> (i -> a -> f b) -> f t
iforOf = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall i a (f :: * -> *) b s t.
(Indexed i a (f b) -> s -> f t) -> (i -> a -> f b) -> s -> f t
itraverseOf
{-# INLINE iforOf #-}
imapMOf :: Over (Indexed i) (WrappedMonad m) s t a b -> (i -> a -> m b) -> s -> m t
imapMOf :: forall i (m :: * -> *) s t a b.
Over (Indexed i) (WrappedMonad m) s t a b
-> (i -> a -> m b) -> s -> m t
imapMOf = coerce :: forall a b. Coercible a b => a -> b
coerce
{-# INLINE imapMOf #-}
iforMOf :: (Indexed i a (WrappedMonad m b) -> s -> WrappedMonad m t) -> s -> (i -> a -> m b) -> m t
iforMOf :: forall i a (m :: * -> *) b s t.
(Indexed i a (WrappedMonad m b) -> s -> WrappedMonad m t)
-> s -> (i -> a -> m b) -> m t
iforMOf = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall i (m :: * -> *) s t a b.
Over (Indexed i) (WrappedMonad m) s t a b
-> (i -> a -> m b) -> s -> m t
imapMOf
{-# INLINE iforMOf #-}
imapAccumROf :: Over (Indexed i) (Backwards (State acc)) s t a b -> (i -> acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
imapAccumROf :: forall i acc s t a b.
Over (Indexed i) (Backwards (State acc)) s t a b
-> (i -> acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
imapAccumROf = forall i acc s t a b.
Over (Indexed i) (State acc) s t a b
-> (i -> acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
imapAccumLOf forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) (q :: * -> * -> *) (f :: * -> *) s t a b.
(Profunctor p, Profunctor q) =>
Optical p q (Backwards f) s t a b -> Optical p q f s t a b
backwards
{-# INLINE imapAccumROf #-}
imapAccumLOf :: Over (Indexed i) (State acc) s t a b -> (i -> acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
imapAccumLOf :: forall i acc s t a b.
Over (Indexed i) (State acc) s t a b
-> (i -> acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
imapAccumLOf Over (Indexed i) (State acc) s t a b
l i -> acc -> a -> (acc, b)
f acc
acc0 s
s = forall a b. (a, b) -> (b, a)
swap (forall s a. State s a -> s -> (a, s)
runState (Over (Indexed i) (State acc) s t a b
l (forall i a b. (i -> a -> b) -> Indexed i a b
Indexed i -> a -> StateT acc Identity b
g) s
s) acc
acc0) where
g :: i -> a -> StateT acc Identity b
g i
i a
a = forall (m :: * -> *) s a. Monad m => (s -> (a, s)) -> StateT s m a
state forall a b. (a -> b) -> a -> b
$ \acc
acc -> forall a b. (a, b) -> (b, a)
swap (i -> acc -> a -> (acc, b)
f i
i acc
acc a
a)
{-# INLINE imapAccumLOf #-}
traversed :: Traversable f => IndexedTraversal Int (f a) (f b) a b
traversed :: forall (f :: * -> *) a b.
Traversable f =>
IndexedTraversal Int (f a) (f b) a b
traversed = forall (p :: * -> * -> *) (q :: * -> * -> *) a b r.
Conjoined p =>
((p ~ (->)) => q (a -> b) r) -> q (p a b) r -> q (p a b) r
conjoined forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (forall (p :: * -> * -> *) a (f :: * -> *) b s t.
Indexable Int p =>
((a -> Indexing f b) -> s -> Indexing f t) -> p a (f b) -> s -> f t
indexing forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse)
{-# INLINE [0] traversed #-}
imapList :: (Int -> a -> b) -> [a] -> [b]
imapList :: forall a b. (Int -> a -> b) -> [a] -> [b]
imapList Int -> a -> b
f = Int -> [a] -> [b]
go Int
0
where
go :: Int -> [a] -> [b]
go Int
i (a
x:[a]
xs) = Int -> a -> b
f Int
i a
x forall a. a -> [a] -> [a]
: Int -> [a] -> [b]
go (Int
iforall a. Num a => a -> a -> a
+Int
1) [a]
xs
go Int
_ [] = []
{-# INLINE imapList #-}
{-# RULES
"traversed -> mapped" traversed = sets fmap :: Functor f => ASetter (f a) (f b) a b;
"traversed -> folded" traversed = folded :: Foldable f => Getting (Endo r) (f a) a;
"traversed -> ifolded" traversed = folded :: Foldable f => IndexedGetting Int (Endo r) (f a) a;
"traversed -> imapList" traversed = isets imapList :: AnIndexedSetter Int [a] [b] a b;
"traversed -> imapSeq" traversed = isets mapWithIndex :: AnIndexedSetter Int (Seq a) (Seq b) a b;
"traversed -> imapVector" traversed = isets Vector.imap :: AnIndexedSetter Int (Vector a) (Vector b) a b;
#-}
traversed1 :: Traversable1 f => IndexedTraversal1 Int (f a) (f b) a b
traversed1 :: forall (f :: * -> *) a b.
Traversable1 f =>
IndexedTraversal1 Int (f a) (f b) a b
traversed1 = forall (p :: * -> * -> *) (q :: * -> * -> *) a b r.
Conjoined p =>
((p ~ (->)) => q (a -> b) r) -> q (p a b) r -> q (p a b) r
conjoined forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 (forall (p :: * -> * -> *) a (f :: * -> *) b s t.
Indexable Int p =>
((a -> Indexing f b) -> s -> Indexing f t) -> p a (f b) -> s -> f t
indexing forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1)
{-# INLINE traversed1 #-}
traversed64 :: Traversable f => IndexedTraversal Int64 (f a) (f b) a b
traversed64 :: forall (f :: * -> *) a b.
Traversable f =>
IndexedTraversal Int64 (f a) (f b) a b
traversed64 = forall (p :: * -> * -> *) (q :: * -> * -> *) a b r.
Conjoined p =>
((p ~ (->)) => q (a -> b) r) -> q (p a b) r -> q (p a b) r
conjoined forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (forall (p :: * -> * -> *) a (f :: * -> *) b s t.
Indexable Int64 p =>
((a -> Indexing64 f b) -> s -> Indexing64 f t)
-> p a (f b) -> s -> f t
indexing64 forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse)
{-# INLINE traversed64 #-}
ignored :: Applicative f => pafb -> s -> f s
ignored :: forall (f :: * -> *) pafb s. Applicative f => pafb -> s -> f s
ignored pafb
_ = forall (f :: * -> *) a. Applicative f => a -> f a
pure
{-# INLINE ignored #-}
class Ord k => TraverseMin k m | m -> k where
traverseMin :: IndexedTraversal' k (m v) v
instance TraverseMin Int IntMap.IntMap where
traverseMin :: forall v. IndexedTraversal' Int (IntMap v) v
traverseMin p v (f v)
f IntMap v
m = case forall a. IntMap a -> Maybe ((Int, a), IntMap a)
IntMap.minViewWithKey IntMap v
m of
Just ((Int
k,v
a), IntMap v
_) -> forall i (p :: * -> * -> *) a b.
Indexable i p =>
p a b -> i -> a -> b
indexed p v (f v)
f Int
k v
a forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \v
v -> forall a. (a -> Maybe a) -> IntMap a -> IntMap a
IntMap.updateMin (forall a b. a -> b -> a
const (forall a. a -> Maybe a
Just v
v)) IntMap v
m
Maybe ((Int, v), IntMap v)
Nothing -> forall (f :: * -> *) a. Applicative f => a -> f a
pure IntMap v
m
{-# INLINE traverseMin #-}
instance Ord k => TraverseMin k (Map k) where
traverseMin :: forall v. IndexedTraversal' k (Map k v) v
traverseMin p v (f v)
f Map k v
m = case forall k a. Map k a -> Maybe ((k, a), Map k a)
Map.minViewWithKey Map k v
m of
Just ((k
k, v
a), Map k v
_) -> forall i (p :: * -> * -> *) a b.
Indexable i p =>
p a b -> i -> a -> b
indexed p v (f v)
f k
k v
a forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \v
v -> forall a k. (a -> Maybe a) -> Map k a -> Map k a
Map.updateMin (forall a b. a -> b -> a
const (forall a. a -> Maybe a
Just v
v)) Map k v
m
Maybe ((k, v), Map k v)
Nothing -> forall (f :: * -> *) a. Applicative f => a -> f a
pure Map k v
m
{-# INLINE traverseMin #-}
class Ord k => TraverseMax k m | m -> k where
traverseMax :: IndexedTraversal' k (m v) v
instance TraverseMax Int IntMap.IntMap where
traverseMax :: forall v. IndexedTraversal' Int (IntMap v) v
traverseMax p v (f v)
f IntMap v
m = case forall a. IntMap a -> Maybe ((Int, a), IntMap a)
IntMap.maxViewWithKey IntMap v
m of
Just ((Int
k,v
a), IntMap v
_) -> forall i (p :: * -> * -> *) a b.
Indexable i p =>
p a b -> i -> a -> b
indexed p v (f v)
f Int
k v
a forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \v
v -> forall a. (a -> Maybe a) -> IntMap a -> IntMap a
IntMap.updateMax (forall a b. a -> b -> a
const (forall a. a -> Maybe a
Just v
v)) IntMap v
m
Maybe ((Int, v), IntMap v)
Nothing -> forall (f :: * -> *) a. Applicative f => a -> f a
pure IntMap v
m
{-# INLINE traverseMax #-}
instance Ord k => TraverseMax k (Map k) where
traverseMax :: forall v. IndexedTraversal' k (Map k v) v
traverseMax p v (f v)
f Map k v
m = case forall k a. Map k a -> Maybe ((k, a), Map k a)
Map.maxViewWithKey Map k v
m of
Just ((k
k, v
a), Map k v
_) -> forall i (p :: * -> * -> *) a b.
Indexable i p =>
p a b -> i -> a -> b
indexed p v (f v)
f k
k v
a forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \v
v -> forall a k. (a -> Maybe a) -> Map k a -> Map k a
Map.updateMax (forall a b. a -> b -> a
const (forall a. a -> Maybe a
Just v
v)) Map k v
m
Maybe ((k, v), Map k v)
Nothing -> forall (f :: * -> *) a. Applicative f => a -> f a
pure Map k v
m
{-# INLINE traverseMax #-}
elementOf :: Applicative f
=> LensLike (Indexing f) s t a a
-> Int
-> IndexedLensLike Int f s t a a
elementOf :: forall (f :: * -> *) s t a.
Applicative f =>
LensLike (Indexing f) s t a a
-> Int -> IndexedLensLike Int f s t a a
elementOf LensLike (Indexing f) s t a a
l Int
p = forall (f :: * -> *) s t a.
Applicative f =>
LensLike (Indexing f) s t a a
-> (Int -> Bool) -> IndexedLensLike Int f s t a a
elementsOf LensLike (Indexing f) s t a a
l (Int
p forall a. Eq a => a -> a -> Bool
==)
{-# INLINE elementOf #-}
element :: Traversable t => Int -> IndexedTraversal' Int (t a) a
element :: forall (t :: * -> *) a.
Traversable t =>
Int -> IndexedTraversal' Int (t a) a
element Int
i = forall (f :: * -> *) s t a.
Applicative f =>
LensLike (Indexing f) s t a a
-> Int -> IndexedLensLike Int f s t a a
elementOf forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Int
i
{-# INLINE element #-}
elementsOf :: Applicative f
=> LensLike (Indexing f) s t a a
-> (Int -> Bool)
-> IndexedLensLike Int f s t a a
elementsOf :: forall (f :: * -> *) s t a.
Applicative f =>
LensLike (Indexing f) s t a a
-> (Int -> Bool) -> IndexedLensLike Int f s t a a
elementsOf LensLike (Indexing f) s t a a
l Int -> Bool
p p a (f a)
iafb s
s = forall a b. (a, b) -> b
snd forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Indexing f a -> Int -> (Int, f a)
runIndexing (LensLike (Indexing f) s t a a
l (\a
a -> forall (f :: * -> *) a. (Int -> (Int, f a)) -> Indexing f a
Indexing (\Int
i -> Int
i seq :: forall a b. a -> b -> b
`seq` (Int
i forall a. Num a => a -> a -> a
+ Int
1, if Int -> Bool
p Int
i then forall i (p :: * -> * -> *) a b.
Indexable i p =>
p a b -> i -> a -> b
indexed p a (f a)
iafb Int
i a
a else forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a))) s
s) Int
0
{-# INLINE elementsOf #-}
elements :: Traversable t => (Int -> Bool) -> IndexedTraversal' Int (t a) a
elements :: forall (t :: * -> *) a.
Traversable t =>
(Int -> Bool) -> IndexedTraversal' Int (t a) a
elements Int -> Bool
i = forall (f :: * -> *) s t a.
Applicative f =>
LensLike (Indexing f) s t a a
-> (Int -> Bool) -> IndexedLensLike Int f s t a a
elementsOf forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Int -> Bool
i
{-# INLINE elements #-}
failover :: Alternative m => LensLike ((,) Any) s t a b -> (a -> b) -> s -> m t
failover :: forall (m :: * -> *) s t a b.
Alternative m =>
LensLike ((,) Any) s t a b -> (a -> b) -> s -> m t
failover LensLike ((,) Any) s t a b
l a -> b
afb s
s = case LensLike ((,) Any) s t a b
l ((,) (Bool -> Any
Any Bool
True) forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
afb) s
s of
(Any Bool
True, t
t) -> forall (f :: * -> *) a. Applicative f => a -> f a
pure t
t
(Any Bool
False, t
_) -> forall (f :: * -> *) a. Alternative f => f a
empty
{-# INLINE failover #-}
ifailover :: Alternative m => Over (Indexed i) ((,) Any) s t a b -> (i -> a -> b) -> s -> m t
ifailover :: forall (m :: * -> *) i s t a b.
Alternative m =>
Over (Indexed i) ((,) Any) s t a b -> (i -> a -> b) -> s -> m t
ifailover Over (Indexed i) ((,) Any) s t a b
l i -> a -> b
iafb s
s = case Over (Indexed i) ((,) Any) s t a b
l ((,) (Bool -> Any
Any Bool
True) forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
`rmap` forall i a b. (i -> a -> b) -> Indexed i a b
Indexed i -> a -> b
iafb) s
s of
(Any Bool
True, t
t) -> forall (f :: * -> *) a. Applicative f => a -> f a
pure t
t
(Any Bool
False, t
_) -> forall (f :: * -> *) a. Alternative f => f a
empty
{-# INLINE ifailover #-}
failing :: (Conjoined p, Applicative f) => Traversing p f s t a b -> Over p f s t a b -> Over p f s t a b
failing :: forall (p :: * -> * -> *) (f :: * -> *) s t a b.
(Conjoined p, Applicative f) =>
Traversing p f s t a b -> Over p f s t a b -> Over p f s t a b
failing Traversing p f s t a b
l Over p f s t a b
r p a (f b)
pafb s
s = case forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p) =>
w a b t -> [Corep p a]
pins BazaarT p f a b t
b of
[] -> Over p f s t a b
r p a (f b)
pafb s
s
[Corep p a]
_ -> forall (p :: * -> * -> *) (w :: * -> * -> * -> *) (f :: * -> *) a b
t.
(Bizarre p w, Applicative f) =>
p a (f b) -> w a b t -> f t
bazaar p a (f b)
pafb BazaarT p f a b t
b
where b :: BazaarT p f a b t
b = Traversing p f s t a b
l forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s
infixl 5 `failing`
deepOf :: (Conjoined p, Applicative f) => LensLike f s t s t -> Traversing p f s t a b -> Over p f s t a b
deepOf :: forall (p :: * -> * -> *) (f :: * -> *) s t a b.
(Conjoined p, Applicative f) =>
LensLike f s t s t -> Traversing p f s t a b -> Over p f s t a b
deepOf LensLike f s t s t
r Traversing p f s t a b
l = forall (p :: * -> * -> *) (f :: * -> *) s t a b.
(Conjoined p, Applicative f) =>
Traversing p f s t a b -> Over p f s t a b -> Over p f s t a b
failing Traversing p f s t a b
l (LensLike f s t s t
r forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) (f :: * -> *) s t a b.
(Conjoined p, Applicative f) =>
LensLike f s t s t -> Traversing p f s t a b -> Over p f s t a b
deepOf LensLike f s t s t
r Traversing p f s t a b
l)
confusing :: Applicative f => LensLike (Curried (Yoneda f) (Yoneda f)) s t a b -> LensLike f s t a b
confusing :: forall (f :: * -> *) s t a b.
Applicative f =>
LensLike (Curried (Yoneda f) (Yoneda f)) s t a b
-> LensLike f s t a b
confusing LensLike (Curried (Yoneda f) (Yoneda f)) s t a b
t = \a -> f b
f -> forall (f :: * -> *) a. Yoneda f a -> f a
lowerYoneda forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) (g :: * -> *) a.
Applicative f =>
Curried f g a -> g a
lowerCurried forall b c a. (b -> c) -> (a -> b) -> a -> c
. LensLike (Curried (Yoneda f) (Yoneda f)) s t a b
t (forall (f :: * -> *) a.
Applicative f =>
f a -> Curried (Yoneda f) (Yoneda f) a
liftCurriedYoneda forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> f b
f)
where
liftCurriedYoneda :: Applicative f => f a -> Curried (Yoneda f) (Yoneda f) a
liftCurriedYoneda :: forall (f :: * -> *) a.
Applicative f =>
f a -> Curried (Yoneda f) (Yoneda f) a
liftCurriedYoneda f a
fa = forall (g :: * -> *) (h :: * -> *) a.
(forall r. g (a -> r) -> h r) -> Curried g h a
Curried (forall (f :: * -> *) a b.
Applicative f =>
Yoneda f (a -> b) -> f a -> Yoneda f b
`yap` f a
fa)
{-# INLINE liftCurriedYoneda #-}
yap :: Applicative f => Yoneda f (a -> b) -> f a -> Yoneda f b
yap :: forall (f :: * -> *) a b.
Applicative f =>
Yoneda f (a -> b) -> f a -> Yoneda f b
yap (Yoneda forall b. ((a -> b) -> b) -> f b
k) f a
fa = forall (f :: * -> *) a. (forall b. (a -> b) -> f b) -> Yoneda f a
Yoneda (\b -> b
ab_r -> forall b. ((a -> b) -> b) -> f b
k (b -> b
ab_r forall b c a. (b -> c) -> (a -> b) -> a -> c
.) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> f a
fa)
{-# INLINE yap #-}
{-# INLINE confusing #-}
traverseByOf :: Traversal s t a b -> (forall x. x -> f x) -> (forall x y. f (x -> y) -> f x -> f y) -> (a -> f b) -> s -> f t
traverseByOf :: forall s t a b (f :: * -> *).
Traversal s t a b
-> (forall x. x -> f x)
-> (forall x y. f (x -> y) -> f x -> f y)
-> (a -> f b)
-> s
-> f t
traverseByOf Traversal s t a b
l forall x. x -> f x
pur forall x y. f (x -> y) -> f x -> f y
app a -> f b
f = forall (f :: * -> *) t a.
(forall x. x -> f x)
-> (forall x y. f (x -> y) -> f x -> f y)
-> (forall s.
Reifies s (ReifiedApplicative f) =>
t -> ReflectedApplicative f s a)
-> t
-> f a
reifyApplicative forall x. x -> f x
pur forall x y. f (x -> y) -> f x -> f y
app (Traversal s t a b
l (forall {k} {k1} (f :: k -> *) (s :: k1) (a :: k).
f a -> ReflectedApplicative f s a
ReflectedApplicative forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. a -> f b
f))
sequenceByOf :: Traversal s t (f b) b -> (forall x. x -> f x) -> (forall x y. f (x -> y) -> f x -> f y) -> s -> f t
sequenceByOf :: forall s t (f :: * -> *) b.
Traversal s t (f b) b
-> (forall x. x -> f x)
-> (forall x y. f (x -> y) -> f x -> f y)
-> s
-> f t
sequenceByOf Traversal s t (f b) b
l forall x. x -> f x
pur forall x y. f (x -> y) -> f x -> f y
app = forall (f :: * -> *) t a.
(forall x. x -> f x)
-> (forall x y. f (x -> y) -> f x -> f y)
-> (forall s.
Reifies s (ReifiedApplicative f) =>
t -> ReflectedApplicative f s a)
-> t
-> f a
reifyApplicative forall x. x -> f x
pur forall x y. f (x -> y) -> f x -> f y
app (Traversal s t (f b) b
l forall {k} {k1} (f :: k -> *) (s :: k1) (a :: k).
f a -> ReflectedApplicative f s a
ReflectedApplicative)