{-# 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'
, 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
traverseOf :: LensLike f s t a b -> (a -> f b) -> s -> f t
traverseOf :: LensLike f s t a b -> LensLike f s t a b
traverseOf = LensLike f s t a b -> LensLike f s t a b
forall a. a -> a
id
{-# INLINE traverseOf #-}
forOf :: LensLike f s t a b -> s -> (a -> f b) -> f t
forOf :: LensLike f s t a b -> s -> (a -> f b) -> f t
forOf = LensLike f s t a b -> s -> (a -> f b) -> f t
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 :: 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 f b -> f b
forall a. a -> a
id
{-# INLINE sequenceAOf #-}
mapMOf :: LensLike (WrappedMonad m) s t a b -> (a -> m b) -> s -> m t
mapMOf :: LensLike (WrappedMonad m) s t a b -> (a -> m b) -> s -> m t
mapMOf LensLike (WrappedMonad m) s t a b
l a -> m b
cmd = WrappedMonad m t -> m t
forall (m :: * -> *) a. WrappedMonad m a -> m a
unwrapMonad (WrappedMonad m t -> m t) -> (s -> WrappedMonad m t) -> s -> m t
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 a b
l (m b -> WrappedMonad m b
forall (m :: * -> *) a. m a -> WrappedMonad m a
WrapMonad (m b -> WrappedMonad m b) -> (a -> m b) -> a -> WrappedMonad m b
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. a -> m b
cmd)
{-# INLINE mapMOf #-}
forMOf :: LensLike (WrappedMonad m) s t a b -> s -> (a -> m b) -> m t
forMOf :: 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 = WrappedMonad m t -> m t
forall (m :: * -> *) a. WrappedMonad m a -> m a
unwrapMonad (LensLike (WrappedMonad m) s t a b
l (m b -> WrappedMonad m b
forall (m :: * -> *) a. m a -> WrappedMonad m a
WrapMonad (m b -> WrappedMonad m b) -> (a -> m b) -> a -> WrappedMonad m b
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 :: LensLike (WrappedMonad m) s t (m b) b -> s -> m t
sequenceOf LensLike (WrappedMonad m) s t (m b) b
l = WrappedMonad m t -> m t
forall (m :: * -> *) a. WrappedMonad m a -> m a
unwrapMonad (WrappedMonad m t -> m t) -> (s -> WrappedMonad m t) -> s -> m t
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 m b -> WrappedMonad m b
forall (m :: * -> *) a. m a -> WrappedMonad m a
WrapMonad
{-# INLINE sequenceOf #-}
transposeOf :: LensLike ZipList s t [a] a -> s -> [t]
transposeOf :: LensLike ZipList s t [a] a -> s -> [t]
transposeOf LensLike ZipList s t [a] a
l = ZipList t -> [t]
forall a. ZipList a -> [a]
getZipList (ZipList t -> [t]) -> (s -> ZipList t) -> s -> [t]
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 [a] -> ZipList a
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 :: LensLike (Backwards (State acc)) s t a b
-> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
mapAccumROf = LensLike (State acc) s t a b
-> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
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
-> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t))
-> (LensLike (Backwards (State acc)) s t a b
-> LensLike (State acc) s t a b)
-> LensLike (Backwards (State acc)) s t a b
-> (acc -> a -> (acc, b))
-> acc
-> s
-> (acc, t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LensLike (Backwards (State acc)) s t a b
-> LensLike (State acc) s t a b
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 :: 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 = (t, acc) -> (acc, t)
forall a b. (a, b) -> (b, a)
swap (State acc t -> acc -> (t, acc)
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 = (acc -> (b, acc)) -> StateT acc Identity b
forall (m :: * -> *) s a. Monad m => (s -> (a, s)) -> StateT s m a
state ((acc -> (b, acc)) -> StateT acc Identity b)
-> (acc -> (b, acc)) -> StateT acc Identity b
forall a b. (a -> b) -> a -> b
$ \acc
acc -> (acc, b) -> (b, 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 :: 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 = (Maybe a, t) -> t
forall a b. (a, b) -> b
snd ((Maybe a, t) -> t) -> (s -> (Maybe a, t)) -> s -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LensLike (Backwards (State (Maybe a))) s t a a
-> (Maybe a -> a -> (Maybe a, a)) -> Maybe a -> s -> (Maybe a, t)
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 Maybe a
forall a. Maybe a
Nothing where
step :: Maybe a -> a -> (Maybe a, a)
step Maybe a
Nothing a
a = (a -> Maybe a
forall a. a -> Maybe a
Just a
a, a
a)
step (Just a
s) a
a = (a -> Maybe 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 :: 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 = (Maybe a, t) -> t
forall a b. (a, b) -> b
snd ((Maybe a, t) -> t) -> (s -> (Maybe a, t)) -> s -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LensLike (State (Maybe a)) s t a a
-> (Maybe a -> a -> (Maybe a, a)) -> Maybe a -> s -> (Maybe a, t)
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 Maybe a
forall a. Maybe a
Nothing where
step :: Maybe a -> a -> (Maybe a, a)
step Maybe a
Nothing a
a = (a -> Maybe a
forall a. a -> Maybe a
Just a
a, a
a)
step (Just a
s) a
a = (a -> Maybe 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 :: (a -> f b) -> Bazaar (->) a c s -> f (Bazaar (->) b c s)
loci a -> f b
f Bazaar (->) a c s
w = Compose f (Bazaar (->) b c) s -> f (Bazaar (->) b c s)
forall k1 (f :: k1 -> *) k2 (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose (Bazaar (->) a c s
-> (a -> Compose f (Bazaar (->) b c) c)
-> Compose f (Bazaar (->) b c) s
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 (f (Bazaar (->) b c c) -> Compose f (Bazaar (->) b c) c
forall k k1 (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose (f (Bazaar (->) b c c) -> Compose f (Bazaar (->) b c) c)
-> (a -> f (Bazaar (->) b c c))
-> a
-> Compose f (Bazaar (->) b c) c
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. (b -> Bazaar (->) b c c) -> f b -> f (Bazaar (->) b c c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> Bazaar (->) b c c
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell (f b -> f (Bazaar (->) b c c))
-> (a -> f b) -> a -> f (Bazaar (->) b c c)
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 :: p a (f b)
-> Bazaar (Indexed i) a c s -> f (Bazaar (Indexed i) b c s)
iloci p a (f b)
f Bazaar (Indexed i) a c s
w = Compose f (Bazaar (Indexed i) b c) s
-> f (Bazaar (Indexed i) b c s)
forall k1 (f :: k1 -> *) k2 (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose (Bazaar (Indexed i) a c s
-> Indexed i a (Compose f (Bazaar (Indexed i) b c) c)
-> Compose f (Bazaar (Indexed i) b c) s
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 (f (Bazaar (Indexed i) b c c)
-> Compose f (Bazaar (Indexed i) b c) c
forall k k1 (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose (f (Bazaar (Indexed i) b c c)
-> Compose f (Bazaar (Indexed i) b c) c)
-> Indexed i a (f (Bazaar (Indexed i) b c c))
-> Indexed i a (Compose f (Bazaar (Indexed i) b c) c)
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. (i -> a -> f (Bazaar (Indexed i) b c c))
-> Indexed i a (f (Bazaar (Indexed i) b c c))
forall i a b. (i -> a -> b) -> Indexed i a b
Indexed (\i
i -> (b -> Bazaar (Indexed i) b c c)
-> f b -> f (Bazaar (Indexed i) b c c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Indexed i b (Bazaar (Indexed i) b c c)
-> i -> b -> Bazaar (Indexed i) b c c
forall i (p :: * -> * -> *) a b.
Indexable i p =>
p a b -> i -> a -> b
indexed Indexed i b (Bazaar (Indexed i) b c c)
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell i
i) (f b -> f (Bazaar (Indexed i) b c c))
-> (a -> f b) -> a -> f (Bazaar (Indexed i) b c c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p a (f b) -> i -> a -> f b
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 :: 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 = BazaarT (->) f a a t -> [a] -> t
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a t.
(Bizarre p w, Category p) =>
w a a t -> [a] -> t
outs BazaarT (->) f a a t
b ([a] -> t) -> f [a] -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [a] -> f [a]
f (BazaarT (->) f a a t -> [a]
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 a -> BazaarT (->) f a a a
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 :: 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 = ((p ~ (->)) => ([a] -> f [a]) -> s -> f t)
-> Over p f s t [a] [a] -> Over p f s t [a] [a]
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 = Traversing (Indexed i) f s t a a
-> Traversing (Indexed i) f s t a a
forall a. a -> a
inline Traversing (Indexed i) f s t a a
l Indexed i a (BazaarT (Indexed i) f a a a)
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s in BazaarT (Indexed i) f a a t -> [a] -> t
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 ([a] -> t) -> f [a] -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [a] -> f [a]
f (BazaarT (Indexed i) f a a t -> [a]
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 = Traversing (Indexed i) f s t a a
-> Traversing (Indexed i) f s t a a
forall a. a -> a
inline Traversing (Indexed i) f s t a a
l Indexed i a (BazaarT (Indexed i) f a a a)
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s; ([i]
is, [a]
as) = [(i, a)] -> ([i], [a])
forall a b. [(a, b)] -> ([a], [b])
unzip (BazaarT (Indexed i) f a a t -> [Corep (Indexed i) a]
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 BazaarT (Indexed i) f a a t -> [a] -> t
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 ([a] -> t) -> f [a] -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> p [a] (f [a]) -> [i] -> [a] -> f [a]
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' :: ATraversal s t a a -> Lens s t [a] [a]
partsOf' ATraversal s t a a
l [a] -> f [a]
f s
s = Bazaar (->) a a t -> [a] -> t
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a t.
(Bizarre p w, Category p) =>
w a a t -> [a] -> t
outs Bazaar (->) a a t
b ([a] -> t) -> f [a] -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [a] -> f [a]
f (Bazaar (->) a a t -> [a]
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 a -> Bazaar (->) a a a
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' :: 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 = ((p ~ (->)) => ([a] -> f [a]) -> s -> f t)
-> Over p f s t [a] [a] -> Over p f s t [a] [a]
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 = Over (Indexed i) (Bazaar' (Indexed i) a) s t a a
-> Over (Indexed i) (Bazaar' (Indexed i) a) s t a a
forall a. a -> a
inline Over (Indexed i) (Bazaar' (Indexed i) a) s t a a
l Indexed i a (Bazaar (Indexed i) a a a)
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s in Bazaar' (Indexed i) a t -> [a] -> t
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a t.
(Bizarre p w, Category p) =>
w a a t -> [a] -> t
outs Bazaar' (Indexed i) a t
b ([a] -> t) -> f [a] -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [a] -> f [a]
f (Bazaar' (Indexed i) a t -> [a]
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 = Over (Indexed i) (Bazaar' (Indexed i) a) s t a a
-> Over (Indexed i) (Bazaar' (Indexed i) a) s t a a
forall a. a -> a
inline Over (Indexed i) (Bazaar' (Indexed i) a) s t a a
l Indexed i a (Bazaar (Indexed i) a a a)
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s; ([i]
is, [a]
as) = [(i, a)] -> ([i], [a])
forall a b. [(a, b)] -> ([a], [b])
unzip (Bazaar' (Indexed i) a t -> [Corep (Indexed i) a]
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 Bazaar' (Indexed i) a t -> [a] -> t
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a t.
(Bizarre p w, Category p) =>
w a a t -> [a] -> t
outs Bazaar' (Indexed i) a t
b ([a] -> t) -> f [a] -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> p [a] (f [a]) -> [i] -> [a] -> f [a]
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 :: 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 = BazaarT (->) f a b t -> [b] -> t
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p) =>
w a b t -> [b] -> t
unsafeOuts BazaarT (->) f a b t
b ([b] -> t) -> f [b] -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [a] -> f [b]
f (BazaarT (->) f a b t -> [a]
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 a -> BazaarT (->) f a b b
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 :: 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 = ((p ~ (->)) => ([a] -> f [b]) -> s -> f t)
-> Over p f s t [a] [b] -> Over p f s t [a] [b]
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 = Traversing (Indexed i) f s t a b
-> Traversing (Indexed i) f s t a b
forall a. a -> a
inline Traversing (Indexed i) f s t a b
l Indexed i a (BazaarT (Indexed i) f a b b)
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s in BazaarT (Indexed i) f a b t -> [b] -> t
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 ([b] -> t) -> f [b] -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [a] -> f [b]
f (BazaarT (Indexed i) f a b t -> [a]
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 = Traversing (Indexed i) f s t a b
-> Traversing (Indexed i) f s t a b
forall a. a -> a
inline Traversing (Indexed i) f s t a b
l Indexed i a (BazaarT (Indexed i) f a b b)
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s; ([i]
is,[a]
as) = [(i, a)] -> ([i], [a])
forall a b. [(a, b)] -> ([a], [b])
unzip (BazaarT (Indexed i) f a b t -> [Corep (Indexed i) a]
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 BazaarT (Indexed i) f a b t -> [b] -> t
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 ([b] -> t) -> f [b] -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> p [a] (f [b]) -> [i] -> [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' :: ATraversal s t a b -> Lens s t [a] [b]
unsafePartsOf' ATraversal s t a b
l [a] -> f [b]
f s
s = Bazaar (->) a b t -> [b] -> t
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b t.
(Bizarre p w, Corepresentable p) =>
w a b t -> [b] -> t
unsafeOuts Bazaar (->) a b t
b ([b] -> t) -> f [b] -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [a] -> f [b]
f (Bazaar (->) a b t -> [a]
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 a -> Bazaar (->) a b b
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' :: 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 = ((p ~ (->)) => ([a] -> f [b]) -> s -> f t)
-> (p [a] (f [b]) -> s -> f t) -> p [a] (f [b]) -> s -> f t
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 = Over (Indexed i) (Bazaar (Indexed i) a b) s t a b
-> Over (Indexed i) (Bazaar (Indexed i) a b) s t a b
forall a. a -> a
inline Over (Indexed i) (Bazaar (Indexed i) a b) s t a b
l Indexed i a (Bazaar (Indexed i) a b b)
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s in Bazaar (Indexed i) a b t -> [b] -> t
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 ([b] -> t) -> f [b] -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [a] -> f [b]
f (Bazaar (Indexed i) a b t -> [a]
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 = Over (Indexed i) (Bazaar (Indexed i) a b) s t a b
-> Over (Indexed i) (Bazaar (Indexed i) a b) s t a b
forall a. a -> a
inline Over (Indexed i) (Bazaar (Indexed i) a b) s t a b
l Indexed i a (Bazaar (Indexed i) a b b)
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s; ([i]
is, [a]
as) = [(i, a)] -> ([i], [a])
forall a b. [(a, b)] -> ([a], [b])
unzip (Bazaar (Indexed i) a b t -> [Corep (Indexed i) a]
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 Bazaar (Indexed i) a b t -> [b] -> t
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 ([b] -> t) -> f [b] -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> p [a] (f [b]) -> [i] -> [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 :: Traversing p f s t a a -> Over p f s t a a
singular Traversing p f s t a a
l = ((p ~ (->)) => (a -> f a) -> s -> f t)
-> Over p f s t a a -> Over p f s t a a
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 p a (BazaarT p f a a a)
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s in case BazaarT p f a a t -> [a]
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) -> BazaarT p f a a t -> [a] -> t
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 ([a] -> t) -> (a -> [a]) -> a -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
ws) (a -> t) -> f a -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f a
afb a
w
[] -> BazaarT p f a a t -> [a] -> t
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 ([a] -> t) -> (a -> [a]) -> a -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> [a]
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> t) -> f a -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f a
afb ([Char] -> a
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 p a (BazaarT p f a a a)
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s in case BazaarT p f a a t -> [Corep p a]
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) -> BazaarT p f a a t -> [a] -> t
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 ([a] -> t) -> (a -> [a]) -> a -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> [a] -> [a]
forall a. a -> [a] -> [a]
:(Corep p a -> a) -> [Corep p a] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map Corep p a -> a
forall (w :: * -> *) a. Comonad w => w a -> a
extract [Corep p a]
ws) (a -> t) -> f a -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> p a (f a) -> Corep p a -> f a
forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
cosieve p a (f a)
pafb Corep p a
w
[] -> BazaarT p f a a t -> [a] -> t
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 ([a] -> t) -> (a -> [a]) -> a -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> [a]
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> t) -> f a -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> p a (f a) -> Corep p a -> f a
forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
cosieve p a (f a)
pafb ([Char] -> Corep p a
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 :: Traversing p f s t a b -> Over p f s t a b
unsafeSingular Traversing p f s t a b
l = ((p ~ (->)) => (a -> f b) -> s -> f t)
-> Over p f s t a b -> Over p f s t a b
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 = Traversing p f s t a b -> Traversing p f s t a b
forall a. a -> a
inline Traversing p f s t a b
l p a (BazaarT p f a b b)
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s in case BazaarT p f a b t -> [a]
forall (w :: * -> * -> * -> *) a b t.
Bizarre (->) w =>
w a b t -> [a]
ins BazaarT p f a b t
b of
[a
w] -> BazaarT p f a b t -> [b] -> t
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 ([b] -> t) -> (b -> [b]) -> b -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> [b]
forall (m :: * -> *) a. Monad m => a -> m a
return (b -> t) -> f b -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
afb a
w
[] -> [Char] -> f t
forall a. HasCallStack => [Char] -> a
error [Char]
"unsafeSingular: empty traversal"
[a]
_ -> [Char] -> f t
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 = Traversing p f s t a b -> Traversing p f s t a b
forall a. a -> a
inline Traversing p f s t a b
l p a (BazaarT p f a b b)
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s in case BazaarT p f a b t -> [Corep p a]
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] -> BazaarT p f a b t -> [b] -> t
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 ([b] -> t) -> (b -> [b]) -> b -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> [b]
forall (m :: * -> *) a. Monad m => a -> m a
return (b -> t) -> f b -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> p a (f b) -> Corep p 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
[] -> [Char] -> f t
forall a. HasCallStack => [Char] -> a
error [Char]
"unsafeSingular: empty traversal"
[Corep p a]
_ -> [Char] -> f t
forall a. HasCallStack => [Char] -> a
error [Char]
"unsafeSingular: traversing multiple results")
{-# INLINE unsafeSingular #-}
ins :: Bizarre (->) w => w a b t -> [a]
ins :: w a b t -> [a]
ins = Getting (Endo [a]) (w a b t) a -> w a b t -> [a]
forall a s. Getting (Endo [a]) s a -> s -> [a]
toListOf (Optical (->) (->) (Const (Endo [a])) (w a b t) t a b
-> Getting (Endo [a]) (w a b t) a
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 Optical (->) (->) (Const (Endo [a])) (w a b t) t a b
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 :: w a b t -> [a]
wins = Const [a] t -> [a]
forall a k (b :: k). Const a b -> a
getConst (Const [a] t -> [a]) -> (w a b t -> Const [a] t) -> w a b t -> [a]
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. p a (Const [a] b) -> w a b t -> Const [a] t
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) (f :: * -> *) a b
t.
(Bizarre p w, Applicative f) =>
p a (f b) -> w a b t -> f t
bazaar ((Corep p a -> Const [a] b) -> p a (Const [a] b)
forall (p :: * -> * -> *) d c.
Corepresentable p =>
(Corep p d -> c) -> p d c
cotabulate ((Corep p a -> Const [a] b) -> p a (Const [a] b))
-> (Corep p a -> Const [a] b) -> p a (Const [a] b)
forall a b. (a -> b) -> a -> b
$ \Corep p a
ra -> [a] -> Const [a] b
forall k a (b :: k). a -> Const a b
Const [Corep p a -> a
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 :: w a b t -> [Corep p a]
pins = Const [Corep p a] t -> [Corep p a]
forall a k (b :: k). Const a b -> a
getConst (Const [Corep p a] t -> [Corep p a])
-> (w a b t -> Const [Corep p a] t) -> w a b t -> [Corep p a]
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. p a (Const [Corep p a] b) -> w a b t -> Const [Corep p a] t
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) (f :: * -> *) a b
t.
(Bizarre p w, Applicative f) =>
p a (f b) -> w a b t -> f t
bazaar ((Corep p a -> Const [Corep p a] b) -> p a (Const [Corep p a] b)
forall (p :: * -> * -> *) d c.
Corepresentable p =>
(Corep p d -> c) -> p d c
cotabulate ((Corep p a -> Const [Corep p a] b) -> p a (Const [Corep p a] b))
-> (Corep p a -> Const [Corep p a] b) -> p a (Const [Corep p a] b)
forall a b. (a -> b) -> a -> b
$ \Corep p a
ra -> [Corep p a] -> Const [Corep p a] b
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 :: (a -> b) -> p a b
parr a -> b
f = (a -> b) -> p b b -> p a b
forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap a -> b
f p b b
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 :: w a a t -> [a] -> t
outs = State [a] t -> [a] -> t
forall s a. State s a -> s -> a
evalState (State [a] t -> [a] -> t)
-> (w a a t -> State [a] t) -> w a a t -> [a] -> t
forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
`rmap` p a (StateT [a] Identity a) -> w a a t -> State [a] t
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) (f :: * -> *) a b
t.
(Bizarre p w, Applicative f) =>
p a (f b) -> w a b t -> f t
bazaar ((a -> StateT [a] Identity a) -> p a (StateT [a] Identity a)
forall (p :: * -> * -> *) a b.
(Profunctor p, Category p) =>
(a -> b) -> p a b
parr (([a] -> (a, [a])) -> StateT [a] Identity a
forall (m :: * -> *) s a. Monad m => (s -> (a, s)) -> StateT s m a
state (([a] -> (a, [a])) -> StateT [a] Identity a)
-> (a -> [a] -> (a, [a])) -> a -> StateT [a] Identity a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> [a] -> (a, [a])
forall a. a -> [a] -> (a, [a])
unconsWithDefault))
{-# INLINE outs #-}
unsafeOuts :: (Bizarre p w, Corepresentable p) => w a b t -> [b] -> t
unsafeOuts :: w a b t -> [b] -> t
unsafeOuts = State [b] t -> [b] -> t
forall s a. State s a -> s -> a
evalState (State [b] t -> [b] -> t)
-> (w a b t -> State [b] t) -> w a b t -> [b] -> t
forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
`rmap` p a (StateT [b] Identity b) -> w a b t -> State [b] t
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) (f :: * -> *) a b
t.
(Bizarre p w, Applicative f) =>
p a (f b) -> w a b t -> f t
bazaar ((Corep p a -> StateT [b] Identity b) -> p a (StateT [b] Identity b)
forall (p :: * -> * -> *) d c.
Corepresentable p =>
(Corep p d -> c) -> p d c
cotabulate (\Corep p a
_ -> ([b] -> (b, [b])) -> StateT [b] Identity b
forall (m :: * -> *) s a. Monad m => (s -> (a, s)) -> StateT s m a
state (b -> [b] -> (b, [b])
forall a. a -> [a] -> (a, [a])
unconsWithDefault b
forall a. a
fakeVal)))
where fakeVal :: a
fakeVal = [Char] -> a
forall a. HasCallStack => [Char] -> a
error [Char]
"unsafePartsOf': not enough elements were supplied"
{-# INLINE unsafeOuts #-}
unconsWithDefault :: a -> [a] -> (a,[a])
unconsWithDefault :: 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 :: 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 = (Endo [Pretext p a a t] -> [Pretext p a a t] -> [Pretext p a a t])
-> [Pretext p a a t] -> Endo [Pretext p a a t] -> [Pretext p a a t]
forall a b c. (a -> b -> c) -> b -> a -> c
flip Endo [Pretext p a a t] -> [Pretext p a a t] -> [Pretext p a a t]
forall a. Endo a -> a -> a
appEndo [] (Endo [Pretext p a a t] -> [Pretext p a a t])
-> ((Endo [Pretext p a a t], t) -> Endo [Pretext p a a t])
-> (Endo [Pretext p a a t], t)
-> [Pretext p a a t]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Endo [Pretext p a a t], t) -> Endo [Pretext p a a t]
forall a b. (a, b) -> a
fst ((Endo [Pretext p a a t], t) -> [Pretext p a a t])
-> (Endo [Pretext p a a t], t) -> [Pretext p a a t]
forall a b. (a -> b) -> a -> b
$
Holes t (Endo [Pretext p a a t]) t
-> (t -> t) -> (Endo [Pretext p a a t], t)
forall t m x. Holes t m x -> (x -> t) -> (m, x)
runHoles (Bazaar p a a t
-> p a (Holes t (Endo [Pretext p a a t]) a)
-> Holes t (Endo [Pretext p a a t]) t
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 p a (Bazaar p a a a)
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
xs) ((Corep p a -> Holes t (Endo [Pretext p a a t]) a)
-> p a (Holes t (Endo [Pretext p a a t]) a)
forall (p :: * -> * -> *) d c.
Corepresentable p =>
(Corep p d -> c) -> p d c
cotabulate Corep p a -> Holes t (Endo [Pretext p a a t]) a
forall (p :: * -> * -> *) a t.
(Corepresentable p, Comonad (Corep p)) =>
Corep p a -> Holes t (Endo [Pretext p a a t]) a
holeInOne)) t -> t
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 :: Corep p a -> Holes t (Endo [Pretext p a a t]) a
holeInOne Corep p a
x = ((a -> t) -> (Endo [Pretext p a a t], a))
-> Holes t (Endo [Pretext p a a t]) a
forall t m x. ((x -> t) -> (m, x)) -> Holes t m x
Holes (((a -> t) -> (Endo [Pretext p a a t], a))
-> Holes t (Endo [Pretext p a a t]) a)
-> ((a -> t) -> (Endo [Pretext p a a t], a))
-> Holes t (Endo [Pretext p a a t]) a
forall a b. (a -> b) -> a -> b
$ \a -> t
xt ->
( ([Pretext p a a t] -> [Pretext p a a t]) -> Endo [Pretext p a a t]
forall a. (a -> a) -> Endo a
Endo ((a -> t) -> Pretext p a a a -> Pretext p a a t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> t
xt (p a (Pretext p a a a) -> Corep p a -> Pretext p a a a
forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
cosieve p a (Pretext p a a a)
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell Corep p a
x) Pretext p a a t -> [Pretext p a a t] -> [Pretext p a a t]
forall a. a -> [a] -> [a]
:)
, Corep p 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 :: 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 = (NonEmptyDList (Pretext p a a t)
-> [Pretext p a a t] -> NonEmpty (Pretext p a a t))
-> [Pretext p a a t]
-> NonEmptyDList (Pretext p a a t)
-> NonEmpty (Pretext p a a t)
forall a b c. (a -> b -> c) -> b -> a -> c
flip NonEmptyDList (Pretext p a a t)
-> [Pretext p a a t] -> NonEmpty (Pretext p a a t)
forall a. NonEmptyDList a -> [a] -> NonEmpty a
getNonEmptyDList [] (NonEmptyDList (Pretext p a a t) -> NonEmpty (Pretext p a a t))
-> ((NonEmptyDList (Pretext p a a t), t)
-> NonEmptyDList (Pretext p a a t))
-> (NonEmptyDList (Pretext p a a t), t)
-> NonEmpty (Pretext p a a t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NonEmptyDList (Pretext p a a t), t)
-> NonEmptyDList (Pretext p a a t)
forall a b. (a, b) -> a
fst ((NonEmptyDList (Pretext p a a t), t)
-> NonEmpty (Pretext p a a t))
-> (NonEmptyDList (Pretext p a a t), t)
-> NonEmpty (Pretext p a a t)
forall a b. (a -> b) -> a -> b
$
Holes t (NonEmptyDList (Pretext p a a t)) t
-> (t -> t) -> (NonEmptyDList (Pretext p a a t), t)
forall t m x. Holes t m x -> (x -> t) -> (m, x)
runHoles (Bazaar1 p a a t
-> p a (Holes t (NonEmptyDList (Pretext p a a t)) a)
-> Holes t (NonEmptyDList (Pretext p a a t)) t
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 p a (Bazaar1 p a a a)
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
xs) ((Corep p a -> Holes t (NonEmptyDList (Pretext p a a t)) a)
-> p a (Holes t (NonEmptyDList (Pretext p a a t)) a)
forall (p :: * -> * -> *) d c.
Corepresentable p =>
(Corep p d -> c) -> p d c
cotabulate Corep p a -> Holes t (NonEmptyDList (Pretext p a a t)) a
forall (p :: * -> * -> *) a t.
(Corepresentable p, Category p) =>
Corep p a -> Holes t (NonEmptyDList (Pretext p a a t)) a
holeInOne1)) t -> t
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 :: Corep p a -> Holes t (NonEmptyDList (Pretext p a a t)) a
holeInOne1 Corep p a
x = ((a -> t) -> (NonEmptyDList (Pretext p a a t), a))
-> Holes t (NonEmptyDList (Pretext p a a t)) a
forall t m x. ((x -> t) -> (m, x)) -> Holes t m x
Holes (((a -> t) -> (NonEmptyDList (Pretext p a a t), a))
-> Holes t (NonEmptyDList (Pretext p a a t)) a)
-> ((a -> t) -> (NonEmptyDList (Pretext p a a t), a))
-> Holes t (NonEmptyDList (Pretext p a a t)) a
forall a b. (a -> b) -> a -> b
$ \a -> t
xt ->
( ([Pretext p a a t] -> NonEmpty (Pretext p a a t))
-> NonEmptyDList (Pretext p a a t)
forall a. ([a] -> NonEmpty a) -> NonEmptyDList a
NonEmptyDList ((a -> t) -> Pretext p a a a -> Pretext p a a t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> t
xt (p a (Pretext p a a a) -> Corep p a -> Pretext p a a a
forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
cosieve p a (Pretext p a a a)
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell Corep p a
x) Pretext p a a t -> [Pretext p a a t] -> NonEmpty (Pretext p a a t)
forall a. a -> [a] -> NonEmpty a
:|)
, p a a -> Corep p a -> a
forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
cosieve (p a a
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 { Holes t m x -> (x -> t) -> (m, x)
runHoles :: (x -> t) -> (m, x) }
instance Functor (Holes t m) where
fmap :: (a -> b) -> Holes t m a -> Holes t m b
fmap a -> b
f Holes t m a
xs = ((b -> t) -> (m, b)) -> Holes t m b
forall t m x. ((x -> t) -> (m, x)) -> Holes t m x
Holes (((b -> t) -> (m, b)) -> Holes t m b)
-> ((b -> t) -> (m, b)) -> Holes t m b
forall a b. (a -> b) -> a -> b
$ \b -> t
xt ->
let
(m
qf, a
qv) = Holes t m a -> (a -> t) -> (m, a)
forall t m x. Holes t m x -> (x -> t) -> (m, x)
runHoles Holes t m a
xs (b -> t
xt (b -> t) -> (a -> b) -> a -> t
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 <.> :: Holes t m (a -> b) -> Holes t m a -> Holes t m b
<.> Holes t m a
xs = ((b -> t) -> (m, b)) -> Holes t m b
forall t m x. ((x -> t) -> (m, x)) -> Holes t m x
Holes (((b -> t) -> (m, b)) -> Holes t m b)
-> ((b -> t) -> (m, b)) -> Holes t m b
forall a b. (a -> b) -> a -> b
$ \b -> t
xt ->
let
(m
pf, a -> b
pv) = Holes t m (a -> b) -> ((a -> b) -> t) -> (m, a -> b)
forall t m x. Holes t m x -> (x -> t) -> (m, x)
runHoles Holes t m (a -> b)
fs (b -> t
xt (b -> t) -> ((a -> b) -> b) -> (a -> b) -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((a -> b) -> a -> b
forall a b. (a -> b) -> a -> b
$ a
qv))
(m
qf, a
qv) = Holes t m a -> (a -> t) -> (m, a)
forall t m x. Holes t m x -> (x -> t) -> (m, x)
runHoles Holes t m a
xs (b -> t
xt (b -> t) -> (a -> b) -> a -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
pv)
in (m
pf m -> m -> m
forall a. Semigroup a => a -> a -> a
<> m
qf, a -> b
pv a
qv)
instance Monoid m => Applicative (Holes t m) where
pure :: a -> Holes t m a
pure a
x = ((a -> t) -> (m, a)) -> Holes t m a
forall t m x. ((x -> t) -> (m, x)) -> Holes t m x
Holes (((a -> t) -> (m, a)) -> Holes t m a)
-> ((a -> t) -> (m, a)) -> Holes t m a
forall a b. (a -> b) -> a -> b
$ \a -> t
_ -> (m
forall a. Monoid a => a
mempty, a
x)
Holes t m (a -> b)
fs <*> :: Holes t m (a -> b) -> Holes t m a -> Holes t m b
<*> Holes t m a
xs = ((b -> t) -> (m, b)) -> Holes t m b
forall t m x. ((x -> t) -> (m, x)) -> Holes t m x
Holes (((b -> t) -> (m, b)) -> Holes t m b)
-> ((b -> t) -> (m, b)) -> Holes t m b
forall a b. (a -> b) -> a -> b
$ \b -> t
xt ->
let
(m
pf, a -> b
pv) = Holes t m (a -> b) -> ((a -> b) -> t) -> (m, a -> b)
forall t m x. Holes t m x -> (x -> t) -> (m, x)
runHoles Holes t m (a -> b)
fs (b -> t
xt (b -> t) -> ((a -> b) -> b) -> (a -> b) -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((a -> b) -> a -> b
forall a b. (a -> b) -> a -> b
$ a
qv))
(m
qf, a
qv) = Holes t m a -> (a -> t) -> (m, a)
forall t m x. Holes t m x -> (x -> t) -> (m, x)
runHoles Holes t m a
xs (b -> t
xt (b -> t) -> (a -> b) -> a -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
pv)
in (m
pf m -> m -> m
forall a. Monoid a => a -> a -> a
`mappend` m
qf, a -> b
pv a
qv)
#if MIN_VERSION_base(4,10,0)
liftA2 :: (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 = ((c -> t) -> (m, c)) -> Holes t m c
forall t m x. ((x -> t) -> (m, x)) -> Holes t m x
Holes (((c -> t) -> (m, c)) -> Holes t m c)
-> ((c -> t) -> (m, c)) -> Holes t m c
forall a b. (a -> b) -> a -> b
$ \c -> t
xt ->
let
(m
pf, a
pv) = Holes t m a -> (a -> t) -> (m, a)
forall t m x. Holes t m x -> (x -> t) -> (m, x)
runHoles Holes t m a
xs (c -> t
xt (c -> t) -> (a -> c) -> a -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b -> c) -> b -> a -> c
forall a b c. (a -> b -> c) -> b -> a -> c
flip a -> b -> c
f b
qv)
(m
qf, b
qv) = Holes t m b -> (b -> t) -> (m, b)
forall t m x. Holes t m x -> (x -> t) -> (m, x)
runHoles Holes t m b
ys (c -> t
xt (c -> t) -> (b -> c) -> b -> t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b -> c
f a
pv)
in (m
pf m -> m -> m
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 :: Traversal (r a a) (r b b) a b
both a -> f b
f = (a -> f b) -> (a -> f b) -> r a a -> f (r b b)
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 :: Traversal1 (r a a) (r b b) a b
both1 a -> f b
f = (a -> f b) -> (a -> f b) -> r a a -> f (r b b)
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 :: 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 = (r s s' -> Rep q (f (r t t'))) -> q (r s s') (f (r t t'))
forall (p :: * -> * -> *) d c.
Representable p =>
(d -> Rep p c) -> p d c
tabulate ((r s s' -> Rep q (f (r t t'))) -> q (r s s') (f (r t t')))
-> (r s s' -> Rep q (f (r t t'))) -> q (r s s') (f (r t t'))
forall a b. (a -> b) -> a -> b
$ Compose (Rep q) f (r t t') -> Rep q (f (r t t'))
forall k1 (f :: k1 -> *) k2 (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose (Compose (Rep q) f (r t t') -> Rep q (f (r t t')))
-> (r s s' -> Compose (Rep q) f (r t t'))
-> r s s'
-> Rep q (f (r t t'))
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. (s -> Compose (Rep q) f t)
-> (s' -> Compose (Rep q) f t')
-> r s s'
-> Compose (Rep q) f (r t t')
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 (Rep q (f t) -> Compose (Rep q) f t
forall k k1 (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose (Rep q (f t) -> Compose (Rep q) f t)
-> (s -> Rep q (f t)) -> s -> Compose (Rep q) f t
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. q s (f t) -> s -> Rep q (f t)
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)) (Rep q (f t') -> Compose (Rep q) f t'
forall k k1 (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose (Rep q (f t') -> Compose (Rep q) f t')
-> (s' -> Rep q (f t')) -> s' -> Compose (Rep q) f t'
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. q s' (f t') -> s' -> Rep q (f t')
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 :: 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 = ((p ~ (->)) => (a -> f a) -> s -> f t)
-> Over p f s t a a -> Over p f s t a a
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 -> Traversing p f s t a a
forall a. a -> a
inline Traversing p f s t a a
l p a (BazaarT p f a a a)
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s in BazaarT p f a a t -> [a] -> t
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a t.
(Bizarre p w, Category p) =>
w a a t -> [a] -> t
outs BazaarT p f a a t
b ([a] -> t) -> f [a] -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> f a) -> [a] -> f [a]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse a -> f a
afb (Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
take Int
n ([a] -> [a]) -> [a] -> [a]
forall a b. (a -> b) -> a -> b
$ BazaarT p f a a t -> [a]
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 = Traversing p f s t a a -> Traversing p f s t a a
forall a. a -> a
inline Traversing p f s t a a
l p a (BazaarT p f a a a)
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell s
s in BazaarT p f a a t -> [a] -> t
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a t.
(Bizarre p w, Category p) =>
w a a t -> [a] -> t
outs BazaarT p f a a t
b ([a] -> t) -> f [a] -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Corep p a -> f a) -> [Corep p a] -> f [a]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (p a (f a) -> Corep p a -> f a
forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
cosieve p a (f a)
pafb) (Int -> [Corep p a] -> [Corep p a]
forall a. Int -> [a] -> [a]
take Int
n ([Corep p a] -> [Corep p a]) -> [Corep p a] -> [Corep p a]
forall a b. (a -> b) -> a -> b
$ BazaarT p f a a t -> [Corep p a]
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 :: 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 = (Int, f t) -> f t
forall a b. (a, b) -> b
snd ((Int, f t) -> f t) -> (Int, f t) -> f t
forall a b. (a -> b) -> a -> b
$ Indexing f t -> Int -> (Int, f t)
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 = (Corep p a -> Indexing f a) -> p a (Indexing f a)
forall (p :: * -> * -> *) d c.
Corepresentable p =>
(Corep p d -> c) -> p d c
cotabulate ((Corep p a -> Indexing f a) -> p a (Indexing f a))
-> (Corep p a -> Indexing f a) -> p a (Indexing f a)
forall a b. (a -> b) -> a -> b
$ \Corep p a
wa -> (Int -> (Int, f a)) -> Indexing f a
forall (f :: * -> *) a. (Int -> (Int, f a)) -> Indexing f a
Indexing ((Int -> (Int, f a)) -> Indexing f a)
-> (Int -> (Int, f a)) -> Indexing f a
forall a b. (a -> b) -> a -> b
$ \Int
i -> let i' :: Int
i' = Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 in Int
i' Int -> (Int, f a) -> (Int, f a)
`seq` (Int
i', if Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
n then a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Corep p a -> a
forall (w :: * -> *) a. Comonad w => w a -> a
extract Corep p a
wa) else p a (f a) -> Corep p a -> f a
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 :: ATraversal s t a b -> Traversal s t a b
cloneTraversal ATraversal s t a b
l a -> f b
f = (a -> f b) -> Bazaar (->) a b t -> f t
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 (Bazaar (->) a b t -> f t) -> (s -> Bazaar (->) a b t) -> s -> f t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ATraversal s t a b
l a -> Bazaar (->) a b b
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 :: ATraversal s t a b -> IndexPreservingTraversal s t a b
cloneIndexPreservingTraversal ATraversal s t a b
l p a (f b)
pafb = (Corep p s -> f t) -> p s (f t)
forall (p :: * -> * -> *) d c.
Corepresentable p =>
(Corep p d -> c) -> p d c
cotabulate ((Corep p s -> f t) -> p s (f t))
-> (Corep p s -> f t) -> p s (f t)
forall a b. (a -> b) -> a -> b
$ \Corep p s
ws -> Bazaar (->) a b t
-> forall (f :: * -> *). Applicative f => (a -> f b) -> f t
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 a -> Bazaar (->) a b b
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell (Corep p s -> s
forall (w :: * -> *) a. Comonad w => w a -> a
extract Corep p s
ws)) ((a -> f b) -> f t) -> (a -> f b) -> f t
forall a b. (a -> b) -> a -> b
$ \a
a -> p a (f b) -> Corep p a -> f b
forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
cosieve p a (f b)
pafb (a
a a -> Corep p s -> Corep p 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 :: 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 = Indexed i a (f b) -> Bazaar (Indexed i) a b t -> f t
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) (f :: * -> *) a b
t.
(Bizarre p w, Applicative f) =>
p a (f b) -> w a b t -> f t
bazaar ((i -> a -> f b) -> Indexed i a (f b)
forall i a b. (i -> a -> b) -> Indexed i a b
Indexed (p a (f b) -> i -> a -> f b
forall i (p :: * -> * -> *) a b.
Indexable i p =>
p a b -> i -> a -> b
indexed p a (f b)
f)) (Bazaar (Indexed i) a b t -> f t)
-> (s -> Bazaar (Indexed i) a b t) -> s -> f t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnIndexedTraversal i s t a b
l Indexed i a (Bazaar (Indexed i) a b b)
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 :: ATraversal1 s t a b -> Traversal1 s t a b
cloneTraversal1 ATraversal1 s t a b
l a -> f b
f = (a -> f b) -> Bazaar1 (->) a b t -> f t
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 (Bazaar1 (->) a b t -> f t)
-> (s -> Bazaar1 (->) a b t) -> s -> f t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ATraversal1 s t a b
l a -> Bazaar1 (->) a b b
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 :: ATraversal1 s t a b -> IndexPreservingTraversal1 s t a b
cloneIndexPreservingTraversal1 ATraversal1 s t a b
l p a (f b)
pafb = (Corep p s -> f t) -> p s (f t)
forall (p :: * -> * -> *) d c.
Corepresentable p =>
(Corep p d -> c) -> p d c
cotabulate ((Corep p s -> f t) -> p s (f t))
-> (Corep p s -> f t) -> p s (f t)
forall a b. (a -> b) -> a -> b
$ \Corep p s
ws -> Bazaar1 (->) a b t
-> forall (f :: * -> *). Apply f => (a -> f b) -> f t
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 a -> Bazaar1 (->) a b b
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell (Corep p s -> s
forall (w :: * -> *) a. Comonad w => w a -> a
extract Corep p s
ws)) ((a -> f b) -> f t) -> (a -> f b) -> f t
forall a b. (a -> b) -> a -> b
$ \a
a -> p a (f b) -> Corep p a -> f b
forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
cosieve p a (f b)
pafb (a
a a -> Corep p s -> Corep p 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 :: 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 = Indexed i a (f b) -> Bazaar1 (Indexed i) a b t -> f t
forall (p :: * -> * -> *) (w :: * -> * -> * -> *) (f :: * -> *) a b
t.
(Bizarre1 p w, Apply f) =>
p a (f b) -> w a b t -> f t
bazaar1 ((i -> a -> f b) -> Indexed i a (f b)
forall i a b. (i -> a -> b) -> Indexed i a b
Indexed (p a (f b) -> i -> a -> f b
forall i (p :: * -> * -> *) a b.
Indexable i p =>
p a b -> i -> a -> b
indexed p a (f b)
f)) (Bazaar1 (Indexed i) a b t -> f t)
-> (s -> Bazaar1 (Indexed i) a b t) -> s -> f t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AnIndexedTraversal1 i s t a b
l Indexed i a (Bazaar1 (Indexed i) a b b)
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 :: (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 (Indexed i a (f b) -> s -> f t)
-> ((i -> a -> f b) -> Indexed i a (f b))
-> (i -> a -> f b)
-> s
-> f t
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible b a) =>
p b c -> q a b -> p a c
.# (i -> a -> f b) -> Indexed i a (f b)
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 :: (Indexed i a (f b) -> s -> f t) -> s -> (i -> a -> f b) -> f t
iforOf = ((i -> a -> f b) -> s -> f t) -> s -> (i -> a -> f b) -> f t
forall a b c. (a -> b -> c) -> b -> a -> c
flip (((i -> a -> f b) -> s -> f t) -> s -> (i -> a -> f b) -> f t)
-> ((Indexed i a (f b) -> s -> f t) -> (i -> a -> f b) -> s -> f t)
-> (Indexed i a (f b) -> s -> f t)
-> s
-> (i -> a -> f b)
-> f t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Indexed i a (f b) -> s -> f t) -> (i -> a -> f b) -> s -> f t
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 :: Over (Indexed i) (WrappedMonad m) s t a b
-> (i -> a -> m b) -> s -> m t
imapMOf Over (Indexed i) (WrappedMonad m) s t a b
l i -> a -> m b
cmd = WrappedMonad m t -> m t
forall (m :: * -> *) a. WrappedMonad m a -> m a
unwrapMonad (WrappedMonad m t -> m t) -> (s -> WrappedMonad m t) -> s -> m t
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. Over (Indexed i) (WrappedMonad m) s t a b
l (m b -> WrappedMonad m b
forall (m :: * -> *) a. m a -> WrappedMonad m a
WrapMonad (m b -> WrappedMonad m b)
-> Indexed i a (m b) -> Indexed i a (WrappedMonad m b)
forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. (i -> a -> m b) -> Indexed i a (m b)
forall i a b. (i -> a -> b) -> Indexed i a b
Indexed i -> a -> m b
cmd)
{-# INLINE imapMOf #-}
iforMOf :: (Indexed i a (WrappedMonad m b) -> s -> WrappedMonad m t) -> s -> (i -> a -> m b) -> m t
iforMOf :: (Indexed i a (WrappedMonad m b) -> s -> WrappedMonad m t)
-> s -> (i -> a -> m b) -> m t
iforMOf = ((i -> a -> m b) -> s -> m t) -> s -> (i -> a -> m b) -> m t
forall a b c. (a -> b -> c) -> b -> a -> c
flip (((i -> a -> m b) -> s -> m t) -> s -> (i -> a -> m b) -> m t)
-> ((Indexed i a (WrappedMonad m b) -> s -> WrappedMonad m t)
-> (i -> a -> m b) -> s -> m t)
-> (Indexed i a (WrappedMonad m b) -> s -> WrappedMonad m t)
-> s
-> (i -> a -> m b)
-> m t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Indexed i a (WrappedMonad m b) -> s -> WrappedMonad m t)
-> (i -> a -> m b) -> s -> m t
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 :: Over (Indexed i) (Backwards (State acc)) s t a b
-> (i -> acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
imapAccumROf = Over (Indexed i) (State acc) s t a b
-> (i -> acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
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
-> (i -> acc -> a -> (acc, b)) -> acc -> s -> (acc, t))
-> (Over (Indexed i) (Backwards (State acc)) s t a b
-> Over (Indexed i) (State acc) s t a b)
-> Over (Indexed i) (Backwards (State acc)) s t a b
-> (i -> acc -> a -> (acc, b))
-> acc
-> s
-> (acc, t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Over (Indexed i) (Backwards (State acc)) s t a b
-> Over (Indexed i) (State acc) s t a b
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 :: 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 = (t, acc) -> (acc, t)
forall a b. (a, b) -> (b, a)
swap (State acc t -> acc -> (t, acc)
forall s a. State s a -> s -> (a, s)
runState (Over (Indexed i) (State acc) s t a b
l ((i -> a -> StateT acc Identity b)
-> Indexed i a (StateT acc Identity b)
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 = (acc -> (b, acc)) -> StateT acc Identity b
forall (m :: * -> *) s a. Monad m => (s -> (a, s)) -> StateT s m a
state ((acc -> (b, acc)) -> StateT acc Identity b)
-> (acc -> (b, acc)) -> StateT acc Identity b
forall a b. (a -> b) -> a -> b
$ \acc
acc -> (acc, b) -> (b, 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 :: IndexedTraversal Int (f a) (f b) a b
traversed = ((p ~ (->)) => (a -> f b) -> f a -> f (f b))
-> (p a (f b) -> f a -> f (f b)) -> p a (f b) -> f a -> f (f b)
forall (p :: * -> * -> *) (q :: * -> * -> *) a b r.
Conjoined p =>
((p ~ (->)) => q (a -> b) r) -> q (p a b) r -> q (p a b) r
conjoined (p ~ (->)) => (a -> f b) -> f a -> f (f b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (((a -> Indexing f b) -> f a -> Indexing f (f b))
-> p a (f b) -> f a -> f (f b)
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 (a -> Indexing f b) -> f a -> Indexing f (f b)
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 :: (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 b -> [b] -> [b]
forall a. a -> [a] -> [a]
: Int -> [a] -> [b]
go (Int
iInt -> Int -> Int
forall 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 :: IndexedTraversal1 Int (f a) (f b) a b
traversed1 = ((p ~ (->)) => (a -> f b) -> f a -> f (f b))
-> (p a (f b) -> f a -> f (f b)) -> p a (f b) -> f a -> f (f b)
forall (p :: * -> * -> *) (q :: * -> * -> *) a b r.
Conjoined p =>
((p ~ (->)) => q (a -> b) r) -> q (p a b) r -> q (p a b) r
conjoined (p ~ (->)) => (a -> f b) -> f a -> f (f b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable1 t, Apply f) =>
(a -> f b) -> t a -> f (t b)
traverse1 (((a -> Indexing f b) -> f a -> Indexing f (f b))
-> p a (f b) -> f a -> f (f b)
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 (a -> Indexing f b) -> f a -> Indexing f (f b)
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 :: IndexedTraversal Int64 (f a) (f b) a b
traversed64 = ((p ~ (->)) => (a -> f b) -> f a -> f (f b))
-> (p a (f b) -> f a -> f (f b)) -> p a (f b) -> f a -> f (f b)
forall (p :: * -> * -> *) (q :: * -> * -> *) a b r.
Conjoined p =>
((p ~ (->)) => q (a -> b) r) -> q (p a b) r -> q (p a b) r
conjoined (p ~ (->)) => (a -> f b) -> f a -> f (f b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (((a -> Indexing64 f b) -> f a -> Indexing64 f (f b))
-> p a (f b) -> f a -> f (f b)
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 (a -> Indexing64 f b) -> f a -> Indexing64 f (f b)
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 :: pafb -> s -> f s
ignored pafb
_ = s -> f s
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 :: p v (f v) -> IntMap v -> f (IntMap v)
traverseMin p v (f v)
f IntMap v
m = case IntMap v -> Maybe ((Int, v), IntMap v)
forall a. IntMap a -> Maybe ((Int, a), IntMap a)
IntMap.minViewWithKey IntMap v
m of
Just ((Int
k,v
a), IntMap v
_) -> p v (f v) -> Int -> v -> f 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 f v -> (v -> IntMap v) -> f (IntMap v)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \v
v -> (v -> Maybe v) -> IntMap v -> IntMap v
forall a. (a -> Maybe a) -> IntMap a -> IntMap a
IntMap.updateMin (Maybe v -> v -> Maybe v
forall a b. a -> b -> a
const (v -> Maybe v
forall a. a -> Maybe a
Just v
v)) IntMap v
m
Maybe ((Int, v), IntMap v)
Nothing -> IntMap v -> f (IntMap v)
forall (f :: * -> *) a. Applicative f => a -> f a
pure IntMap v
m
{-# INLINE traverseMin #-}
instance Ord k => TraverseMin k (Map k) where
traverseMin :: p v (f v) -> Map k v -> f (Map k v)
traverseMin p v (f v)
f Map k v
m = case Map k v -> Maybe ((k, v), Map k v)
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
_) -> p v (f v) -> k -> v -> f 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 f v -> (v -> Map k v) -> f (Map k v)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \v
v -> (v -> Maybe v) -> Map k v -> Map k v
forall a k. (a -> Maybe a) -> Map k a -> Map k a
Map.updateMin (Maybe v -> v -> Maybe v
forall a b. a -> b -> a
const (v -> Maybe v
forall a. a -> Maybe a
Just v
v)) Map k v
m
Maybe ((k, v), Map k v)
Nothing -> Map k v -> f (Map k v)
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 :: p v (f v) -> IntMap v -> f (IntMap v)
traverseMax p v (f v)
f IntMap v
m = case IntMap v -> Maybe ((Int, v), IntMap v)
forall a. IntMap a -> Maybe ((Int, a), IntMap a)
IntMap.maxViewWithKey IntMap v
m of
Just ((Int
k,v
a), IntMap v
_) -> p v (f v) -> Int -> v -> f 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 f v -> (v -> IntMap v) -> f (IntMap v)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \v
v -> (v -> Maybe v) -> IntMap v -> IntMap v
forall a. (a -> Maybe a) -> IntMap a -> IntMap a
IntMap.updateMax (Maybe v -> v -> Maybe v
forall a b. a -> b -> a
const (v -> Maybe v
forall a. a -> Maybe a
Just v
v)) IntMap v
m
Maybe ((Int, v), IntMap v)
Nothing -> IntMap v -> f (IntMap v)
forall (f :: * -> *) a. Applicative f => a -> f a
pure IntMap v
m
{-# INLINE traverseMax #-}
instance Ord k => TraverseMax k (Map k) where
traverseMax :: p v (f v) -> Map k v -> f (Map k v)
traverseMax p v (f v)
f Map k v
m = case Map k v -> Maybe ((k, v), Map k v)
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
_) -> p v (f v) -> k -> v -> f 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 f v -> (v -> Map k v) -> f (Map k v)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \v
v -> (v -> Maybe v) -> Map k v -> Map k v
forall a k. (a -> Maybe a) -> Map k a -> Map k a
Map.updateMax (Maybe v -> v -> Maybe v
forall a b. a -> b -> a
const (v -> Maybe v
forall a. a -> Maybe a
Just v
v)) Map k v
m
Maybe ((k, v), Map k v)
Nothing -> Map k v -> f (Map k v)
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 :: 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 = LensLike (Indexing f) s t a a
-> (Int -> Bool) -> IndexedLensLike Int f s t a a
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 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
==)
{-# INLINE elementOf #-}
element :: Traversable t => Int -> IndexedTraversal' Int (t a) a
element :: Int -> IndexedTraversal' Int (t a) a
element Int
i = LensLike (Indexing f) (t a) (t a) a a
-> Int -> IndexedLensLike Int f (t a) (t a) a a
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) (t a) (t a) a a
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 :: 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 = (Int, f t) -> f t
forall a b. (a, b) -> b
snd ((Int, f t) -> f t) -> (Int, f t) -> f t
forall a b. (a -> b) -> a -> b
$ Indexing f t -> Int -> (Int, f t)
forall (f :: * -> *) a. Indexing f a -> Int -> (Int, f a)
runIndexing (LensLike (Indexing f) s t a a
l (\a
a -> (Int -> (Int, f a)) -> Indexing f a
forall (f :: * -> *) a. (Int -> (Int, f a)) -> Indexing f a
Indexing (\Int
i -> Int
i Int -> (Int, f a) -> (Int, f a)
`seq` (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1, if Int -> Bool
p Int
i then p a (f a) -> Int -> a -> f a
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 a -> f a
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 :: (Int -> Bool) -> IndexedTraversal' Int (t a) a
elements Int -> Bool
i = LensLike (Indexing f) (t a) (t a) a a
-> (Int -> Bool) -> IndexedLensLike Int f (t a) (t a) a a
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) (t a) (t a) a a
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 :: 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) (b -> (Any, b)) -> (a -> b) -> a -> (Any, b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
afb) s
s of
(Any Bool
True, t
t) -> t -> m t
forall (f :: * -> *) a. Applicative f => a -> f a
pure t
t
(Any Bool
False, t
_) -> m 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 :: 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) (b -> (Any, b)) -> Indexed i a b -> Indexed i a (Any, b)
forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
`rmap` (i -> a -> b) -> Indexed i a b
forall i a b. (i -> a -> b) -> Indexed i a b
Indexed i -> a -> b
iafb) s
s of
(Any Bool
True, t
t) -> t -> m t
forall (f :: * -> *) a. Applicative f => a -> f a
pure t
t
(Any Bool
False, t
_) -> m 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 :: 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 BazaarT p f a b t -> [Corep p a]
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]
_ -> p a (f b) -> BazaarT p f a b t -> f t
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 p a (BazaarT p f a b b)
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 :: 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 = Traversing p f s t a b -> Over p f s t a b -> Over p f s t a b
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 LensLike f s t s t -> Over p f s t a b -> Over p f s t a b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LensLike f s t s t -> Traversing p f s t a b -> Over p f s t a b
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 :: 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 -> Yoneda f t -> f t
forall (f :: * -> *) a. Yoneda f a -> f a
lowerYoneda (Yoneda f t -> f t) -> (s -> Yoneda f t) -> s -> f t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Curried (Yoneda f) (Yoneda f) t -> Yoneda f t
forall (f :: * -> *) (g :: * -> *) a.
Applicative f =>
Curried f g a -> g a
lowerCurried (Curried (Yoneda f) (Yoneda f) t -> Yoneda f t)
-> (s -> Curried (Yoneda f) (Yoneda f) t) -> s -> Yoneda f t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LensLike (Curried (Yoneda f) (Yoneda f)) s t a b
t (f b -> Curried (Yoneda f) (Yoneda f) b
forall (f :: * -> *) a.
Applicative f =>
f a -> Curried (Yoneda f) (Yoneda f) a
liftCurriedYoneda (f b -> Curried (Yoneda f) (Yoneda f) b)
-> (a -> f b) -> a -> Curried (Yoneda f) (Yoneda f) b
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 :: f a -> Curried (Yoneda f) (Yoneda f) a
liftCurriedYoneda f a
fa = (forall r. Yoneda f (a -> r) -> Yoneda f r)
-> Curried (Yoneda f) (Yoneda f) a
forall (g :: * -> *) (h :: * -> *) a.
(forall r. g (a -> r) -> h r) -> Curried g h a
Curried (Yoneda f (a -> r) -> f a -> Yoneda f r
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 :: Yoneda f (a -> b) -> f a -> Yoneda f b
yap (Yoneda forall b. ((a -> b) -> b) -> f b
k) f a
fa = (forall b. (b -> b) -> f b) -> Yoneda f b
forall (f :: * -> *) a. (forall b. (a -> b) -> f b) -> Yoneda f a
Yoneda (\b -> b
ab_r -> ((a -> b) -> a -> b) -> f (a -> b)
forall b. ((a -> b) -> b) -> f b
k (b -> b
ab_r (b -> b) -> (a -> b) -> a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
.) f (a -> b) -> f a -> f b
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 :: 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 x. x -> f x)
-> (forall x y. f (x -> y) -> f x -> f y)
-> (forall s.
Reifies s (ReifiedApplicative f) =>
s -> ReflectedApplicative f s t)
-> s
-> f t
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 ((a -> ReflectedApplicative f s b)
-> s -> ReflectedApplicative f s t
Traversal s t a b
l (f b -> ReflectedApplicative f s b
forall k k1 (f :: k -> *) (s :: k1) (a :: k).
f a -> ReflectedApplicative f s a
ReflectedApplicative (f b -> ReflectedApplicative f s b)
-> (a -> f b) -> a -> ReflectedApplicative f s b
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 :: 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 x. x -> f x)
-> (forall x y. f (x -> y) -> f x -> f y)
-> (forall s.
Reifies s (ReifiedApplicative f) =>
s -> ReflectedApplicative f s t)
-> s
-> f t
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 ((f b -> ReflectedApplicative f s b)
-> s -> ReflectedApplicative f s t
Traversal s t (f b) b
l f b -> ReflectedApplicative f s b
forall k k1 (f :: k -> *) (s :: k1) (a :: k).
f a -> ReflectedApplicative f s a
ReflectedApplicative)