packages feed

lens 3.7.6 → 3.8

raw patch · 112 files changed

+14454/−8010 lines, 112 filesdep +MonadCatchIO-transformersdep +base-orphansdep +bifunctorsdep ~basedep ~comonaddep ~comonads-fdPVP ok

version bump matches the API change (PVP)

Dependencies added: MonadCatchIO-transformers, base-orphans, bifunctors, contravariant, distributive, profunctor-extras, profunctors, semigroupoids, tagged

Dependency ranges changed: base, comonad, comonads-fd, containers, generic-deriving, nats, semigroups, template-haskell, transformers, transformers-compat

API changes (from Hackage documentation)

- Control.Lens.Classes: class (Monad m, Gettable f) => Effective m r f | f -> m r
- Control.Lens.Classes: class Functor f => Gettable f
- Control.Lens.Classes: class Indexable i k
- Control.Lens.Classes: class Category k => Isomorphic k
- Control.Lens.Classes: class Isomorphic k => Prismatic k
- Control.Lens.Classes: class Applicative f => Settable f where untainted# g = g `seq` \ x -> untainted (g x) tainted# g = g `seq` \ x -> pure (g x)
- Control.Lens.Classes: coerce :: Gettable f => f a -> f b
- Control.Lens.Classes: effective :: Effective m r f => m r -> f a
- Control.Lens.Classes: indexed :: Indexable i k => ((i -> a) -> b) -> k a b
- Control.Lens.Classes: ineffective :: Effective m r f => f a -> m r
- Control.Lens.Classes: instance (Functor f, Gettable g) => Gettable (Compose f g)
- Control.Lens.Classes: instance (Settable f, Settable g) => Settable (Compose f g)
- Control.Lens.Classes: instance Effective m r f => Effective m (Dual r) (Backwards f)
- Control.Lens.Classes: instance Gettable (Const r)
- Control.Lens.Classes: instance Gettable f => Gettable (Backwards f)
- Control.Lens.Classes: instance Indexable i (->)
- Control.Lens.Classes: instance Isomorphic (->)
- Control.Lens.Classes: instance Prismatic (->)
- Control.Lens.Classes: instance Settable Identity
- Control.Lens.Classes: instance Settable f => Settable (Backwards f)
- Control.Lens.Classes: iso :: (Isomorphic k, Functor f) => (s -> a) -> (b -> t) -> k (a -> f b) (s -> f t)
- Control.Lens.Classes: noEffect :: (Applicative f, Gettable f) => f a
- Control.Lens.Classes: prism :: (Prismatic k, Applicative f) => (b -> t) -> (s -> Either t a) -> k (a -> f b) (s -> f t)
- Control.Lens.Classes: tainted# :: Settable f => (a -> b) -> a -> f b
- Control.Lens.Classes: untainted :: Settable f => f a -> a
- Control.Lens.Classes: untainted# :: Settable f => (a -> f b) -> a -> b
- Control.Lens.Combinators: (<$!) :: Monad m => b -> m a -> m b
- Control.Lens.Combinators: (<$!>) :: Monad m => (a -> b) -> m a -> m b
- Control.Lens.Each: instance (Ix i, IArray UArray a, IArray UArray b) => Each i (Array i a) (Array i b) a b
- Control.Lens.Each: instance (Ix i, IArray UArray a, IArray UArray b) => Each i (UArray i a) (UArray i b) a b
- Control.Lens.Each: instance (Prim a, Prim b) => Each Int (Vector a) (Vector b) a b
- Control.Lens.Each: instance (Storable a, Storable b) => Each Int (Vector a) (Vector b) a b
- Control.Lens.Each: instance (Unbox a, Unbox b) => Each Int (Vector a) (Vector b) a b
- Control.Lens.Each: instance (a ~ a', b ~ b') => Each Int (a, a') (b, b') a b
- Control.Lens.Each: instance (a ~ a2, a ~ a3, a ~ a4, a ~ a5, a ~ a6, a ~ a7, a ~ a8, a ~ a9, b ~ b2, b ~ b3, b ~ b4, b ~ b5, b ~ b6, b ~ b7, b ~ b8, b ~ b9) => Each Int (a, a2, a3, a4, a5, a6, a7, a8, a9) (b, b2, b3, b4, b5, b6, b7, b8, b9) a b
- Control.Lens.Each: instance (a ~ a2, a ~ a3, a ~ a4, a ~ a5, a ~ a6, a ~ a7, a ~ a8, b ~ b2, b ~ b3, b ~ b4, b ~ b5, b ~ b6, b ~ b7, b ~ b8) => Each Int (a, a2, a3, a4, a5, a6, a7, a8) (b, b2, b3, b4, b5, b6, b7, b8) a b
- Control.Lens.Each: instance (a ~ a2, a ~ a3, a ~ a4, a ~ a5, a ~ a6, a ~ a7, b ~ b2, b ~ b3, b ~ b4, b ~ b5, b ~ b6, b ~ b7) => Each Int (a, a2, a3, a4, a5, a6, a7) (b, b2, b3, b4, b5, b6, b7) a b
- Control.Lens.Each: instance (a ~ a2, a ~ a3, a ~ a4, a ~ a5, a ~ a6, b ~ b2, b ~ b3, b ~ b4, b ~ b5, b ~ b6) => Each Int (a, a2, a3, a4, a5, a6) (b, b2, b3, b4, b5, b6) a b
- Control.Lens.Each: instance (a ~ a2, a ~ a3, a ~ a4, a ~ a5, b ~ b2, b ~ b3, b ~ b4, b ~ b5) => Each Int (a, a2, a3, a4, a5) (b, b2, b3, b4, b5) a b
- Control.Lens.Each: instance (a ~ a2, a ~ a3, a ~ a4, b ~ b2, b ~ b3, b ~ b4) => Each Int (a, a2, a3, a4) (b, b2, b3, b4) a b
- Control.Lens.Each: instance (a ~ a2, a ~ a3, b ~ b2, b ~ b3) => Each Int (a, a2, a3) (b, b2, b3) a b
- Control.Lens.Each: instance Each Int (Complex a) (Complex b) a b
- Control.Lens.Each: instance Each Int (Identity a) (Identity b) a b
- Control.Lens.Each: instance Each Int (IntMap a) (IntMap b) a b
- Control.Lens.Each: instance Each Int (Maybe a) (Maybe b) a b
- Control.Lens.Each: instance Each Int (Seq a) (Seq b) a b
- Control.Lens.Each: instance Each Int (Tree a) (Tree b) a b
- Control.Lens.Each: instance Each Int (Vector a) (Vector b) a b
- Control.Lens.Each: instance Each Int ByteString ByteString Word8 Word8
- Control.Lens.Each: instance Each Int Text Text Char Char
- Control.Lens.Each: instance Each Int [a] [b] a b
- Control.Lens.Each: instance Each Int64 ByteString ByteString Word8 Word8
- Control.Lens.Each: instance Each Int64 Text Text Char Char
- Control.Lens.Each: instance Each k (HashMap k a) (HashMap k b) a b
- Control.Lens.Each: instance Each k (Map k a) (Map k b) a b
- Control.Lens.Fold: ReifyFold :: Fold s a -> ReifiedFold s a
- Control.Lens.Fold: newtype ReifiedFold s a
- Control.Lens.Fold: reflectFold :: ReifiedFold s a -> Fold s a
- Control.Lens.Getter: (&) :: a -> (a -> b) -> b
- Control.Lens.Getter: (^$) :: Getting a s t a b -> s -> a
- Control.Lens.Getter: (^&) :: a -> (a -> b) -> b
- Control.Lens.Getter: ReifyGetter :: Getter s a -> ReifiedGetter s a
- Control.Lens.Getter: data Accessor r a
- Control.Lens.Getter: newtype ReifiedGetter s a
- Control.Lens.Getter: reflectGetter :: ReifiedGetter s a -> Getter s a
- Control.Lens.IndexedFold: ReifyIndexedFold :: IndexedFold i s a -> ReifiedIndexedFold i s a
- Control.Lens.IndexedFold: iallOf :: IndexedGetting i All s t a b -> (i -> a -> Bool) -> s -> Bool
- Control.Lens.IndexedFold: ianyOf :: IndexedGetting i Any s t a b -> (i -> a -> Bool) -> s -> Bool
- Control.Lens.IndexedFold: ibackwards :: Indexable i k => Indexed i (a -> (Backwards f) b) (s -> (Backwards f) t) -> k (a -> f b) (s -> f t)
- Control.Lens.IndexedFold: iconcatMapOf :: IndexedGetting i [r] s t a b -> (i -> a -> [r]) -> s -> [r]
- Control.Lens.IndexedFold: idroppingWhile :: (Gettable f, Applicative f, Indexable i k) => (i -> a -> Bool) -> IndexedGetting i (Endo (f s, f s)) s s a a -> k (a -> f a) (s -> f s)
- Control.Lens.IndexedFold: ifiltering :: (Applicative f, Indexable i k) => (i -> a -> Bool) -> Indexed i (a -> f a) (s -> f t) -> k (a -> f a) (s -> f t)
- Control.Lens.IndexedFold: ifindOf :: IndexedGetting i (First (i, a)) s t a b -> (i -> a -> Bool) -> s -> Maybe (i, a)
- Control.Lens.IndexedFold: ifoldMapOf :: IndexedGetting i m s t a b -> (i -> a -> m) -> s -> m
- Control.Lens.IndexedFold: ifoldlMOf :: Monad m => IndexedGetting i (Endo (r -> m r)) s t a b -> (i -> r -> a -> m r) -> r -> s -> m r
- Control.Lens.IndexedFold: ifoldlOf :: IndexedGetting i (Dual (Endo r)) s t a b -> (i -> r -> a -> r) -> r -> s -> r
- Control.Lens.IndexedFold: ifoldlOf' :: IndexedGetting i (Endo (r -> r)) s t a b -> (i -> r -> a -> r) -> r -> s -> r
- Control.Lens.IndexedFold: ifoldrMOf :: Monad m => IndexedGetting i (Dual (Endo (r -> m r))) s t a b -> (i -> a -> r -> m r) -> r -> s -> m r
- Control.Lens.IndexedFold: ifoldrOf :: IndexedGetting i (Endo r) s t a b -> (i -> a -> r -> r) -> r -> s -> r
- Control.Lens.IndexedFold: ifoldrOf' :: IndexedGetting i (Dual (Endo (r -> r))) s t a b -> (i -> a -> r -> r) -> r -> s -> r
- Control.Lens.IndexedFold: iforMOf_ :: Monad m => IndexedGetting i (Sequenced m) s t a b -> s -> (i -> a -> m r) -> m ()
- Control.Lens.IndexedFold: iforOf_ :: Functor f => IndexedGetting i (Traversed f) s t a b -> s -> (i -> a -> f r) -> f ()
- Control.Lens.IndexedFold: imapMOf_ :: Monad m => IndexedGetting i (Sequenced m) s t a b -> (i -> a -> m r) -> s -> m ()
- Control.Lens.IndexedFold: indicesOf :: Gettable f => Overloaded (Indexed i) f s t a a -> LensLike f s t i j
- Control.Lens.IndexedFold: itakingWhile :: (Gettable f, Applicative f, Indexable i k) => (i -> a -> Bool) -> IndexedGetting i (Endo (f s)) s s a a -> k (a -> f a) (s -> f s)
- Control.Lens.IndexedFold: itoListOf :: IndexedGetting i (Endo [(i, a)]) s t a b -> s -> [(i, a)]
- Control.Lens.IndexedFold: itraverseOf_ :: Functor f => IndexedGetting i (Traversed f) s t a b -> (i -> a -> f r) -> s -> f ()
- Control.Lens.IndexedFold: newtype ReifiedIndexedFold i s a
- Control.Lens.IndexedFold: reflectIndexedFold :: ReifiedIndexedFold i s a -> IndexedFold i s a
- Control.Lens.IndexedFold: type IndexedFold i s a = forall k f. (Indexable i k, Applicative f, Gettable f) => k (a -> f a) (s -> f s)
- Control.Lens.IndexedFold: withIndicesOf :: Functor f => Overloaded (Indexed i) f s t a b -> LensLike f s t (i, a) (j, b)
- Control.Lens.IndexedGetter: ReifyIndexedGetter :: IndexedGetter i s a -> ReifiedIndexedGetter i s a
- Control.Lens.IndexedGetter: iuse :: MonadState s m => IndexedGetting i (i, a) s t a b -> m (i, a)
- Control.Lens.IndexedGetter: iuses :: MonadState s m => IndexedGetting i r s t a b -> (i -> a -> r) -> m r
- Control.Lens.IndexedGetter: iview :: MonadReader s m => IndexedGetting i (i, a) s t a b -> m (i, a)
- Control.Lens.IndexedGetter: iviews :: MonadReader s m => IndexedGetting i r s t a b -> (i -> a -> r) -> m r
- Control.Lens.IndexedGetter: newtype ReifiedIndexedGetter i s a
- Control.Lens.IndexedGetter: reflectIndexedGetter :: ReifiedIndexedGetter i s a -> IndexedGetter i s a
- Control.Lens.IndexedGetter: type IndexedGetting i m s t a b = Indexed i (a -> Accessor m b) (s -> Accessor m t)
- Control.Lens.IndexedGetter: type IndexedGetter i s a = forall k f. (Indexable i k, Gettable f) => k (a -> f a) (s -> f s)
- Control.Lens.IndexedLens: (%%@=) :: MonadState s m => Overloaded (Indexed i) ((,) r) s s a b -> (i -> a -> (r, b)) -> m r
- Control.Lens.IndexedLens: (%%@~) :: Overloaded (Indexed i) f s t a b -> (i -> a -> f b) -> s -> f t
- Control.Lens.IndexedLens: (<%@=) :: MonadState s m => Overloaded (Indexed i) ((,) b) s s a b -> (i -> a -> b) -> m b
- Control.Lens.IndexedLens: (<%@~) :: Overloaded (Indexed i) ((,) b) s t a b -> (i -> a -> b) -> s -> (b, t)
- Control.Lens.IndexedLens: ReifyIndexedLens :: IndexedLens i s t a b -> ReifiedIndexedLens i s t a b
- Control.Lens.IndexedLens: class Contains k m | m -> k
- Control.Lens.IndexedLens: contains :: Contains k m => k -> SimpleIndexedLens k m Bool
- Control.Lens.IndexedLens: instance (Eq k, Hashable k) => Contains k (HashSet k)
- Control.Lens.IndexedLens: instance Contains Int IntSet
- Control.Lens.IndexedLens: instance Ord k => Contains k (Set k)
- Control.Lens.IndexedLens: newtype ReifiedIndexedLens i s t a b
- Control.Lens.IndexedLens: reflectIndexedLens :: ReifiedIndexedLens i s t a b -> IndexedLens i s t a b
- Control.Lens.IndexedLens: resultAt :: Eq e => e -> SimpleIndexedLens e (e -> a) a
- Control.Lens.IndexedLens: type SimpleIndexedLens i s a = IndexedLens i s s a a
- Control.Lens.IndexedLens: type SimpleReifiedIndexedLens i s a = ReifiedIndexedLens i s s a a
- Control.Lens.IndexedLens: type IndexedLens i s t a b = forall f k. (Indexable i k, Functor f) => k (a -> f b) (s -> f t)
- Control.Lens.IndexedSetter: (%@=) :: MonadState s m => Overloaded (Indexed i) Mutator s s a b -> (i -> a -> b) -> m ()
- Control.Lens.IndexedSetter: (%@~) :: Overloaded (Indexed i) Mutator s t a b -> (i -> a -> b) -> s -> t
- Control.Lens.IndexedSetter: ReifyIndexedSetter :: IndexedSetter i s t a b -> ReifiedIndexedSetter i s t a b
- Control.Lens.IndexedSetter: imapOf :: Overloaded (Indexed i) Mutator s t a b -> (i -> a -> b) -> s -> t
- Control.Lens.IndexedSetter: iover :: Overloaded (Indexed i) Mutator s t a b -> (i -> a -> b) -> s -> t
- Control.Lens.IndexedSetter: isets :: ((i -> a -> b) -> s -> t) -> IndexedSetter i s t a b
- Control.Lens.IndexedSetter: newtype ReifiedIndexedSetter i s t a b
- Control.Lens.IndexedSetter: reflectIndexedSetter :: ReifiedIndexedSetter i s t a b -> IndexedSetter i s t a b
- Control.Lens.IndexedSetter: type SimpleIndexedSetter i s a = IndexedSetter i s s a a
- Control.Lens.IndexedSetter: type SimpleReifiedIndexedSetter i s a = ReifiedIndexedSetter i s s a a
- Control.Lens.IndexedSetter: type IndexedSetter i s t a b = forall f k. (Indexable i k, Settable f) => k (a -> f b) (s -> f t)
- Control.Lens.IndexedTraversal: ReifyIndexedTraversal :: IndexedTraversal i s t a b -> ReifiedIndexedTraversal i s t a b
- Control.Lens.IndexedTraversal: _at :: At k m => k -> SimpleIndexedTraversal k (m v) v
- Control.Lens.IndexedTraversal: at :: At k m => k -> SimpleIndexedLens k (m v) (Maybe v)
- Control.Lens.IndexedTraversal: class At k m | m -> k where _at k = at k <. traverse
- Control.Lens.IndexedTraversal: class Ord k => TraverseMax k m | m -> k
- Control.Lens.IndexedTraversal: class Ord k => TraverseMin k m | m -> k
- Control.Lens.IndexedTraversal: element :: Traversable t => Int -> SimpleIndexedTraversal Int (t a) a
- Control.Lens.IndexedTraversal: elementOf :: (Applicative f, Indexable Int k) => LensLike (Indexing f) s t a a -> Int -> Overloaded k f s t a a
- Control.Lens.IndexedTraversal: elements :: Traversable t => (Int -> Bool) -> SimpleIndexedTraversal Int (t a) a
- Control.Lens.IndexedTraversal: elementsOf :: (Applicative f, Indexable Int k) => LensLike (Indexing f) s t a a -> (Int -> Bool) -> Overloaded k f s t a a
- Control.Lens.IndexedTraversal: iforMOf :: Overloaded (Indexed i) (WrappedMonad m) s t a b -> s -> (i -> a -> m b) -> m t
- Control.Lens.IndexedTraversal: iforOf :: Overloaded (Indexed i) f s t a b -> s -> (i -> a -> f b) -> f t
- Control.Lens.IndexedTraversal: ignored :: (Indexable i k, Applicative f) => Overloaded k f s s a b
- Control.Lens.IndexedTraversal: imapAccumLOf :: Overloaded (Indexed i) (Backwards (State s)) s t a b -> (i -> s -> a -> (s, b)) -> s -> s -> (s, t)
- Control.Lens.IndexedTraversal: imapAccumROf :: Overloaded (Indexed i) (State s) s t a b -> (i -> s -> a -> (s, b)) -> s -> s -> (s, t)
- Control.Lens.IndexedTraversal: imapMOf :: Overloaded (Indexed i) (WrappedMonad m) s t a b -> (i -> a -> m b) -> s -> m t
- Control.Lens.IndexedTraversal: instance (Eq k, Hashable k) => At k (HashMap k)
- Control.Lens.IndexedTraversal: instance At Int IntMap
- Control.Lens.IndexedTraversal: instance Ord k => At k (Map k)
- Control.Lens.IndexedTraversal: instance Ord k => TraverseMax k (Map k)
- Control.Lens.IndexedTraversal: instance Ord k => TraverseMin k (Map k)
- Control.Lens.IndexedTraversal: instance TraverseMax Int IntMap
- Control.Lens.IndexedTraversal: instance TraverseMin Int IntMap
- Control.Lens.IndexedTraversal: itraverseOf :: Overloaded (Indexed i) f s t a b -> (i -> a -> f b) -> s -> f t
- Control.Lens.IndexedTraversal: iwhereOf :: (Indexable i k, Applicative f) => Overloaded (Indexed i) f s t a a -> (i -> Bool) -> Overloaded k f s t a a
- Control.Lens.IndexedTraversal: newtype ReifiedIndexedTraversal i s t a b
- Control.Lens.IndexedTraversal: reflectIndexedTraversal :: ReifiedIndexedTraversal i s t a b -> IndexedTraversal i s t a b
- Control.Lens.IndexedTraversal: traverseMax :: TraverseMax k m => SimpleIndexedTraversal k (m v) v
- Control.Lens.IndexedTraversal: traverseMin :: TraverseMin k m => SimpleIndexedTraversal k (m v) v
- Control.Lens.IndexedTraversal: traversed :: Traversable f => IndexedTraversal Int (f a) (f b) a b
- Control.Lens.IndexedTraversal: traversed64 :: Traversable f => IndexedTraversal Int64 (f a) (f b) a b
- Control.Lens.IndexedTraversal: type SimpleIndexedTraversal i s a = IndexedTraversal i s s a a
- Control.Lens.IndexedTraversal: type SimpleReifiedIndexedTraversal i s a = ReifiedIndexedTraversal i s s a a
- Control.Lens.IndexedTraversal: type IndexedTraversal i s t a b = forall f k. (Indexable i k, Applicative f) => k (a -> f b) (s -> f t)
- Control.Lens.IndexedTraversal: value :: (k -> Bool) -> SimpleIndexedTraversal k (k, v) v
- Control.Lens.Internal: Accessor :: r -> Accessor r a
- Control.Lens.Internal: Bazaar :: (forall f. Applicative f => (a -> f b) -> f t) -> Bazaar a b t
- Control.Lens.Internal: BazaarT :: (forall f. Applicative f => (a -> f b) -> f t) -> BazaarT a b t
- Control.Lens.Internal: Context :: (b -> t) -> a -> Context a b t
- Control.Lens.Internal: Effect :: m r -> Effect m r a
- Control.Lens.Internal: EffectRWS :: (st -> m (s, st, w)) -> EffectRWS w st m s a
- Control.Lens.Internal: Err :: Either e a -> Err e a
- Control.Lens.Internal: Focusing :: m (s, a) -> Focusing m s a
- Control.Lens.Internal: FocusingErr :: k (Err e s) a -> FocusingErr e k s a
- Control.Lens.Internal: FocusingMay :: k (May s) a -> FocusingMay k s a
- Control.Lens.Internal: FocusingOn :: k (f s) a -> FocusingOn f k s a
- Control.Lens.Internal: FocusingPlus :: k (s, w) a -> FocusingPlus w k s a
- Control.Lens.Internal: FocusingWith :: m (s, a, w) -> FocusingWith w m s a
- Control.Lens.Internal: Folding :: f a -> Folding f a
- Control.Lens.Internal: Indexed :: ((i -> a) -> b) -> Indexed i a b
- Control.Lens.Internal: Indexing :: (Int -> (f a, Int)) -> Indexing f a
- Control.Lens.Internal: Indexing64 :: (Int64 -> (f a, Int64)) -> Indexing64 f a
- Control.Lens.Internal: Iso :: (CoA y -> CoA x) -> (CoB x -> CoB y) -> Isoid x y
- Control.Lens.Internal: Isoid :: Isoid ab ab
- Control.Lens.Internal: Max :: a -> Max a
- Control.Lens.Internal: May :: Maybe a -> May a
- Control.Lens.Internal: Min :: a -> Min a
- Control.Lens.Internal: Mutator :: a -> Mutator a
- Control.Lens.Internal: NoMax :: Max a
- Control.Lens.Internal: NoMin :: Min a
- Control.Lens.Internal: Prism :: (CoB x -> CoB y) -> (CoA y -> Either (CoB y) (CoA x)) -> Prismoid x y
- Control.Lens.Internal: Prismoid :: Prismoid x x
- Control.Lens.Internal: Sequenced :: m () -> Sequenced m
- Control.Lens.Internal: Traversed :: f () -> Traversed f
- Control.Lens.Internal: bazaar :: Applicative f => (a -> f b) -> Bazaar a b t -> f t
- Control.Lens.Internal: bazaarT :: Applicative f => (a -> f b) -> BazaarT a b g t -> f t
- Control.Lens.Internal: data Context a b t
- Control.Lens.Internal: data Isoid ab st
- Control.Lens.Internal: data Max a
- Control.Lens.Internal: data Min a
- Control.Lens.Internal: data Prismoid ab st
- Control.Lens.Internal: duplicateBazaar :: Bazaar a c t -> Bazaar a b (Bazaar b c t)
- Control.Lens.Internal: duplicateBazaarT :: BazaarT a c f t -> BazaarT a b f (BazaarT b c f t)
- Control.Lens.Internal: getEffect :: Effect m r a -> m r
- Control.Lens.Internal: getEffectRWS :: EffectRWS w st m s a -> st -> m (s, st, w)
- Control.Lens.Internal: getErr :: Err e a -> Either e a
- Control.Lens.Internal: getFolding :: Folding f a -> f a
- Control.Lens.Internal: getMax :: Max a -> Maybe a
- Control.Lens.Internal: getMay :: May a -> Maybe a
- Control.Lens.Internal: getMin :: Min a -> Maybe a
- Control.Lens.Internal: getSequenced :: Sequenced m -> m ()
- Control.Lens.Internal: getTraversed :: Traversed f -> f ()
- Control.Lens.Internal: instance (Gettable f, Applicative f) => Monoid (Folding f a)
- Control.Lens.Internal: instance (Monad m, Monoid r) => Applicative (Effect m r)
- Control.Lens.Internal: instance (Monad m, Monoid r) => Monoid (Effect m r a)
- Control.Lens.Internal: instance (Monad m, Monoid s) => Applicative (Focusing m s)
- Control.Lens.Internal: instance (Monad m, Monoid s, Monoid w) => Applicative (FocusingWith w m s)
- Control.Lens.Internal: instance (Monoid s, Monoid w, Monad m) => Applicative (EffectRWS w st m s)
- Control.Lens.Internal: instance (Monoid w, Applicative (k (s, w))) => Applicative (FocusingPlus w k s)
- Control.Lens.Internal: instance Applicative (Bazaar a b)
- Control.Lens.Internal: instance Applicative (BazaarT a b g)
- Control.Lens.Internal: instance Applicative (k (Err e s)) => Applicative (FocusingErr e k s)
- Control.Lens.Internal: instance Applicative (k (May s)) => Applicative (FocusingMay k s)
- Control.Lens.Internal: instance Applicative (k (f s)) => Applicative (FocusingOn f k s)
- Control.Lens.Internal: instance Applicative Mutator
- Control.Lens.Internal: instance Applicative f => Applicative (Indexing f)
- Control.Lens.Internal: instance Applicative f => Applicative (Indexing64 f)
- Control.Lens.Internal: instance Applicative f => Monoid (Traversed f)
- Control.Lens.Internal: instance Category Isoid
- Control.Lens.Internal: instance Category Prismoid
- Control.Lens.Internal: instance Effective Identity r (Accessor r)
- Control.Lens.Internal: instance Functor (Accessor r)
- Control.Lens.Internal: instance Functor (Bazaar a b)
- Control.Lens.Internal: instance Functor (BazaarT a b g)
- Control.Lens.Internal: instance Functor (Context a b)
- Control.Lens.Internal: instance Functor (Effect m r)
- Control.Lens.Internal: instance Functor (EffectRWS w st m s)
- Control.Lens.Internal: instance Functor (k (Err e s)) => Functor (FocusingErr e k s)
- Control.Lens.Internal: instance Functor (k (May s)) => Functor (FocusingMay k s)
- Control.Lens.Internal: instance Functor (k (f s)) => Functor (FocusingOn f k s)
- Control.Lens.Internal: instance Functor (k (s, w)) => Functor (FocusingPlus w k s)
- Control.Lens.Internal: instance Functor Mutator
- Control.Lens.Internal: instance Functor f => Functor (Indexing f)
- Control.Lens.Internal: instance Functor f => Functor (Indexing64 f)
- Control.Lens.Internal: instance Gettable (Accessor r)
- Control.Lens.Internal: instance Gettable (Effect m r)
- Control.Lens.Internal: instance Gettable (EffectRWS w st m s)
- Control.Lens.Internal: instance Gettable f => Gettable (Indexing f)
- Control.Lens.Internal: instance Gettable f => Gettable (Indexing64 f)
- Control.Lens.Internal: instance Gettable g => Gettable (BazaarT a b g)
- Control.Lens.Internal: instance Isomorphic Isoid
- Control.Lens.Internal: instance Isomorphic Prismoid
- Control.Lens.Internal: instance Monad m => Effective m r (Effect m r)
- Control.Lens.Internal: instance Monad m => Functor (Focusing m s)
- Control.Lens.Internal: instance Monad m => Functor (FocusingWith w m s)
- Control.Lens.Internal: instance Monad m => Monoid (Sequenced m)
- Control.Lens.Internal: instance Monoid a => Monoid (Err e a)
- Control.Lens.Internal: instance Monoid a => Monoid (May a)
- Control.Lens.Internal: instance Monoid r => Applicative (Accessor r)
- Control.Lens.Internal: instance Ord a => Monoid (Max a)
- Control.Lens.Internal: instance Ord a => Monoid (Min a)
- Control.Lens.Internal: instance Prismatic Prismoid
- Control.Lens.Internal: instance Settable Mutator
- Control.Lens.Internal: instance a ~ b => Comonad (Bazaar a b)
- Control.Lens.Internal: instance a ~ b => Comonad (BazaarT a b g)
- Control.Lens.Internal: instance a ~ b => Comonad (Context a b)
- Control.Lens.Internal: instance a ~ b => ComonadApply (Bazaar a b)
- Control.Lens.Internal: instance a ~ b => ComonadStore a (Context a b)
- Control.Lens.Internal: instance i ~ j => Indexable i (Indexed j)
- Control.Lens.Internal: newtype Accessor r a
- Control.Lens.Internal: newtype Bazaar a b t
- Control.Lens.Internal: newtype BazaarT a b (g :: * -> *) t
- Control.Lens.Internal: newtype Effect m r a
- Control.Lens.Internal: newtype EffectRWS w st m s a
- Control.Lens.Internal: newtype Err e a
- Control.Lens.Internal: newtype Focusing m s a
- Control.Lens.Internal: newtype FocusingErr e k s a
- Control.Lens.Internal: newtype FocusingMay k s a
- Control.Lens.Internal: newtype FocusingOn f k s a
- Control.Lens.Internal: newtype FocusingPlus w k s a
- Control.Lens.Internal: newtype FocusingWith w m s a
- Control.Lens.Internal: newtype Folding f a
- Control.Lens.Internal: newtype Indexed i a b
- Control.Lens.Internal: newtype Indexing f a
- Control.Lens.Internal: newtype Indexing64 f a
- Control.Lens.Internal: newtype May a
- Control.Lens.Internal: newtype Mutator a
- Control.Lens.Internal: newtype Sequenced m
- Control.Lens.Internal: newtype Traversed f
- Control.Lens.Internal: runAccessor :: Accessor r a -> r
- Control.Lens.Internal: runBazaar :: Bazaar a b t -> forall f. Applicative f => (a -> f b) -> f t
- Control.Lens.Internal: runBazaarT :: BazaarT a b t -> forall f. Applicative f => (a -> f b) -> f t
- Control.Lens.Internal: runIndexing :: Indexing f a -> Int -> (f a, Int)
- Control.Lens.Internal: runIndexing64 :: Indexing64 f a -> Int64 -> (f a, Int64)
- Control.Lens.Internal: runMutator :: Mutator a -> a
- Control.Lens.Internal: sell :: a -> Bazaar a b b
- Control.Lens.Internal: sellT :: a -> BazaarT a b f b
- Control.Lens.Internal: unfocusing :: Focusing m s a -> m (s, a)
- Control.Lens.Internal: unfocusingErr :: FocusingErr e k s a -> k (Err e s) a
- Control.Lens.Internal: unfocusingMay :: FocusingMay k s a -> k (May s) a
- Control.Lens.Internal: unfocusingOn :: FocusingOn f k s a -> k (f s) a
- Control.Lens.Internal: unfocusingPlus :: FocusingPlus w k s a -> k (s, w) a
- Control.Lens.Internal: unfocusingWith :: FocusingWith w m s a -> m (s, a, w)
- Control.Lens.Internal: withIndex :: Indexed i a b -> (i -> a) -> b
- Control.Lens.Internal.Zipper: instance Zipping h s => Zipping (h :> s) a
- Control.Lens.Internal.Zipper: reverseList :: [a] -> [a]
- Control.Lens.Internal.Zipper: type Zipper = :>
- Control.Lens.Iso: Iso :: (CoA y -> CoA x) -> (CoB x -> CoB y) -> Isoid x y
- Control.Lens.Iso: Isoid :: Isoid ab ab
- Control.Lens.Iso: class Category k => Isomorphic k
- Control.Lens.Iso: data Isoid ab st
- Control.Lens.Iso: instance Strict ByteString ByteString ByteString ByteString
- Control.Lens.Iso: instance Strict Text Text Text Text
- Control.Lens.Iso: type SimpleIso s a = Iso s s a a
- Control.Lens.Iso: type Iso s t a b = forall k f. (Isomorphic k, Functor f) => k (a -> f b) (s -> f t)
- Control.Lens.Prism: Prism :: (CoB x -> CoB y) -> (CoA y -> Either (CoB y) (CoA x)) -> Prismoid x y
- Control.Lens.Prism: Prismoid :: Prismoid x x
- Control.Lens.Prism: _just :: Prism (Maybe a) (Maybe b) a b
- Control.Lens.Prism: _left :: Prism (Either a c) (Either b c) a b
- Control.Lens.Prism: _right :: Prism (Either c a) (Either c b) a b
- Control.Lens.Prism: class Isomorphic k => Prismatic k
- Control.Lens.Prism: data Prismoid ab st
- Control.Lens.Prism: remit :: APrism s t a b -> Getter b t
- Control.Lens.Prism: reuse :: MonadState b m => APrism s t a b -> m t
- Control.Lens.Prism: reuses :: MonadState b m => APrism s t a b -> (t -> r) -> m r
- Control.Lens.Prism: review :: MonadReader b m => APrism s t a b -> m t
- Control.Lens.Prism: reviews :: MonadReader b m => APrism s t a b -> (t -> r) -> m r
- Control.Lens.Prism: type SimplePrism s a = Prism s s a a
- Control.Lens.Prism: type Prism s t a b = forall k f. (Prismatic k, Applicative f) => k (a -> f b) (s -> f t)
- Control.Lens.Representable: Path :: Rep f -> Path f
- Control.Lens.Representable: apRep :: Representable f => f (a -> b) -> f a -> f b
- Control.Lens.Representable: bindRep :: Representable f => f a -> (a -> f b) -> f b
- Control.Lens.Representable: class Functor f => Representable f
- Control.Lens.Representable: distributeRep :: (Representable f, Functor w) => w (f a) -> f (w a)
- Control.Lens.Representable: fmapRep :: Representable f => (a -> b) -> f a -> f b
- Control.Lens.Representable: instance Eq e => Representable ((->) e)
- Control.Lens.Representable: instance Representable Identity
- Control.Lens.Representable: newtype Path f
- Control.Lens.Representable: paths :: Representable f => f (Path f)
- Control.Lens.Representable: pureRep :: Representable f => a -> f a
- Control.Lens.Representable: rep :: Representable f => (Rep f -> a) -> f a
- Control.Lens.Representable: rfoldMap :: (Representable f, Foldable f, Monoid m) => (Rep f -> a -> m) -> f a -> m
- Control.Lens.Representable: rfolded :: (Representable f, Foldable f) => IndexedFold (Path f) (f a) a
- Control.Lens.Representable: rfoldr :: (Representable f, Foldable f) => (Rep f -> a -> b -> b) -> b -> f a -> b
- Control.Lens.Representable: rfor :: (Representable f, Traversable f, Applicative g) => f a -> (Rep f -> a -> g b) -> g (f b)
- Control.Lens.Representable: rforM :: (Representable f, Traversable f, Monad m) => f a -> (Rep f -> a -> m b) -> m (f b)
- Control.Lens.Representable: rmap :: Representable f => (Rep f -> a -> b) -> f a -> f b
- Control.Lens.Representable: rmapM :: (Representable f, Traversable f, Monad m) => (Rep f -> a -> m b) -> f a -> m (f b)
- Control.Lens.Representable: rmapM_ :: (Representable f, Foldable f, Monad m) => (Rep f -> a -> m b) -> f a -> m ()
- Control.Lens.Representable: rmapped :: Representable f => IndexedSetter (Path f) (f a) (f b) a b
- Control.Lens.Representable: rtraverse :: (Representable f, Traversable f, Applicative g) => (Rep f -> a -> g b) -> f a -> g (f b)
- Control.Lens.Representable: rtraverse_ :: (Representable f, Foldable f, Applicative g) => (Rep f -> a -> g b) -> f a -> g ()
- Control.Lens.Representable: rtraversed :: (Representable f, Traversable f) => IndexedTraversal (Path f) (f a) (f b) a b
- Control.Lens.Representable: tabulated :: Representable f => (Path f -> a) -> f a
- Control.Lens.Representable: type Rep f = forall a. Simple Lens (f a) a
- Control.Lens.Representable: walk :: Path f -> Rep f
- Control.Lens.Setter: ReifySetter :: Setter s t a b -> ReifiedSetter s t a b
- Control.Lens.Setter: newtype ReifiedSetter s t a b
- Control.Lens.Setter: reflectSetter :: ReifiedSetter s t a b -> Setter s t a b
- Control.Lens.Setter: type SimpleReifiedSetter s a = ReifiedSetter s s a a
- Control.Lens.Setter: type SimpleSetter s a = Setter s s a a
- Control.Lens.Setter: type SimpleSetting s a = Setting s s a a
- Control.Lens.Simple: type (:<->) s a = Iso s s a a
- Control.Lens.Traversal: ReifyTraversal :: Traversal s t a b -> ReifiedTraversal s t a b
- Control.Lens.Traversal: data ReifiedTraversal s t a b
- Control.Lens.Traversal: reflectTraversal :: ReifiedTraversal s t a b -> Traversal s t a b
- Control.Lens.Traversal: type SimpleReifiedTraversal s a = ReifiedTraversal s s a a
- Control.Lens.Traversal: type SimpleTraversal s a = Traversal s s a a
- Control.Lens.Type: (%%=) :: MonadState s m => LensLike ((,) r) s s a b -> (a -> (r, b)) -> m r
- Control.Lens.Type: (%%~) :: LensLike f s t a b -> (a -> f b) -> s -> f t
- Control.Lens.Type: (<%=) :: MonadState s m => LensLike ((,) b) s s a b -> (a -> b) -> m b
- Control.Lens.Type: (<%~) :: LensLike ((,) b) s t a b -> (a -> b) -> s -> (b, t)
- Control.Lens.Type: (<&&=) :: MonadState s m => SimpleLensLike ((,) Bool) s Bool -> Bool -> m Bool
- Control.Lens.Type: (<&&~) :: LensLike ((,) Bool) s t Bool Bool -> Bool -> s -> (Bool, t)
- Control.Lens.Type: (<**=) :: (MonadState s m, Floating a) => SimpleLensLike ((,) a) s a -> a -> m a
- Control.Lens.Type: (<**~) :: Floating a => LensLike ((,) a) s t a a -> a -> s -> (a, t)
- Control.Lens.Type: (<*=) :: (MonadState s m, Num a) => SimpleLensLike ((,) a) s a -> a -> m a
- Control.Lens.Type: (<*~) :: Num a => LensLike ((,) a) s t a a -> a -> s -> (a, t)
- Control.Lens.Type: (<+=) :: (MonadState s m, Num a) => SimpleLensLike ((,) a) s a -> a -> m a
- Control.Lens.Type: (<+~) :: Num a => LensLike ((,) a) s t a a -> a -> s -> (a, t)
- Control.Lens.Type: (<-=) :: (MonadState s m, Num a) => SimpleLensLike ((,) a) s a -> a -> m a
- Control.Lens.Type: (<-~) :: Num a => LensLike ((,) a) s t a a -> a -> s -> (a, t)
- Control.Lens.Type: (<//=) :: (MonadState s m, Fractional a) => SimpleLensLike ((,) a) s a -> a -> m a
- Control.Lens.Type: (<//~) :: Fractional a => LensLike ((,) a) s t a a -> a -> s -> (a, t)
- Control.Lens.Type: (<<%=) :: MonadState s m => LensLike ((,) a) s s a b -> (a -> b) -> m a
- Control.Lens.Type: (<<%~) :: LensLike ((,) a) s t a b -> (a -> b) -> s -> (a, t)
- Control.Lens.Type: (<<.=) :: MonadState s m => LensLike ((,) a) s s a b -> b -> m a
- Control.Lens.Type: (<<.~) :: LensLike ((,) a) s t a b -> b -> s -> (a, t)
- Control.Lens.Type: (<<>=) :: (MonadState s m, Monoid r) => SimpleLensLike ((,) r) s r -> r -> m r
- Control.Lens.Type: (<<>~) :: Monoid m => LensLike ((,) m) s t m m -> m -> s -> (m, t)
- Control.Lens.Type: (<<~) :: MonadState s m => LensLike (Context a b) s s a b -> m b -> m b
- Control.Lens.Type: (<^=) :: (MonadState s m, Num a, Integral e) => SimpleLensLike ((,) a) s a -> e -> m a
- Control.Lens.Type: (<^^=) :: (MonadState s m, Fractional a, Integral e) => SimpleLensLike ((,) a) s a -> e -> m a
- Control.Lens.Type: (<^^~) :: (Fractional a, Integral e) => LensLike ((,) a) s t a a -> e -> s -> (a, t)
- Control.Lens.Type: (<^~) :: (Num a, Integral e) => LensLike ((,) a) s t a a -> e -> s -> (a, t)
- Control.Lens.Type: (<||=) :: MonadState s m => SimpleLensLike ((,) Bool) s Bool -> Bool -> m Bool
- Control.Lens.Type: (<||~) :: LensLike ((,) Bool) s t Bool Bool -> Bool -> s -> (Bool, t)
- Control.Lens.Type: Context :: (b -> t) -> a -> Context a b t
- Control.Lens.Type: ReifyLens :: Lens s t a b -> ReifiedLens s t a b
- Control.Lens.Type: alongside :: LensLike (Context a b) s t a b -> LensLike (Context a' b') s' t' a' b' -> Lens (s, s') (t, t') (a, a') (b, b')
- Control.Lens.Type: choosing :: Functor f => LensLike f s t a b -> LensLike f s' t' a b -> LensLike f (Either s s') (Either t t') a b
- Control.Lens.Type: chosen :: Lens (Either a a) (Either b b) a b
- Control.Lens.Type: cloneLens :: Functor f => LensLike (Context a b) s t a b -> (a -> f b) -> s -> f t
- Control.Lens.Type: data Context a b t
- Control.Lens.Type: inside :: LensLike (Context a b) s t a b -> Lens (e -> s) (e -> t) (e -> a) (e -> b)
- Control.Lens.Type: lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b
- Control.Lens.Type: locus :: ComonadStore s w => Simple Lens (w a) s
- Control.Lens.Type: newtype ReifiedLens s t a b
- Control.Lens.Type: reflectLens :: ReifiedLens s t a b -> Lens s t a b
- Control.Lens.Type: type SimpleLens s a = Lens s s a a
- Control.Lens.Type: type SimpleLensLike f s a = LensLike f s s a a
- Control.Lens.Type: type SimpleOverloaded k f s a = Overloaded k f s s a a
- Control.Lens.Type: type SimpleReifiedLens s a = ReifiedLens s s a a
- Control.Lens.WithIndex: class Foldable f => FoldableWithIndex i f | f -> i where ifoldr f z t = appEndo (ifoldMap (\ i -> endo# (f i)) t) z ifoldl f z t = appEndo (getDual (ifoldMap (\ i -> dual# (endo# (flip (f i)))) t)) z ifoldr' f z0 xs = ifoldl f' id xs z0 where f' i k x z = k $! f i x z ifoldl' f z0 xs = ifoldr f' id xs z0 where f' i x k z = k $! f i z x
- Control.Lens.WithIndex: class Functor f => FunctorWithIndex i f | f -> i
- Control.Lens.WithIndex: class (FunctorWithIndex i t, FoldableWithIndex i t, Traversable t) => TraversableWithIndex i t | t -> i
- Control.Lens.WithIndex: iall :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Bool
- Control.Lens.WithIndex: iany :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Bool
- Control.Lens.WithIndex: iconcatMap :: FoldableWithIndex i f => (i -> a -> [b]) -> f a -> [b]
- Control.Lens.WithIndex: ifind :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Maybe (i, a)
- Control.Lens.WithIndex: ifoldMap :: (FoldableWithIndex i f, Monoid m) => (i -> a -> m) -> f a -> m
- Control.Lens.WithIndex: ifolded :: FoldableWithIndex i f => IndexedFold i (f a) a
- Control.Lens.WithIndex: ifolding :: FoldableWithIndex i f => (s -> f a) -> IndexedFold i s a
- Control.Lens.WithIndex: ifoldl :: FoldableWithIndex i f => (i -> b -> a -> b) -> b -> f a -> b
- Control.Lens.WithIndex: ifoldl' :: FoldableWithIndex i f => (i -> b -> a -> b) -> b -> f a -> b
- Control.Lens.WithIndex: ifoldlM :: (FoldableWithIndex i f, Monad m) => (i -> b -> a -> m b) -> b -> f a -> m b
- Control.Lens.WithIndex: ifoldr :: FoldableWithIndex i f => (i -> a -> b -> b) -> b -> f a -> b
- Control.Lens.WithIndex: ifoldr' :: FoldableWithIndex i f => (i -> a -> b -> b) -> b -> f a -> b
- Control.Lens.WithIndex: ifoldrM :: (FoldableWithIndex i f, Monad m) => (i -> a -> b -> m b) -> b -> f a -> m b
- Control.Lens.WithIndex: ifor :: (TraversableWithIndex i t, Applicative f) => t a -> (i -> a -> f b) -> f (t b)
- Control.Lens.WithIndex: iforM :: (TraversableWithIndex i t, Monad m) => t a -> (i -> a -> m b) -> m (t b)
- Control.Lens.WithIndex: iforM_ :: (FoldableWithIndex i t, Monad m) => t a -> (i -> a -> m b) -> m ()
- Control.Lens.WithIndex: ifor_ :: (FoldableWithIndex i t, Applicative f) => t a -> (i -> a -> f b) -> f ()
- Control.Lens.WithIndex: imap :: FunctorWithIndex i f => (i -> a -> b) -> f a -> f b
- Control.Lens.WithIndex: imapAccumL :: TraversableWithIndex i t => (i -> s -> a -> (s, b)) -> s -> t a -> (s, t b)
- Control.Lens.WithIndex: imapAccumR :: TraversableWithIndex i t => (i -> s -> a -> (s, b)) -> s -> t a -> (s, t b)
- Control.Lens.WithIndex: imapM :: (TraversableWithIndex i t, Monad m) => (i -> a -> m b) -> t a -> m (t b)
- Control.Lens.WithIndex: imapM_ :: (FoldableWithIndex i t, Monad m) => (i -> a -> m b) -> t a -> m ()
- Control.Lens.WithIndex: imapped :: FunctorWithIndex i f => IndexedSetter i (f a) (f b) a b
- Control.Lens.WithIndex: indices :: FoldableWithIndex i f => Fold (f a) i
- Control.Lens.WithIndex: instance (Eq k, Hashable k) => FoldableWithIndex k (HashMap k)
- Control.Lens.WithIndex: instance (Eq k, Hashable k) => FunctorWithIndex k (HashMap k)
- Control.Lens.WithIndex: instance (Eq k, Hashable k) => TraversableWithIndex k (HashMap k)
- Control.Lens.WithIndex: instance FoldableWithIndex Int IntMap
- Control.Lens.WithIndex: instance FoldableWithIndex Int Seq
- Control.Lens.WithIndex: instance FoldableWithIndex Int Vector
- Control.Lens.WithIndex: instance FoldableWithIndex Int []
- Control.Lens.WithIndex: instance FoldableWithIndex k (Map k)
- Control.Lens.WithIndex: instance FunctorWithIndex Int IntMap
- Control.Lens.WithIndex: instance FunctorWithIndex Int Seq
- Control.Lens.WithIndex: instance FunctorWithIndex Int Vector
- Control.Lens.WithIndex: instance FunctorWithIndex Int []
- Control.Lens.WithIndex: instance FunctorWithIndex k (Map k)
- Control.Lens.WithIndex: instance TraversableWithIndex Int IntMap
- Control.Lens.WithIndex: instance TraversableWithIndex Int Seq
- Control.Lens.WithIndex: instance TraversableWithIndex Int Vector
- Control.Lens.WithIndex: instance TraversableWithIndex Int []
- Control.Lens.WithIndex: instance TraversableWithIndex k (Map k)
- Control.Lens.WithIndex: itoList :: FoldableWithIndex i f => f a -> [(i, a)]
- Control.Lens.WithIndex: itraverse :: (TraversableWithIndex i t, Applicative f) => (i -> a -> f b) -> t a -> f (t b)
- Control.Lens.WithIndex: itraverse_ :: (FoldableWithIndex i t, Applicative f) => (i -> a -> f b) -> t a -> f ()
- Control.Lens.WithIndex: itraversed :: TraversableWithIndex i f => IndexedTraversal i (f a) (f b) a b
- Control.Lens.WithIndex: iwhere :: TraversableWithIndex i t => (i -> Bool) -> SimpleIndexedTraversal i (t a) a
- Control.Lens.WithIndex: withIndices :: FoldableWithIndex i f => Fold (f a) (i, a)
- Control.Lens.Wrapped: instance (Applicative f, Applicative g) => Wrapped (f a) (g b) (Lift f a) (Lift g b)
- Control.Lens.Zipper: type Zipper = :>
- Control.Lens.Zoom: instance (Error e, Zoom m n k s t) => Zoom (ErrorT e m) (ErrorT e n) (FocusingErr e k) s t
- Control.Lens.Zoom: instance (Monad m, Monoid w) => Magnify (RWST b w s m) (RWST a w s m) (EffectRWS w s m) b a
- Control.Lens.Zoom: instance (Monoid w, Monad z) => Zoom (RWST r w s z) (RWST r w t z) (FocusingWith w z) s t
- Control.Lens.Zoom: instance (Monoid w, Zoom m n k s t) => Zoom (WriterT w m) (WriterT w n) (FocusingPlus w k) s t
- Control.Lens.Zoom: instance Magnify ((->) b) ((->) a) Accessor b a
- Control.Lens.Zoom: instance Magnify m n k b a => Magnify (IdentityT m) (IdentityT n) k b a
- Control.Lens.Zoom: instance Monad m => Magnify (ReaderT b m) (ReaderT a m) (Effect m) b a
- Control.Lens.Zoom: instance Monad z => Zoom (StateT s z) (StateT t z) (Focusing z) s t
- Control.Lens.Zoom: instance Zoom m n k s t => Zoom (IdentityT m) (IdentityT n) k s t
- Control.Lens.Zoom: instance Zoom m n k s t => Zoom (ListT m) (ListT n) (FocusingOn [] k) s t
- Control.Lens.Zoom: instance Zoom m n k s t => Zoom (MaybeT m) (MaybeT n) (FocusingMay k) s t
- Control.Lens.Zoom: instance Zoom m n k s t => Zoom (ReaderT e m) (ReaderT e n) k s t
- Data.Array.Lens: _array :: (IArray arr a, IArray arr b, Ix i) => IndexedTraversal i (arr i a) (arr i b) a b
- Data.Array.Lens: ix :: (IArray a e, Ix i) => i -> Simple Lens (a i e) e
- Data.Complex.Lens: complex :: Traversal (Complex a) (Complex b) a b
- Data.Dynamic.Lens: dynamic :: Typeable a => Simple Prism Dynamic a
- Data.List.Lens: _head :: SimpleIndexedTraversal Int [a] a
- Data.List.Lens: _init :: Simple Traversal [a] [a]
- Data.List.Lens: _last :: SimpleIndexedTraversal Int [a] a
- Data.List.Lens: _tail :: Simple Traversal [a] [a]
- Data.Sequence.Lens: _head :: SimpleIndexedTraversal Int (Seq a) a
- Data.Sequence.Lens: _init :: SimpleTraversal (Seq a) (Seq a)
- Data.Sequence.Lens: _last :: SimpleIndexedTraversal Int (Seq a) a
- Data.Sequence.Lens: _tail :: SimpleTraversal (Seq a) (Seq a)
- Data.Sequence.Lens: ordinal :: Int -> SimpleIndexedLens Int (Seq a) a
- Data.Vector.Generic.Lens: _head :: Vector v a => SimpleLens (v a) a
- Data.Vector.Generic.Lens: _init :: Vector v a => SimpleLens (v a) (v a)
- Data.Vector.Generic.Lens: _last :: Vector v a => SimpleLens (v a) a
- Data.Vector.Generic.Lens: _tail :: Vector v a => SimpleLens (v a) (v a)
- Data.Vector.Generic.Lens: ordinal :: Vector v a => Int -> SimpleIndexedLens Int (v a) a
- Data.Vector.Lens: _head :: SimpleLens (Vector a) a
- Data.Vector.Lens: _init :: SimpleLens (Vector a) (Vector a)
- Data.Vector.Lens: _last :: SimpleLens (Vector a) a
- Data.Vector.Lens: _tail :: SimpleLens (Vector a) (Vector a)
- Data.Vector.Lens: ordinal :: Int -> SimpleIndexedLens Int (Vector a) a
+ Control.Exception.Lens: _ArithException :: AsArithException p f t => Overloaded' p f t ArithException
+ Control.Exception.Lens: _ArrayException :: AsArrayException p f t => Overloaded' p f t ArrayException
+ Control.Exception.Lens: _AssertionFailed :: AsAssertionFailed p f t => Overloaded' p f t String
+ Control.Exception.Lens: _AsyncException :: AsAsyncException p f t => Overloaded' p f t AsyncException
+ Control.Exception.Lens: _BlockedIndefinitelyOnMVar :: AsBlockedIndefinitelyOnMVar p f t => Overloaded' p f t ()
+ Control.Exception.Lens: _BlockedIndefinitelyOnSTM :: AsBlockedIndefinitelyOnSTM p f t => Overloaded' p f t ()
+ Control.Exception.Lens: _Deadlock :: AsDeadlock p f t => Overloaded' p f t ()
+ Control.Exception.Lens: _Denormal :: (AsArithException p f t, Choice p, Applicative f) => Overloaded' p f t ()
+ Control.Exception.Lens: _DivideByZero :: (AsArithException p f t, Choice p, Applicative f) => Overloaded' p f t ()
+ Control.Exception.Lens: _ErrorCall :: AsErrorCall p f t => Overloaded' p f t String
+ Control.Exception.Lens: _HeapOverflow :: (AsAsyncException p f t, Choice p, Applicative f) => Overloaded' p f t ()
+ Control.Exception.Lens: _IOException :: AsIOException p f t => Overloaded' p f t IOException
+ Control.Exception.Lens: _IndexOutOfBounds :: (AsArrayException p f t, Choice p, Applicative f) => Overloaded' p f t String
+ Control.Exception.Lens: _LossOfPrecision :: (AsArithException p f t, Choice p, Applicative f) => Overloaded' p f t ()
+ Control.Exception.Lens: _NestedAtomically :: AsNestedAtomically p f t => Overloaded' p f t ()
+ Control.Exception.Lens: _NoMethodError :: AsNoMethodError p f t => Overloaded' p f t String
+ Control.Exception.Lens: _NonTermination :: AsNonTermination p f t => Overloaded' p f t ()
+ Control.Exception.Lens: _Overflow :: (AsArithException p f t, Choice p, Applicative f) => Overloaded' p f t ()
+ Control.Exception.Lens: _PatternMatchFail :: AsPatternMatchFail p f t => Overloaded' p f t String
+ Control.Exception.Lens: _RatioZeroDenominator :: (AsArithException p f t, Choice p, Applicative f) => Overloaded' p f t ()
+ Control.Exception.Lens: _RecConError :: AsRecConError p f t => Overloaded' p f t String
+ Control.Exception.Lens: _RecSelError :: AsRecSelError p f t => Overloaded' p f t String
+ Control.Exception.Lens: _RecUpdError :: AsRecUpdError p f t => Overloaded' p f t String
+ Control.Exception.Lens: _StackOverflow :: (AsAsyncException p f t, Choice p, Applicative f) => Overloaded' p f t ()
+ Control.Exception.Lens: _ThreadKilled :: (AsAsyncException p f t, Choice p, Applicative f) => Overloaded' p f t ()
+ Control.Exception.Lens: _UndefinedElement :: (AsArrayException p f t, Choice p, Applicative f) => Overloaded' p f t String
+ Control.Exception.Lens: _Underflow :: (AsArithException p f t, Choice p, Applicative f) => Overloaded' p f t ()
+ Control.Exception.Lens: _UserInterrupt :: (AsAsyncException p f t, Choice p, Applicative f) => Overloaded' p f t ()
+ Control.Exception.Lens: catching :: MonadCatchIO m => Getting (First a) SomeException t a b -> m r -> (a -> m r) -> m r
+ Control.Exception.Lens: catching_ :: MonadCatchIO m => Getting (First a) SomeException t a b -> m r -> m r -> m r
+ Control.Exception.Lens: class AsArithException p f t
+ Control.Exception.Lens: class AsArrayException p f t
+ Control.Exception.Lens: class AsAssertionFailed p f t
+ Control.Exception.Lens: class AsAsyncException p f t
+ Control.Exception.Lens: class (Profunctor p, Functor f) => AsBlockedIndefinitelyOnMVar p f t
+ Control.Exception.Lens: class (Profunctor p, Functor f) => AsBlockedIndefinitelyOnSTM p f t
+ Control.Exception.Lens: class (Profunctor p, Functor f) => AsDeadlock p f t
+ Control.Exception.Lens: class (Profunctor p, Functor f) => AsErrorCall p f t
+ Control.Exception.Lens: class AsIOException p f t
+ Control.Exception.Lens: class (Profunctor p, Functor f) => AsNestedAtomically p f t
+ Control.Exception.Lens: class (Profunctor p, Functor f) => AsNoMethodError p f t
+ Control.Exception.Lens: class (Profunctor p, Functor f) => AsNonTermination p f t
+ Control.Exception.Lens: class (Profunctor p, Functor f) => AsPatternMatchFail p f t
+ Control.Exception.Lens: class (Profunctor p, Functor f) => AsRecConError p f t
+ Control.Exception.Lens: class (Profunctor p, Functor f) => AsRecSelError p f t
+ Control.Exception.Lens: class (Profunctor p, Functor f) => AsRecUpdError p f t
+ Control.Exception.Lens: handling :: MonadCatchIO m => Getting (First a) SomeException t a b -> (a -> m r) -> m r -> m r
+ Control.Exception.Lens: handling_ :: MonadCatchIO m => Getting (First a) SomeException t a b -> m r -> m r -> m r
+ Control.Exception.Lens: instance (Choice p, Applicative f) => AsArithException p f SomeException
+ Control.Exception.Lens: instance (Choice p, Applicative f) => AsArrayException p f SomeException
+ Control.Exception.Lens: instance (Choice p, Applicative f) => AsAssertionFailed p f SomeException
+ Control.Exception.Lens: instance (Choice p, Applicative f) => AsAsyncException p f SomeException
+ Control.Exception.Lens: instance (Choice p, Applicative f) => AsBlockedIndefinitelyOnMVar p f SomeException
+ Control.Exception.Lens: instance (Choice p, Applicative f) => AsBlockedIndefinitelyOnSTM p f SomeException
+ Control.Exception.Lens: instance (Choice p, Applicative f) => AsDeadlock p f SomeException
+ Control.Exception.Lens: instance (Choice p, Applicative f) => AsErrorCall p f SomeException
+ Control.Exception.Lens: instance (Choice p, Applicative f) => AsIOException p f SomeException
+ Control.Exception.Lens: instance (Choice p, Applicative f) => AsNestedAtomically p f SomeException
+ Control.Exception.Lens: instance (Choice p, Applicative f) => AsNoMethodError p f SomeException
+ Control.Exception.Lens: instance (Choice p, Applicative f) => AsNonTermination p f SomeException
+ Control.Exception.Lens: instance (Choice p, Applicative f) => AsPatternMatchFail p f SomeException
+ Control.Exception.Lens: instance (Choice p, Applicative f) => AsRecConError p f SomeException
+ Control.Exception.Lens: instance (Choice p, Applicative f) => AsRecSelError p f SomeException
+ Control.Exception.Lens: instance (Choice p, Applicative f) => AsRecUpdError p f SomeException
+ Control.Exception.Lens: instance (Profunctor p, Functor f) => AsAssertionFailed p f AssertionFailed
+ Control.Exception.Lens: instance (Profunctor p, Functor f) => AsBlockedIndefinitelyOnMVar p f BlockedIndefinitelyOnMVar
+ Control.Exception.Lens: instance (Profunctor p, Functor f) => AsBlockedIndefinitelyOnSTM p f BlockedIndefinitelyOnSTM
+ Control.Exception.Lens: instance (Profunctor p, Functor f) => AsDeadlock p f Deadlock
+ Control.Exception.Lens: instance (Profunctor p, Functor f) => AsErrorCall p f ErrorCall
+ Control.Exception.Lens: instance (Profunctor p, Functor f) => AsNestedAtomically p f NestedAtomically
+ Control.Exception.Lens: instance (Profunctor p, Functor f) => AsNoMethodError p f NoMethodError
+ Control.Exception.Lens: instance (Profunctor p, Functor f) => AsNonTermination p f NonTermination
+ Control.Exception.Lens: instance (Profunctor p, Functor f) => AsPatternMatchFail p f PatternMatchFail
+ Control.Exception.Lens: instance (Profunctor p, Functor f) => AsRecConError p f RecConError
+ Control.Exception.Lens: instance (Profunctor p, Functor f) => AsRecSelError p f RecSelError
+ Control.Exception.Lens: instance (Profunctor p, Functor f) => AsRecUpdError p f RecUpdError
+ Control.Exception.Lens: instance AsArithException p f ArithException
+ Control.Exception.Lens: instance AsArrayException p f ArrayException
+ Control.Exception.Lens: instance AsAsyncException p f AsyncException
+ Control.Exception.Lens: instance AsIOException p f IOException
+ Control.Exception.Lens: throwing :: AReview s SomeException a b -> b -> a
+ Control.Exception.Lens: throwingM :: MonadCatchIO m => AReview s SomeException a b -> b -> m a
+ Control.Exception.Lens: throwingTo :: MonadIO m => ThreadId -> AReview s SomeException a b -> b -> m ()
+ Control.Exception.Lens: trying :: MonadCatchIO m => Getting (First a) SomeException t a b -> m r -> m (Either a r)
+ Control.Lens.Action: (^!!) :: Monad m => s -> Acting m [a] s t a b -> m [a]
+ Control.Lens.Action: (^!?) :: Monad m => s -> Acting m (Leftmost a) s t a b -> m (Maybe a)
+ Control.Lens.Action: (^@!!) :: Monad m => s -> IndexedActing i m [(i, a)] s t a b -> m [(i, a)]
+ Control.Lens.Action: (^@!) :: Monad m => s -> IndexedActing i m (i, a) s t a b -> m (i, a)
+ Control.Lens.Action: (^@!?) :: Monad m => s -> IndexedActing i m (Leftmost (i, a)) s t a b -> m (Maybe (i, a))
+ Control.Lens.Action: class (Monad m, Gettable f) => Effective m r f | f -> m r
+ Control.Lens.Action: iact :: Monad m => (s -> m (i, a)) -> IndexedAction i m s a
+ Control.Lens.Action: iperform :: Monad m => IndexedActing i m (i, a) s t a b -> s -> m (i, a)
+ Control.Lens.Action: iperforms :: Monad m => IndexedActing i m e s t a b -> (i -> a -> e) -> s -> m e
+ Control.Lens.Action: type IndexedActing i m r s t a b = Over (Indexed i) (Effect m r) s t a b
+ Control.Lens.Action: type IndexedMonadicFold i m s a = forall p f r. (Indexable i p, Effective m r f, Applicative f) => p a (f a) -> s -> f s
+ Control.Lens.At: _at :: Ixed f m => Index m -> IndexedLensLike' (Index m) f m (IxValue m)
+ Control.Lens.At: at :: At m => Index m -> IndexedLens' (Index m) m (Maybe (IxValue m))
+ Control.Lens.At: class At m
+ Control.Lens.At: class Functor f => Contains f m where contains = containsAt
+ Control.Lens.At: class (Functor f, Contains (Accessor (IxValue m)) m) => Ixed f m where ix = ixAt
+ Control.Lens.At: contains :: Contains f m => Index m -> IndexedLensLike' (Index m) f m Bool
+ Control.Lens.At: containsAt :: (Gettable f, At m) => Index m -> IndexedLensLike' (Index m) f m Bool
+ Control.Lens.At: containsIx :: (Gettable f, Ixed (Accessor Any) m) => Index m -> IndexedLensLike' (Index m) f m Bool
+ Control.Lens.At: containsLength :: (Ord i, Num i) => (s -> i) -> i -> IndexedGetter i s Bool
+ Control.Lens.At: containsLookup :: (i -> s -> Maybe a) -> i -> IndexedGetter i s Bool
+ Control.Lens.At: containsN :: Int -> Int -> IndexedGetter Int s Bool
+ Control.Lens.At: containsTest :: (i -> s -> Bool) -> i -> IndexedGetter i s Bool
+ Control.Lens.At: instance (Applicative f, Eq k, Hashable k) => Ixed f (HashMap k a)
+ Control.Lens.At: instance (Applicative f, IArray UArray e, Ix i) => Ixed f (UArray i e)
+ Control.Lens.At: instance (Applicative f, Ix i) => Ixed f (Array i e)
+ Control.Lens.At: instance (Applicative f, Ord k) => Ixed f (Map k a)
+ Control.Lens.At: instance (Applicative f, Prim a) => Ixed f (Vector a)
+ Control.Lens.At: instance (Applicative f, Storable a) => Ixed f (Vector a)
+ Control.Lens.At: instance (Applicative f, Unbox a) => Ixed f (Vector a)
+ Control.Lens.At: instance (Applicative f, a ~ b) => Ixed f (a, b)
+ Control.Lens.At: instance (Applicative f, a ~ b, b ~ c) => Ixed f (a, b, c)
+ Control.Lens.At: instance (Applicative f, a ~ b, b ~ c, c ~ d) => Ixed f (a, b, c, d)
+ Control.Lens.At: instance (Applicative f, a ~ b, b ~ c, c ~ d, d ~ e) => Ixed f (a, b, c, d, e)
+ Control.Lens.At: instance (Applicative f, a ~ b, b ~ c, c ~ d, d ~ e, e ~ f') => Ixed f (a, b, c, d, e, f')
+ Control.Lens.At: instance (Applicative f, a ~ b, b ~ c, c ~ d, d ~ e, e ~ f', f' ~ g) => Ixed f (a, b, c, d, e, f', g)
+ Control.Lens.At: instance (Applicative f, a ~ b, b ~ c, c ~ d, d ~ e, e ~ f', f' ~ g, g ~ h) => Ixed f (a, b, c, d, e, f', g, h)
+ Control.Lens.At: instance (Applicative f, a ~ b, b ~ c, c ~ d, d ~ e, e ~ f', f' ~ g, g ~ h, h ~ i) => Ixed f (a, b, c, d, e, f', g, h, i)
+ Control.Lens.At: instance (Eq k, Hashable k) => At (HashMap k a)
+ Control.Lens.At: instance (Functor f, Eq a, Hashable a) => Contains f (HashSet a)
+ Control.Lens.At: instance (Functor f, Eq k) => Ixed f (k -> a)
+ Control.Lens.At: instance (Functor f, Ord a) => Contains f (Set a)
+ Control.Lens.At: instance (Gettable f, Eq k, Hashable k) => Contains f (HashMap k a)
+ Control.Lens.At: instance (Gettable f, IArray UArray e, Ix i) => Contains f (UArray i e)
+ Control.Lens.At: instance (Gettable f, Ix i) => Contains f (Array i e)
+ Control.Lens.At: instance (Gettable f, Ord k) => Contains f (Map k a)
+ Control.Lens.At: instance (Gettable f, Prim a) => Contains f (Vector a)
+ Control.Lens.At: instance (Gettable f, Storable a) => Contains f (Vector a)
+ Control.Lens.At: instance (Gettable f, Unbox a) => Contains f (Vector a)
+ Control.Lens.At: instance Applicative f => Ixed f (Complex a)
+ Control.Lens.At: instance Applicative f => Ixed f (IntMap a)
+ Control.Lens.At: instance Applicative f => Ixed f (Seq a)
+ Control.Lens.At: instance Applicative f => Ixed f (Tree a)
+ Control.Lens.At: instance Applicative f => Ixed f (Vector a)
+ Control.Lens.At: instance Applicative f => Ixed f ByteString
+ Control.Lens.At: instance Applicative f => Ixed f Text
+ Control.Lens.At: instance Applicative f => Ixed f [a]
+ Control.Lens.At: instance At (IntMap a)
+ Control.Lens.At: instance Functor f => Contains f IntSet
+ Control.Lens.At: instance Functor f => Ixed f (Identity a)
+ Control.Lens.At: instance Gettable f => Contains f (Complex a)
+ Control.Lens.At: instance Gettable f => Contains f (Seq a)
+ Control.Lens.At: instance Gettable f => Contains f (Tree a)
+ Control.Lens.At: instance Gettable f => Contains f (Vector a)
+ Control.Lens.At: instance Gettable f => Contains f (e -> a)
+ Control.Lens.At: instance Gettable f => Contains f ByteString
+ Control.Lens.At: instance Gettable f => Contains f Text
+ Control.Lens.At: instance Gettable f => Contains f [a]
+ Control.Lens.At: instance Gettable k => Contains k (Identity a)
+ Control.Lens.At: instance Gettable k => Contains k (IntMap a)
+ Control.Lens.At: instance Gettable k => Contains k (a, b)
+ Control.Lens.At: instance Gettable k => Contains k (a, b, c)
+ Control.Lens.At: instance Gettable k => Contains k (a, b, c, d)
+ Control.Lens.At: instance Gettable k => Contains k (a, b, c, d, e)
+ Control.Lens.At: instance Gettable k => Contains k (a, b, c, d, e, f)
+ Control.Lens.At: instance Gettable k => Contains k (a, b, c, d, e, f, g)
+ Control.Lens.At: instance Gettable k => Contains k (a, b, c, d, e, f, g, h)
+ Control.Lens.At: instance Gettable k => Contains k (a, b, c, d, e, f, g, h, i)
+ Control.Lens.At: instance Ord k => At (Map k a)
+ Control.Lens.At: ix :: Ixed f m => Index m -> IndexedLensLike' (Index m) f m (IxValue m)
+ Control.Lens.At: ixAt :: (Applicative f, At m) => Index m -> IndexedLensLike' (Index m) f m (IxValue m)
+ Control.Lens.At: ixEach :: (Applicative f, Eq (Index m), Each f m m (IxValue m) (IxValue m)) => Index m -> IndexedLensLike' (Index m) f m (IxValue m)
+ Control.Lens.At: resultAt :: Ixed f m => Index m -> IndexedLensLike' (Index m) f m (IxValue m)
+ Control.Lens.Combinators: (&) :: a -> (a -> b) -> b
+ Control.Lens.Cons: (<|) :: Cons Reviewed Identity s s a a => a -> s -> s
+ Control.Lens.Cons: (|>) :: Snoc Reviewed Identity s s a a => s -> a -> s
+ Control.Lens.Cons: _Cons :: Cons p f s t a b => Overloaded p f s t (a, s) (b, t)
+ Control.Lens.Cons: _Snoc :: Snoc p f s t a b => Overloaded p f s t (s, a) (t, b)
+ Control.Lens.Cons: _head :: Cons (->) f s s a a => LensLike' f s a
+ Control.Lens.Cons: _init :: Snoc (->) f s s a a => LensLike' f s s
+ Control.Lens.Cons: _last :: Snoc (->) f s s a a => LensLike' f s a
+ Control.Lens.Cons: _tail :: Cons (->) f s s a a => LensLike' f s s
+ Control.Lens.Cons: class (Profunctor p, Functor f) => Cons p f s t a b | s -> a, t -> b, s b -> t, t a -> s
+ Control.Lens.Cons: class (Profunctor p, Functor f) => Snoc p f s t a b | s -> a, t -> b, s b -> t, t a -> s
+ Control.Lens.Cons: cons :: Cons Reviewed Identity s s a a => a -> s -> s
+ Control.Lens.Cons: instance (Choice p, Applicative f) => Cons p f (Seq a) (Seq b) a b
+ Control.Lens.Cons: instance (Choice p, Applicative f) => Cons p f (Vector a) (Vector b) a b
+ Control.Lens.Cons: instance (Choice p, Applicative f) => Cons p f ByteString ByteString Word8 Word8
+ Control.Lens.Cons: instance (Choice p, Applicative f) => Cons p f Text Text Char Char
+ Control.Lens.Cons: instance (Choice p, Applicative f) => Cons p f [a] [b] a b
+ Control.Lens.Cons: instance (Choice p, Applicative f) => Snoc p f (Seq a) (Seq b) a b
+ Control.Lens.Cons: instance (Choice p, Applicative f) => Snoc p f (Vector a) (Vector b) a b
+ Control.Lens.Cons: instance (Choice p, Applicative f) => Snoc p f ByteString ByteString Word8 Word8
+ Control.Lens.Cons: instance (Choice p, Applicative f) => Snoc p f Text Text Char Char
+ Control.Lens.Cons: instance (Choice p, Applicative f) => Snoc p f [a] [b] a b
+ Control.Lens.Cons: instance (Choice p, Applicative f, Prim a, Prim b) => Cons p f (Vector a) (Vector b) a b
+ Control.Lens.Cons: instance (Choice p, Applicative f, Prim a, Prim b) => Snoc p f (Vector a) (Vector b) a b
+ Control.Lens.Cons: instance (Choice p, Applicative f, Storable a, Storable b) => Cons p f (Vector a) (Vector b) a b
+ Control.Lens.Cons: instance (Choice p, Applicative f, Storable a, Storable b) => Snoc p f (Vector a) (Vector b) a b
+ Control.Lens.Cons: instance (Choice p, Applicative f, Unbox a, Unbox b) => Cons p f (Vector a) (Vector b) a b
+ Control.Lens.Cons: instance (Choice p, Applicative f, Unbox a, Unbox b) => Snoc p f (Vector a) (Vector b) a b
+ Control.Lens.Cons: snoc :: Snoc Reviewed Identity s s a a => s -> a -> s
+ Control.Lens.Cons: uncons :: Cons (->) (Accessor (First (a, s))) s s a a => s -> Maybe (a, s)
+ Control.Lens.Cons: unsnoc :: Snoc (->) (Accessor (First (s, a))) s s a a => s -> Maybe (s, a)
+ Control.Lens.Each: instance (Applicative f, Ix i) => Each f (Array i a) (Array i b) a b
+ Control.Lens.Each: instance (Applicative f, Ix i, IArray UArray a, IArray UArray b) => Each f (UArray i a) (UArray i b) a b
+ Control.Lens.Each: instance (Applicative f, Prim a, Prim b) => Each f (Vector a) (Vector b) a b
+ Control.Lens.Each: instance (Applicative f, Storable a, Storable b) => Each f (Vector a) (Vector b) a b
+ Control.Lens.Each: instance (Applicative f, Unbox a, Unbox b) => Each f (Vector a) (Vector b) a b
+ Control.Lens.Each: instance (Applicative f, a ~ a', b ~ b') => Each f (a, a') (b, b') a b
+ Control.Lens.Each: instance (Applicative f, a ~ a2, a ~ a3, a ~ a4, a ~ a5, a ~ a6, a ~ a7, a ~ a8, a ~ a9, b ~ b2, b ~ b3, b ~ b4, b ~ b5, b ~ b6, b ~ b7, b ~ b8, b ~ b9) => Each f (a, a2, a3, a4, a5, a6, a7, a8, a9) (b, b2, b3, b4, b5, b6, b7, b8, b9) a b
+ Control.Lens.Each: instance (Applicative f, a ~ a2, a ~ a3, a ~ a4, a ~ a5, a ~ a6, a ~ a7, a ~ a8, b ~ b2, b ~ b3, b ~ b4, b ~ b5, b ~ b6, b ~ b7, b ~ b8) => Each f (a, a2, a3, a4, a5, a6, a7, a8) (b, b2, b3, b4, b5, b6, b7, b8) a b
+ Control.Lens.Each: instance (Applicative f, a ~ a2, a ~ a3, a ~ a4, a ~ a5, a ~ a6, a ~ a7, b ~ b2, b ~ b3, b ~ b4, b ~ b5, b ~ b6, b ~ b7) => Each f (a, a2, a3, a4, a5, a6, a7) (b, b2, b3, b4, b5, b6, b7) a b
+ Control.Lens.Each: instance (Applicative f, a ~ a2, a ~ a3, a ~ a4, a ~ a5, a ~ a6, b ~ b2, b ~ b3, b ~ b4, b ~ b5, b ~ b6) => Each f (a, a2, a3, a4, a5, a6) (b, b2, b3, b4, b5, b6) a b
+ Control.Lens.Each: instance (Applicative f, a ~ a2, a ~ a3, a ~ a4, a ~ a5, b ~ b2, b ~ b3, b ~ b4, b ~ b5) => Each f (a, a2, a3, a4, a5) (b, b2, b3, b4, b5) a b
+ Control.Lens.Each: instance (Applicative f, a ~ a2, a ~ a3, a ~ a4, b ~ b2, b ~ b3, b ~ b4) => Each f (a, a2, a3, a4) (b, b2, b3, b4) a b
+ Control.Lens.Each: instance (Applicative f, a ~ a2, a ~ a3, b ~ b2, b ~ b3) => Each f (a, a2, a3) (b, b2, b3) a b
+ Control.Lens.Each: instance Applicative f => Each f (Complex a) (Complex b) a b
+ Control.Lens.Each: instance Applicative f => Each f (HashMap c a) (HashMap c b) a b
+ Control.Lens.Each: instance Applicative f => Each f (IntMap a) (IntMap b) a b
+ Control.Lens.Each: instance Applicative f => Each f (Map c a) (Map c b) a b
+ Control.Lens.Each: instance Applicative f => Each f (Maybe a) (Maybe b) a b
+ Control.Lens.Each: instance Applicative f => Each f (Seq a) (Seq b) a b
+ Control.Lens.Each: instance Applicative f => Each f (Tree a) (Tree b) a b
+ Control.Lens.Each: instance Applicative f => Each f (Vector a) (Vector b) a b
+ Control.Lens.Each: instance Applicative f => Each f ByteString ByteString Word8 Word8
+ Control.Lens.Each: instance Applicative f => Each f Text Text Char Char
+ Control.Lens.Each: instance Applicative f => Each f [a] [b] a b
+ Control.Lens.Each: instance Functor f => Each f (Identity a) (Identity b) a b
+ Control.Lens.Each: instance Settable f => Each f (i -> a) (i -> b) a b
+ Control.Lens.Equality: Identical :: Identical a b a b
+ Control.Lens.Equality: data Identical a b s t
+ Control.Lens.Equality: fromEq :: AnEquality s t a b -> Equality b a t s
+ Control.Lens.Equality: mapEq :: AnEquality s t a b -> f s -> f a
+ Control.Lens.Equality: runEq :: AnEquality s t a b -> Identical s t a b
+ Control.Lens.Equality: simply :: (Overloaded' p f s a -> r) -> Overloaded' p f s a -> r
+ Control.Lens.Equality: substEq :: AnEquality s t a b -> ((s ~ a, t ~ b) => r) -> r
+ Control.Lens.Equality: type AnEquality s t a b = Identical a (Mutator b) a (Mutator b) -> Identical a (Mutator b) s (Mutator t)
+ Control.Lens.Equality: type AnEquality' s a = AnEquality s s a a
+ Control.Lens.Equality: type Equality s t a b = forall p (f :: * -> *). p a (f b) -> p s (f t)
+ Control.Lens.Equality: type Equality' s a = Equality s s a a
+ Control.Lens.Fold: (^@..) :: s -> IndexedGetting i (Endo [(i, a)]) s t a b -> [(i, a)]
+ Control.Lens.Fold: (^@?!) :: s -> IndexedGetting i (Endo (i, a)) s t a b -> (i, a)
+ Control.Lens.Fold: (^@?) :: s -> IndexedGetting i (Endo (Maybe (i, a))) s t a b -> Maybe (i, a)
+ Control.Lens.Fold: data Leftmost a
+ Control.Lens.Fold: data Rightmost a
+ Control.Lens.Fold: data Sequenced a m
+ Control.Lens.Fold: data Traversed a f
+ Control.Lens.Fold: foldl1Of' :: Getting (Endo (Endo (Maybe a))) s t a b -> (a -> a -> a) -> s -> a
+ Control.Lens.Fold: foldr1Of' :: Getting (Dual (Endo (Endo (Maybe a)))) s t a b -> (a -> a -> a) -> s -> a
+ Control.Lens.Fold: has :: Getting Any s t a b -> s -> Bool
+ Control.Lens.Fold: hasn't :: Getting All s t a b -> s -> Bool
+ Control.Lens.Fold: iallOf :: IndexedGetting i All s t a b -> (i -> a -> Bool) -> s -> Bool
+ Control.Lens.Fold: ianyOf :: IndexedGetting i Any s t a b -> (i -> a -> Bool) -> s -> Bool
+ Control.Lens.Fold: iconcatMapOf :: IndexedGetting i [r] s t a b -> (i -> a -> [r]) -> s -> [r]
+ Control.Lens.Fold: idroppingWhile :: (Indexable i p, Profunctor q, Applicative f) => (i -> a -> Bool) -> Overloading (Indexed i) q (Compose (State Bool) f) s t a a -> Overloading p q f s t a a
+ Control.Lens.Fold: ifiltered :: (Indexable i p, Applicative f) => (i -> a -> Bool) -> Overloading' p (Indexed i) f a a
+ Control.Lens.Fold: ifindOf :: IndexedGetting i (Endo (Maybe a)) s t a b -> (i -> a -> Bool) -> s -> Maybe a
+ Control.Lens.Fold: ifoldMapOf :: IndexedGetting i m s t a b -> (i -> a -> m) -> s -> m
+ Control.Lens.Fold: ifoldlMOf :: Monad m => IndexedGetting i (Endo (r -> m r)) s t a b -> (i -> r -> a -> m r) -> r -> s -> m r
+ Control.Lens.Fold: ifoldlOf :: IndexedGetting i (Dual (Endo r)) s t a b -> (i -> r -> a -> r) -> r -> s -> r
+ Control.Lens.Fold: ifoldlOf' :: IndexedGetting i (Endo (r -> r)) s t a b -> (i -> r -> a -> r) -> r -> s -> r
+ Control.Lens.Fold: ifoldrMOf :: Monad m => IndexedGetting i (Dual (Endo (r -> m r))) s t a b -> (i -> a -> r -> m r) -> r -> s -> m r
+ Control.Lens.Fold: ifoldrOf :: IndexedGetting i (Endo r) s t a b -> (i -> a -> r -> r) -> r -> s -> r
+ Control.Lens.Fold: ifoldrOf' :: IndexedGetting i (Dual (Endo (r -> r))) s t a b -> (i -> a -> r -> r) -> r -> s -> r
+ Control.Lens.Fold: iforMOf_ :: Monad m => IndexedGetting i (Sequenced r m) s t a b -> s -> (i -> a -> m r) -> m ()
+ Control.Lens.Fold: iforOf_ :: Functor f => IndexedGetting i (Traversed r f) s t a b -> s -> (i -> a -> f r) -> f ()
+ Control.Lens.Fold: imapMOf_ :: Monad m => IndexedGetting i (Sequenced r m) s t a b -> (i -> a -> m r) -> s -> m ()
+ Control.Lens.Fold: ipre :: IndexedGetting i (First (i, a)) s t a b -> IndexPreservingGetter s (Maybe (i, a))
+ Control.Lens.Fold: ipreuse :: MonadState s m => IndexedGetting i (First (i, a)) s t a b -> m (Maybe (i, a))
+ Control.Lens.Fold: ipreuses :: MonadState s m => IndexedGetting i (First r) s t a b -> (i -> a -> r) -> m (Maybe r)
+ Control.Lens.Fold: ipreview :: MonadReader s m => IndexedGetting i (First (i, a)) s t a b -> m (Maybe (i, a))
+ Control.Lens.Fold: ipreviews :: MonadReader s m => IndexedGetting i (First r) s t a b -> (i -> a -> r) -> m (Maybe r)
+ Control.Lens.Fold: itakingWhile :: (Indexable i p, Profunctor q, Applicative f, Gettable f) => (i -> a -> Bool) -> Overloading (Indexed i) q (Accessor (Endo (f s))) s s a a -> Overloading p q f s s a a
+ Control.Lens.Fold: itoListOf :: IndexedGetting i (Endo [(i, a)]) s t a b -> s -> [(i, a)]
+ Control.Lens.Fold: itraverseOf_ :: Functor f => IndexedGetting i (Traversed r f) s t a b -> (i -> a -> f r) -> s -> f ()
+ Control.Lens.Fold: pre :: Getting (First a) s t a b -> IndexPreservingGetter s (Maybe a)
+ Control.Lens.Fold: type IndexedFold i s a = forall p f. (Indexable i p, Applicative f, Gettable f) => p a (f a) -> s -> f s
+ Control.Lens.Getter: (^@.) :: s -> IndexedGetting i (i, a) s t a b -> (i, a)
+ Control.Lens.Getter: Accessor :: r -> Accessor r a
+ Control.Lens.Getter: coerce :: Gettable f => f a -> f b
+ Control.Lens.Getter: ilistening :: MonadWriter w m => IndexedGetting i (i, u) w t u b -> m a -> m (a, (i, u))
+ Control.Lens.Getter: ilistenings :: MonadWriter w m => IndexedGetting i v w t u b -> (i -> u -> v) -> m a -> m (a, v)
+ Control.Lens.Getter: iuse :: MonadState s m => IndexedGetting i (i, a) s t a b -> m (i, a)
+ Control.Lens.Getter: iuses :: MonadState s m => IndexedGetting i r s t a b -> (i -> a -> r) -> m r
+ Control.Lens.Getter: iview :: MonadReader s m => IndexedGetting i (i, a) s t a b -> m (i, a)
+ Control.Lens.Getter: iviews :: MonadReader s m => IndexedGetting i r s t a b -> (i -> a -> r) -> m r
+ Control.Lens.Getter: listening :: MonadWriter w m => Getting u w t u b -> m a -> m (a, u)
+ Control.Lens.Getter: listenings :: MonadWriter w m => Getting v w t u b -> (u -> v) -> m a -> m (a, v)
+ Control.Lens.Getter: newtype Accessor r a
+ Control.Lens.Getter: runAccessor :: Accessor r a -> r
+ Control.Lens.Getter: type Accessing p m s t a b = p a (Accessor m b) -> s -> Accessor m t
+ Control.Lens.Getter: type IndexedGetting i m s t a b = Indexed i a (Accessor m b) -> s -> Accessor m t
+ Control.Lens.Getter: type IndexedGetter i s a = forall p f. (Indexable i p, Gettable f) => p a (f a) -> s -> f s
+ Control.Lens.Indexed: asIndex :: (Indexable i p, Functor f, Gettable f) => Overloading' p (Indexed i) f s i
+ Control.Lens.Indexed: class (Profunctor p, Choice p, Strong p, Corepresentable p, Comonad (Corep p), Traversable (Corep p), Representable p, Monad (Rep p), MonadFix (Rep p), Distributive (Rep p), ArrowLoop p, ArrowApply p, ArrowChoice p) => Conjoined p where distrib = tabulate . collect . rep conjoined _ r = r
+ Control.Lens.Indexed: class Foldable f => FoldableWithIndex i f | f -> i where ifoldMap = ifoldMapOf itraversed ifolded = conjoined folded $ \ f -> coerce . getFolding . ifoldMap (\ i -> Folding #. indexed f i) ifoldr f z t = appEndo (ifoldMap (\ i -> Endo #. f i) t) z ifoldl f z t = appEndo (getDual (ifoldMap (\ i -> Dual #. Endo #. flip (f i)) t)) z ifoldr' f z0 xs = ifoldl f' id xs z0 where f' i k x z = k $! f i x z ifoldl' f z0 xs = ifoldr f' id xs z0 where f' i x k z = k $! f i z x
+ Control.Lens.Indexed: class Functor f => FunctorWithIndex i f | f -> i where imap = iover itraversed imapped = conjoined mapped (isets imap)
+ Control.Lens.Indexed: class (FunctorWithIndex i t, FoldableWithIndex i t, Traversable t) => TraversableWithIndex i t | t -> i where itraverse = traversed .# Indexed itraversed = conjoined traverse (itraverse . indexed)
+ Control.Lens.Indexed: conjoined :: Conjoined p => (p ~ (->) => q (a -> b) r) -> q (p a b) r -> q (p a b) r
+ Control.Lens.Indexed: distrib :: (Conjoined p, Functor f) => p a b -> p (f a) (f b)
+ Control.Lens.Indexed: iall :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Bool
+ Control.Lens.Indexed: iany :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Bool
+ Control.Lens.Indexed: iconcatMap :: FoldableWithIndex i f => (i -> a -> [b]) -> f a -> [b]
+ Control.Lens.Indexed: ifind :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Maybe (i, a)
+ Control.Lens.Indexed: ifoldMap :: (FoldableWithIndex i f, Monoid m) => (i -> a -> m) -> f a -> m
+ Control.Lens.Indexed: ifolded :: FoldableWithIndex i f => IndexedFold i (f a) a
+ Control.Lens.Indexed: ifolding :: FoldableWithIndex i f => (s -> f a) -> IndexedFold i s a
+ Control.Lens.Indexed: ifoldl :: FoldableWithIndex i f => (i -> b -> a -> b) -> b -> f a -> b
+ Control.Lens.Indexed: ifoldl' :: FoldableWithIndex i f => (i -> b -> a -> b) -> b -> f a -> b
+ Control.Lens.Indexed: ifoldlM :: (FoldableWithIndex i f, Monad m) => (i -> b -> a -> m b) -> b -> f a -> m b
+ Control.Lens.Indexed: ifoldr :: FoldableWithIndex i f => (i -> a -> b -> b) -> b -> f a -> b
+ Control.Lens.Indexed: ifoldr' :: FoldableWithIndex i f => (i -> a -> b -> b) -> b -> f a -> b
+ Control.Lens.Indexed: ifoldrM :: (FoldableWithIndex i f, Monad m) => (i -> a -> b -> m b) -> b -> f a -> m b
+ Control.Lens.Indexed: ifor :: (TraversableWithIndex i t, Applicative f) => t a -> (i -> a -> f b) -> f (t b)
+ Control.Lens.Indexed: iforM :: (TraversableWithIndex i t, Monad m) => t a -> (i -> a -> m b) -> m (t b)
+ Control.Lens.Indexed: iforM_ :: (FoldableWithIndex i t, Monad m) => t a -> (i -> a -> m b) -> m ()
+ Control.Lens.Indexed: ifor_ :: (FoldableWithIndex i t, Applicative f) => t a -> (i -> a -> f b) -> f ()
+ Control.Lens.Indexed: imap :: FunctorWithIndex i f => (i -> a -> b) -> f a -> f b
+ Control.Lens.Indexed: imapAccumL :: TraversableWithIndex i t => (i -> s -> a -> (s, b)) -> s -> t a -> (s, t b)
+ Control.Lens.Indexed: imapAccumR :: TraversableWithIndex i t => (i -> s -> a -> (s, b)) -> s -> t a -> (s, t b)
+ Control.Lens.Indexed: imapM :: (TraversableWithIndex i t, Monad m) => (i -> a -> m b) -> t a -> m (t b)
+ Control.Lens.Indexed: imapM_ :: (FoldableWithIndex i t, Monad m) => (i -> a -> m b) -> t a -> m ()
+ Control.Lens.Indexed: imapped :: (FunctorWithIndex i f, FunctorWithIndex i f) => IndexedSetter i (f a) (f b) a b
+ Control.Lens.Indexed: index :: (Indexable i p, Eq i, Applicative f) => i -> Overloading' p (Indexed i) f a a
+ Control.Lens.Indexed: indices :: (Indexable i p, Applicative f) => (i -> Bool) -> Overloading' p (Indexed i) f a a
+ Control.Lens.Indexed: instance (Eq k, Hashable k) => FoldableWithIndex k (HashMap k)
+ Control.Lens.Indexed: instance (Eq k, Hashable k) => FunctorWithIndex k (HashMap k)
+ Control.Lens.Indexed: instance (Eq k, Hashable k) => TraversableWithIndex k (HashMap k)
+ Control.Lens.Indexed: instance FoldableWithIndex () Identity
+ Control.Lens.Indexed: instance FoldableWithIndex Int IntMap
+ Control.Lens.Indexed: instance FoldableWithIndex Int Seq
+ Control.Lens.Indexed: instance FoldableWithIndex Int Vector
+ Control.Lens.Indexed: instance FoldableWithIndex Int []
+ Control.Lens.Indexed: instance FoldableWithIndex i (Level i)
+ Control.Lens.Indexed: instance FoldableWithIndex i (Magma i t b)
+ Control.Lens.Indexed: instance FoldableWithIndex i f => FoldableWithIndex i (Backwards f)
+ Control.Lens.Indexed: instance FoldableWithIndex i f => FoldableWithIndex i (Reverse f)
+ Control.Lens.Indexed: instance FoldableWithIndex k ((,) k)
+ Control.Lens.Indexed: instance FoldableWithIndex k (Map k)
+ Control.Lens.Indexed: instance FunctorWithIndex () Identity
+ Control.Lens.Indexed: instance FunctorWithIndex Int IntMap
+ Control.Lens.Indexed: instance FunctorWithIndex Int Seq
+ Control.Lens.Indexed: instance FunctorWithIndex Int Vector
+ Control.Lens.Indexed: instance FunctorWithIndex Int []
+ Control.Lens.Indexed: instance FunctorWithIndex i (Level i)
+ Control.Lens.Indexed: instance FunctorWithIndex i (Magma i t b)
+ Control.Lens.Indexed: instance FunctorWithIndex i f => FunctorWithIndex i (Backwards f)
+ Control.Lens.Indexed: instance FunctorWithIndex i f => FunctorWithIndex i (Reverse f)
+ Control.Lens.Indexed: instance FunctorWithIndex k ((,) k)
+ Control.Lens.Indexed: instance FunctorWithIndex k (Map k)
+ Control.Lens.Indexed: instance FunctorWithIndex r ((->) r)
+ Control.Lens.Indexed: instance TraversableWithIndex () Identity
+ Control.Lens.Indexed: instance TraversableWithIndex Int IntMap
+ Control.Lens.Indexed: instance TraversableWithIndex Int Seq
+ Control.Lens.Indexed: instance TraversableWithIndex Int Vector
+ Control.Lens.Indexed: instance TraversableWithIndex Int []
+ Control.Lens.Indexed: instance TraversableWithIndex i (Level i)
+ Control.Lens.Indexed: instance TraversableWithIndex i (Magma i t b)
+ Control.Lens.Indexed: instance TraversableWithIndex i f => TraversableWithIndex i (Backwards f)
+ Control.Lens.Indexed: instance TraversableWithIndex i f => TraversableWithIndex i (Reverse f)
+ Control.Lens.Indexed: instance TraversableWithIndex k ((,) k)
+ Control.Lens.Indexed: instance TraversableWithIndex k (Map k)
+ Control.Lens.Indexed: itoList :: FoldableWithIndex i f => f a -> [(i, a)]
+ Control.Lens.Indexed: itraverse :: (TraversableWithIndex i t, Applicative f) => (i -> a -> f b) -> t a -> f (t b)
+ Control.Lens.Indexed: itraverse_ :: (FoldableWithIndex i t, Applicative f) => (i -> a -> f b) -> t a -> f ()
+ Control.Lens.Indexed: itraversed :: TraversableWithIndex i t => IndexedTraversal i (t a) (t b) a b
+ Control.Lens.Indexed: runIndexed :: Indexed i a b -> i -> a -> b
+ Control.Lens.Internal.Action: Effect :: m r -> Effect m r a
+ Control.Lens.Internal.Action: class (Monad m, Gettable f) => Effective m r f | f -> m r
+ Control.Lens.Internal.Action: effective :: Effective m r f => m r -> f a
+ Control.Lens.Internal.Action: getEffect :: Effect m r a -> m r
+ Control.Lens.Internal.Action: ineffective :: Effective m r f => f a -> m r
+ Control.Lens.Internal.Action: instance (Apply m, Semigroup r) => Apply (Effect m r)
+ Control.Lens.Internal.Action: instance (Apply m, Semigroup r) => Semigroup (Effect m r a)
+ Control.Lens.Internal.Action: instance (Monad m, Monoid r) => Applicative (Effect m r)
+ Control.Lens.Internal.Action: instance (Monad m, Monoid r) => Monoid (Effect m r a)
+ Control.Lens.Internal.Action: instance Effective Identity r (Accessor r)
+ Control.Lens.Internal.Action: instance Effective m r f => Effective m (Dual r) (Backwards f)
+ Control.Lens.Internal.Action: instance Functor (Effect m r)
+ Control.Lens.Internal.Action: instance Gettable (Effect m r)
+ Control.Lens.Internal.Action: instance Monad m => Effective m r (Effect m r)
+ Control.Lens.Internal.Action: newtype Effect m r a
+ Control.Lens.Internal.Bazaar: Bazaar :: (forall f. Applicative f => p a (f b) -> f t) -> Bazaar p a b t
+ Control.Lens.Internal.Bazaar: BazaarT :: (forall f. Applicative f => p a (f b) -> f t) -> BazaarT p a b t
+ Control.Lens.Internal.Bazaar: bazaar :: (Bizarre p w, Applicative f) => p a (f b) -> w a b t -> f t
+ Control.Lens.Internal.Bazaar: class Profunctor p => Bizarre p w | w -> p
+ Control.Lens.Internal.Bazaar: instance (Profunctor p, Gettable g) => Gettable (BazaarT p g a b)
+ Control.Lens.Internal.Bazaar: instance (a ~ b, Conjoined p) => Comonad (Bazaar p a b)
+ Control.Lens.Internal.Bazaar: instance (a ~ b, Conjoined p) => Comonad (BazaarT p g a b)
+ Control.Lens.Internal.Bazaar: instance (a ~ b, Conjoined p) => ComonadApply (Bazaar p a b)
+ Control.Lens.Internal.Bazaar: instance (a ~ b, Conjoined p) => ComonadApply (BazaarT p g a b)
+ Control.Lens.Internal.Bazaar: instance Applicative (Bazaar p a b)
+ Control.Lens.Internal.Bazaar: instance Applicative (BazaarT p g a b)
+ Control.Lens.Internal.Bazaar: instance Apply (Bazaar p a b)
+ Control.Lens.Internal.Bazaar: instance Apply (BazaarT p g a b)
+ Control.Lens.Internal.Bazaar: instance Conjoined p => IndexedComonad (Bazaar p)
+ Control.Lens.Internal.Bazaar: instance Conjoined p => IndexedComonad (BazaarT p g)
+ Control.Lens.Internal.Bazaar: instance Corepresentable p => Sellable p (Bazaar p)
+ Control.Lens.Internal.Bazaar: instance Corepresentable p => Sellable p (BazaarT p g)
+ Control.Lens.Internal.Bazaar: instance Functor (Bazaar p a b)
+ Control.Lens.Internal.Bazaar: instance Functor (BazaarT p g a b)
+ Control.Lens.Internal.Bazaar: instance IndexedFunctor (Bazaar p)
+ Control.Lens.Internal.Bazaar: instance IndexedFunctor (BazaarT p g)
+ Control.Lens.Internal.Bazaar: instance Profunctor p => Bizarre p (Bazaar p)
+ Control.Lens.Internal.Bazaar: instance Profunctor p => Bizarre p (BazaarT p g)
+ Control.Lens.Internal.Bazaar: newtype Bazaar p a b t
+ Control.Lens.Internal.Bazaar: newtype BazaarT p (g :: * -> *) a b t
+ Control.Lens.Internal.Bazaar: runBazaar :: Bazaar p a b t -> forall f. Applicative f => p a (f b) -> f t
+ Control.Lens.Internal.Bazaar: runBazaarT :: BazaarT p a b t -> forall f. Applicative f => p a (f b) -> f t
+ Control.Lens.Internal.Bazaar: type Bazaar' p a = Bazaar p a a
+ Control.Lens.Internal.Bazaar: type BazaarT' p g a = BazaarT p g a a
+ Control.Lens.Internal.ByteString: traversedLazy :: IndexedTraversal' Int64 ByteString Word8
+ Control.Lens.Internal.ByteString: traversedLazy8 :: IndexedTraversal' Int64 ByteString Char
+ Control.Lens.Internal.ByteString: traversedStrict :: Int -> IndexedTraversal' Int ByteString Word8
+ Control.Lens.Internal.ByteString: traversedStrict8 :: Int -> IndexedTraversal' Int ByteString Char
+ Control.Lens.Internal.ByteString: traversedStrictTree :: Int -> IndexedTraversal' Int ByteString Word8
+ Control.Lens.Internal.ByteString: traversedStrictTree8 :: Int -> IndexedTraversal' Int ByteString Char
+ Control.Lens.Internal.ByteString: unpackLazy :: ByteString -> [Word8]
+ Control.Lens.Internal.ByteString: unpackLazy8 :: ByteString -> String
+ Control.Lens.Internal.ByteString: unpackStrict :: ByteString -> [Word8]
+ Control.Lens.Internal.ByteString: unpackStrict8 :: ByteString -> String
+ Control.Lens.Internal.Context: Context :: (b -> t) -> a -> Context a b t
+ Control.Lens.Internal.Context: Pretext :: (forall f. Functor f => p a (f b) -> f t) -> Pretext p a b t
+ Control.Lens.Internal.Context: PretextT :: (forall f. Functor f => p a (f b) -> f t) -> PretextT p a b t
+ Control.Lens.Internal.Context: class IndexedFunctor w => IndexedComonad w where iduplicate = iextend id iextend f = ifmap f . iduplicate
+ Control.Lens.Internal.Context: class IndexedComonad w => IndexedComonadStore w where ipeek c = iextract . iseek c ipeeks f = iextract . iseeks f iexperiment bfc wbct = (`ipeek` wbct) <$> bfc (ipos wbct) context wabt = Context (`ipeek` wabt) (ipos wabt)
+ Control.Lens.Internal.Context: class IndexedFunctor w
+ Control.Lens.Internal.Context: class Corepresentable p => Sellable p w | w -> p
+ Control.Lens.Internal.Context: context :: IndexedComonadStore w => w a b t -> Context a b t
+ Control.Lens.Internal.Context: data Context a b t
+ Control.Lens.Internal.Context: iduplicate :: IndexedComonad w => w a c t -> w a b (w b c t)
+ Control.Lens.Internal.Context: iexperiment :: (IndexedComonadStore w, Functor f) => (b -> f c) -> w b c t -> f t
+ Control.Lens.Internal.Context: iextend :: IndexedComonad w => (w b c t -> r) -> w a c t -> w a b r
+ Control.Lens.Internal.Context: iextract :: IndexedComonad w => w a a t -> t
+ Control.Lens.Internal.Context: ifmap :: IndexedFunctor w => (s -> t) -> w a b s -> w a b t
+ Control.Lens.Internal.Context: instance (Profunctor p, Gettable g) => Gettable (PretextT p g a b)
+ Control.Lens.Internal.Context: instance (a ~ b, Conjoined p) => Comonad (Pretext p a b)
+ Control.Lens.Internal.Context: instance (a ~ b, Conjoined p) => Comonad (PretextT p g a b)
+ Control.Lens.Internal.Context: instance (a ~ b, Conjoined p) => ComonadStore a (Pretext p a b)
+ Control.Lens.Internal.Context: instance (a ~ b, Conjoined p) => ComonadStore a (PretextT p g a b)
+ Control.Lens.Internal.Context: instance Conjoined p => IndexedComonad (Pretext p)
+ Control.Lens.Internal.Context: instance Conjoined p => IndexedComonad (PretextT p g)
+ Control.Lens.Internal.Context: instance Conjoined p => IndexedComonadStore (Pretext p)
+ Control.Lens.Internal.Context: instance Conjoined p => IndexedComonadStore (PretextT p g)
+ Control.Lens.Internal.Context: instance Corepresentable p => Sellable p (Pretext p)
+ Control.Lens.Internal.Context: instance Corepresentable p => Sellable p (PretextT p g)
+ Control.Lens.Internal.Context: instance Functor (Context a b)
+ Control.Lens.Internal.Context: instance Functor (Pretext p a b)
+ Control.Lens.Internal.Context: instance Functor (PretextT p g a b)
+ Control.Lens.Internal.Context: instance IndexedComonad Context
+ Control.Lens.Internal.Context: instance IndexedComonadStore Context
+ Control.Lens.Internal.Context: instance IndexedFunctor (Pretext p)
+ Control.Lens.Internal.Context: instance IndexedFunctor (PretextT p g)
+ Control.Lens.Internal.Context: instance IndexedFunctor Context
+ Control.Lens.Internal.Context: instance Sellable (->) Context
+ Control.Lens.Internal.Context: instance a ~ b => Comonad (Context a b)
+ Control.Lens.Internal.Context: instance a ~ b => ComonadStore a (Context a b)
+ Control.Lens.Internal.Context: ipeek :: IndexedComonadStore w => c -> w a c t -> t
+ Control.Lens.Internal.Context: ipeeks :: IndexedComonadStore w => (a -> c) -> w a c t -> t
+ Control.Lens.Internal.Context: ipos :: IndexedComonadStore w => w a c t -> a
+ Control.Lens.Internal.Context: iseek :: IndexedComonadStore w => b -> w a c t -> w b c t
+ Control.Lens.Internal.Context: iseeks :: IndexedComonadStore w => (a -> b) -> w a c t -> w b c t
+ Control.Lens.Internal.Context: newtype Pretext p a b t
+ Control.Lens.Internal.Context: newtype PretextT p (g :: * -> *) a b t
+ Control.Lens.Internal.Context: runPretext :: Pretext p a b t -> forall f. Functor f => p a (f b) -> f t
+ Control.Lens.Internal.Context: runPretextT :: PretextT p a b t -> forall f. Functor f => p a (f b) -> f t
+ Control.Lens.Internal.Context: sell :: Sellable p w => p a (w a b b)
+ Control.Lens.Internal.Context: type Context' a = Context a a
+ Control.Lens.Internal.Context: type Pretext' p a = Pretext p a a
+ Control.Lens.Internal.Context: type PretextT' p g a = PretextT p g a a
+ Control.Lens.Internal.Deque: BD :: !Int -> [a] -> !Int -> [a] -> Deque a
+ Control.Lens.Internal.Deque: data Deque a
+ Control.Lens.Internal.Deque: fromList :: [a] -> Deque a
+ Control.Lens.Internal.Deque: instance (Choice p, Applicative f) => Cons p f (Deque a) (Deque b) a b
+ Control.Lens.Internal.Deque: instance (Choice p, Applicative f) => Snoc p f (Deque a) (Deque b) a b
+ Control.Lens.Internal.Deque: instance Alt Deque
+ Control.Lens.Internal.Deque: instance Alternative Deque
+ Control.Lens.Internal.Deque: instance Applicative Deque
+ Control.Lens.Internal.Deque: instance Apply Deque
+ Control.Lens.Internal.Deque: instance Bind Deque
+ Control.Lens.Internal.Deque: instance Eq a => Eq (Deque a)
+ Control.Lens.Internal.Deque: instance Foldable Deque
+ Control.Lens.Internal.Deque: instance FoldableWithIndex Int Deque
+ Control.Lens.Internal.Deque: instance Functor Deque
+ Control.Lens.Internal.Deque: instance FunctorWithIndex Int Deque
+ Control.Lens.Internal.Deque: instance Monad Deque
+ Control.Lens.Internal.Deque: instance MonadPlus Deque
+ Control.Lens.Internal.Deque: instance Monoid (Deque a)
+ Control.Lens.Internal.Deque: instance Ord a => Ord (Deque a)
+ Control.Lens.Internal.Deque: instance Plus Deque
+ Control.Lens.Internal.Deque: instance Semigroup (Deque a)
+ Control.Lens.Internal.Deque: instance Show a => Show (Deque a)
+ Control.Lens.Internal.Deque: instance Traversable Deque
+ Control.Lens.Internal.Deque: instance TraversableWithIndex Int Deque
+ Control.Lens.Internal.Deque: null :: Deque a -> Bool
+ Control.Lens.Internal.Deque: singleton :: a -> Deque a
+ Control.Lens.Internal.Deque: size :: Deque a -> Int
+ Control.Lens.Internal.Fold: Folding :: f a -> Folding f a
+ Control.Lens.Internal.Fold: LLeaf :: a -> Leftmost a
+ Control.Lens.Internal.Fold: LPure :: Leftmost a
+ Control.Lens.Internal.Fold: LStep :: (Leftmost a) -> Leftmost a
+ Control.Lens.Internal.Fold: Max :: a -> Max a
+ Control.Lens.Internal.Fold: Min :: a -> Min a
+ Control.Lens.Internal.Fold: NoMax :: Max a
+ Control.Lens.Internal.Fold: NoMin :: Min a
+ Control.Lens.Internal.Fold: RLeaf :: a -> Rightmost a
+ Control.Lens.Internal.Fold: RPure :: Rightmost a
+ Control.Lens.Internal.Fold: RStep :: (Rightmost a) -> Rightmost a
+ Control.Lens.Internal.Fold: Sequenced :: m a -> Sequenced a m
+ Control.Lens.Internal.Fold: Traversed :: f a -> Traversed a f
+ Control.Lens.Internal.Fold: data Leftmost a
+ Control.Lens.Internal.Fold: data Max a
+ Control.Lens.Internal.Fold: data Min a
+ Control.Lens.Internal.Fold: data Rightmost a
+ Control.Lens.Internal.Fold: getFolding :: Folding f a -> f a
+ Control.Lens.Internal.Fold: getLeftmost :: Leftmost a -> Maybe a
+ Control.Lens.Internal.Fold: getMax :: Max a -> Maybe a
+ Control.Lens.Internal.Fold: getMin :: Min a -> Maybe a
+ Control.Lens.Internal.Fold: getRightmost :: Rightmost a -> Maybe a
+ Control.Lens.Internal.Fold: getSequenced :: Sequenced a m -> m a
+ Control.Lens.Internal.Fold: getTraversed :: Traversed a f -> f a
+ Control.Lens.Internal.Fold: instance (Gettable f, Applicative f) => Monoid (Folding f a)
+ Control.Lens.Internal.Fold: instance (Gettable f, Apply f) => Semigroup (Folding f a)
+ Control.Lens.Internal.Fold: instance Applicative f => Monoid (Traversed a f)
+ Control.Lens.Internal.Fold: instance Apply f => Semigroup (Traversed a f)
+ Control.Lens.Internal.Fold: instance Apply m => Semigroup (Sequenced a m)
+ Control.Lens.Internal.Fold: instance Monad m => Monoid (Sequenced a m)
+ Control.Lens.Internal.Fold: instance Monoid (Leftmost a)
+ Control.Lens.Internal.Fold: instance Monoid (Rightmost a)
+ Control.Lens.Internal.Fold: instance Ord a => Monoid (Max a)
+ Control.Lens.Internal.Fold: instance Ord a => Monoid (Min a)
+ Control.Lens.Internal.Fold: instance Ord a => Semigroup (Max a)
+ Control.Lens.Internal.Fold: instance Ord a => Semigroup (Min a)
+ Control.Lens.Internal.Fold: instance Semigroup (Leftmost a)
+ Control.Lens.Internal.Fold: instance Semigroup (Rightmost a)
+ Control.Lens.Internal.Fold: newtype Folding f a
+ Control.Lens.Internal.Fold: newtype Sequenced a m
+ Control.Lens.Internal.Fold: newtype Traversed a f
+ Control.Lens.Internal.Getter: Accessor :: r -> Accessor r a
+ Control.Lens.Internal.Getter: class Functor f => Gettable f
+ Control.Lens.Internal.Getter: coerce :: Gettable f => f a -> f b
+ Control.Lens.Internal.Getter: instance (Functor f, Gettable g) => Gettable (Compose f g)
+ Control.Lens.Internal.Getter: instance Functor (Accessor r)
+ Control.Lens.Internal.Getter: instance Gettable (Accessor r)
+ Control.Lens.Internal.Getter: instance Gettable (Const r)
+ Control.Lens.Internal.Getter: instance Gettable f => Gettable (Backwards f)
+ Control.Lens.Internal.Getter: instance Monoid r => Applicative (Accessor r)
+ Control.Lens.Internal.Getter: instance Semigroup r => Apply (Accessor r)
+ Control.Lens.Internal.Getter: newtype Accessor r a
+ Control.Lens.Internal.Getter: noEffect :: (Applicative f, Gettable f) => f a
+ Control.Lens.Internal.Getter: runAccessor :: Accessor r a -> r
+ Control.Lens.Internal.Indexed: Indexed :: (i -> a -> b) -> Indexed i a b
+ Control.Lens.Internal.Indexed: Indexing :: (Int -> (Int, f a)) -> Indexing f a
+ Control.Lens.Internal.Indexed: Indexing64 :: (Int64 -> (Int64, f a)) -> Indexing64 f a
+ Control.Lens.Internal.Indexed: class (Profunctor p, Choice p, Strong p, Corepresentable p, Comonad (Corep p), Traversable (Corep p), Representable p, Monad (Rep p), MonadFix (Rep p), Distributive (Rep p), ArrowLoop p, ArrowApply p, ArrowChoice p) => Conjoined p where distrib = tabulate . collect . rep conjoined _ r = r
+ Control.Lens.Internal.Indexed: class Conjoined p => Indexable i p
+ Control.Lens.Internal.Indexed: conjoined :: Conjoined p => (p ~ (->) => q (a -> b) r) -> q (p a b) r -> q (p a b) r
+ Control.Lens.Internal.Indexed: distrib :: (Conjoined p, Functor f) => p a b -> p (f a) (f b)
+ Control.Lens.Internal.Indexed: indexed :: Indexable i p => p a b -> i -> a -> b
+ Control.Lens.Internal.Indexed: indexing :: Indexable Int p => ((a -> Indexing f b) -> s -> Indexing f t) -> p a (f b) -> s -> f t
+ Control.Lens.Internal.Indexed: indexing64 :: Indexable Int64 p => ((a -> Indexing64 f b) -> s -> Indexing64 f t) -> p a (f b) -> s -> f t
+ Control.Lens.Internal.Indexed: instance Applicative (Indexed i a)
+ Control.Lens.Internal.Indexed: instance Applicative f => Applicative (Indexing f)
+ Control.Lens.Internal.Indexed: instance Applicative f => Applicative (Indexing64 f)
+ Control.Lens.Internal.Indexed: instance Apply (Indexed i a)
+ Control.Lens.Internal.Indexed: instance Apply f => Apply (Indexing f)
+ Control.Lens.Internal.Indexed: instance Apply f => Apply (Indexing64 f)
+ Control.Lens.Internal.Indexed: instance Arrow (Indexed i)
+ Control.Lens.Internal.Indexed: instance ArrowApply (Indexed i)
+ Control.Lens.Internal.Indexed: instance ArrowChoice (Indexed i)
+ Control.Lens.Internal.Indexed: instance ArrowLoop (Indexed i)
+ Control.Lens.Internal.Indexed: instance Bind (Indexed i a)
+ Control.Lens.Internal.Indexed: instance Category (Indexed i)
+ Control.Lens.Internal.Indexed: instance Choice (Indexed i)
+ Control.Lens.Internal.Indexed: instance Conjoined (->)
+ Control.Lens.Internal.Indexed: instance Conjoined (Indexed i)
+ Control.Lens.Internal.Indexed: instance Corepresentable (Indexed i)
+ Control.Lens.Internal.Indexed: instance Functor (Indexed i a)
+ Control.Lens.Internal.Indexed: instance Functor f => Functor (Indexing f)
+ Control.Lens.Internal.Indexed: instance Functor f => Functor (Indexing64 f)
+ Control.Lens.Internal.Indexed: instance Gettable f => Gettable (Indexing f)
+ Control.Lens.Internal.Indexed: instance Gettable f => Gettable (Indexing64 f)
+ Control.Lens.Internal.Indexed: instance Indexable i (->)
+ Control.Lens.Internal.Indexed: instance Monad (Indexed i a)
+ Control.Lens.Internal.Indexed: instance MonadFix (Indexed i a)
+ Control.Lens.Internal.Indexed: instance Profunctor (Indexed i)
+ Control.Lens.Internal.Indexed: instance Representable (Indexed i)
+ Control.Lens.Internal.Indexed: instance Strong (Indexed i)
+ Control.Lens.Internal.Indexed: instance i ~ j => Indexable i (Indexed j)
+ Control.Lens.Internal.Indexed: newtype Indexed i a b
+ Control.Lens.Internal.Indexed: newtype Indexing f a
+ Control.Lens.Internal.Indexed: newtype Indexing64 f a
+ Control.Lens.Internal.Indexed: runIndexed :: Indexed i a b -> i -> a -> b
+ Control.Lens.Internal.Indexed: runIndexing :: Indexing f a -> Int -> (Int, f a)
+ Control.Lens.Internal.Indexed: runIndexing64 :: Indexing64 f a -> Int64 -> (Int64, f a)
+ Control.Lens.Internal.Instances: instance Foldable ((,) b)
+ Control.Lens.Internal.Instances: instance Foldable (Const m)
+ Control.Lens.Internal.Instances: instance Foldable (Either a)
+ Control.Lens.Internal.Instances: instance Foldable1 ((,) b)
+ Control.Lens.Internal.Instances: instance Traversable ((,) b)
+ Control.Lens.Internal.Instances: instance Traversable (Const m)
+ Control.Lens.Internal.Instances: instance Traversable (Either a)
+ Control.Lens.Internal.Instances: instance Traversable1 ((,) b)
+ Control.Lens.Internal.Iso: Exchange :: (s -> a) -> (b -> t) -> Exchange a b s t
+ Control.Lens.Internal.Iso: data Exchange a b s t
+ Control.Lens.Internal.Iso: instance Functor (Exchange a b s)
+ Control.Lens.Internal.Iso: instance Profunctor (Exchange a b)
+ Control.Lens.Internal.Level: Deepening :: (forall r. Int -> (Level i a -> Bool -> r) -> r) -> Deepening i a
+ Control.Lens.Internal.Level: Flows :: ([Level i b] -> a) -> Flows i b a
+ Control.Lens.Internal.Level: One :: i -> a -> Level i a
+ Control.Lens.Internal.Level: Two :: {-# UNPACK #-} !Word -> !(Level i a) -> !(Level i a) -> Level i a
+ Control.Lens.Internal.Level: Zero :: Level i a
+ Control.Lens.Internal.Level: data Level i a
+ Control.Lens.Internal.Level: deepening :: i -> a -> Deepening i a
+ Control.Lens.Internal.Level: instance (Eq i, Eq a) => Eq (Level i a)
+ Control.Lens.Internal.Level: instance (Ord i, Ord a) => Ord (Level i a)
+ Control.Lens.Internal.Level: instance (Read i, Read a) => Read (Level i a)
+ Control.Lens.Internal.Level: instance (Show i, Show a) => Show (Level i a)
+ Control.Lens.Internal.Level: instance Applicative (Flows i b)
+ Control.Lens.Internal.Level: instance Apply (Flows i b)
+ Control.Lens.Internal.Level: instance Foldable (Level i)
+ Control.Lens.Internal.Level: instance Functor (Flows i b)
+ Control.Lens.Internal.Level: instance Functor (Level i)
+ Control.Lens.Internal.Level: instance Monoid (Deepening i a)
+ Control.Lens.Internal.Level: instance Semigroup (Deepening i a)
+ Control.Lens.Internal.Level: instance Traversable (Level i)
+ Control.Lens.Internal.Level: newtype Deepening i a
+ Control.Lens.Internal.Level: newtype Flows i b a
+ Control.Lens.Internal.Level: runDeepening :: Deepening i a -> forall r. Int -> (Level i a -> Bool -> r) -> r
+ Control.Lens.Internal.Level: runFlows :: Flows i b a -> [Level i b] -> a
+ Control.Lens.Internal.Magma: Mafic :: Int -> (Int -> Magma Int t b a) -> Mafic a b t
+ Control.Lens.Internal.Magma: Magma :: i -> a -> Magma i b b a
+ Control.Lens.Internal.Magma: MagmaAp :: Magma i (x -> y) b a -> Magma i x b a -> Magma i y b a
+ Control.Lens.Internal.Magma: MagmaFmap :: (x -> y) -> Magma i x b a -> Magma i y b a
+ Control.Lens.Internal.Magma: MagmaPure :: x -> Magma i x b a
+ Control.Lens.Internal.Magma: Molten :: Magma i t b a -> Molten i a b t
+ Control.Lens.Internal.Magma: TakingWhile :: Bool -> t -> (Bool -> Magma () t b (Corep p a)) -> TakingWhile p a b t
+ Control.Lens.Internal.Magma: data Mafic a b t
+ Control.Lens.Internal.Magma: data Magma i t b a
+ Control.Lens.Internal.Magma: data TakingWhile p (g :: * -> *) a b t
+ Control.Lens.Internal.Magma: instance (Show i, Show a) => Show (Magma i t b a)
+ Control.Lens.Internal.Magma: instance Applicative (Mafic a b)
+ Control.Lens.Internal.Magma: instance Applicative (Molten i a b)
+ Control.Lens.Internal.Magma: instance Applicative (TakingWhile p f a b)
+ Control.Lens.Internal.Magma: instance Apply (Mafic a b)
+ Control.Lens.Internal.Magma: instance Apply (Molten i a b)
+ Control.Lens.Internal.Magma: instance Apply (TakingWhile p f a b)
+ Control.Lens.Internal.Magma: instance Bizarre (Indexed Int) Mafic
+ Control.Lens.Internal.Magma: instance Bizarre (Indexed i) (Molten i)
+ Control.Lens.Internal.Magma: instance Corepresentable p => Bizarre p (TakingWhile p g)
+ Control.Lens.Internal.Magma: instance Foldable (Magma i t b)
+ Control.Lens.Internal.Magma: instance Functor (Mafic a b)
+ Control.Lens.Internal.Magma: instance Functor (Magma i t b)
+ Control.Lens.Internal.Magma: instance Functor (Molten i a b)
+ Control.Lens.Internal.Magma: instance Functor (TakingWhile p f a b)
+ Control.Lens.Internal.Magma: instance Gettable f => Gettable (TakingWhile p f a b)
+ Control.Lens.Internal.Magma: instance IndexedComonad (Molten i)
+ Control.Lens.Internal.Magma: instance IndexedFunctor (Molten i)
+ Control.Lens.Internal.Magma: instance IndexedFunctor (TakingWhile p f)
+ Control.Lens.Internal.Magma: instance IndexedFunctor Mafic
+ Control.Lens.Internal.Magma: instance Sellable (->) Mafic
+ Control.Lens.Internal.Magma: instance Sellable (Indexed i) (Molten i)
+ Control.Lens.Internal.Magma: instance Traversable (Magma i t b)
+ Control.Lens.Internal.Magma: instance a ~ b => Comonad (Molten i a b)
+ Control.Lens.Internal.Magma: newtype Molten i a b t
+ Control.Lens.Internal.Magma: runMafic :: Mafic a b t -> Magma Int t b a
+ Control.Lens.Internal.Magma: runMagma :: Magma i t a a -> t
+ Control.Lens.Internal.Magma: runMolten :: Molten i a b t -> Magma i t b a
+ Control.Lens.Internal.Magma: runTakingWhile :: Corepresentable p => TakingWhile p f a b t -> Magma () t b (Corep p a)
+ Control.Lens.Internal.Prism: Market :: (b -> t) -> (s -> Either t a) -> Market a b s t
+ Control.Lens.Internal.Prism: data Market a b s t
+ Control.Lens.Internal.Prism: instance Choice (Market a b)
+ Control.Lens.Internal.Prism: instance Functor (Market a b s)
+ Control.Lens.Internal.Prism: instance Profunctor (Market a b)
+ Control.Lens.Internal.Prism: type Market' a = Market a a
+ Control.Lens.Internal.Review: Reviewed :: b -> Reviewed a b
+ Control.Lens.Internal.Review: class Profunctor p => Reviewable p
+ Control.Lens.Internal.Review: instance Applicative (Reviewed a)
+ Control.Lens.Internal.Review: instance Apply (Reviewed a)
+ Control.Lens.Internal.Review: instance Bifoldable Reviewed
+ Control.Lens.Internal.Review: instance Bifunctor Reviewed
+ Control.Lens.Internal.Review: instance Bind (Reviewed a)
+ Control.Lens.Internal.Review: instance Bitraversable Reviewed
+ Control.Lens.Internal.Review: instance Choice Reviewed
+ Control.Lens.Internal.Review: instance Comonad (Reviewed a)
+ Control.Lens.Internal.Review: instance ComonadApply (Reviewed a)
+ Control.Lens.Internal.Review: instance Corepresentable Reviewed
+ Control.Lens.Internal.Review: instance Distributive (Reviewed a)
+ Control.Lens.Internal.Review: instance Foldable (Reviewed a)
+ Control.Lens.Internal.Review: instance Functor (Reviewed a)
+ Control.Lens.Internal.Review: instance Monad (Reviewed a)
+ Control.Lens.Internal.Review: instance MonadFix (Reviewed a)
+ Control.Lens.Internal.Review: instance Profunctor Reviewed
+ Control.Lens.Internal.Review: instance Reviewable (Tagged *)
+ Control.Lens.Internal.Review: instance Reviewable Reviewed
+ Control.Lens.Internal.Review: instance Traversable (Reviewed a)
+ Control.Lens.Internal.Review: newtype Reviewed a b
+ Control.Lens.Internal.Review: retagged :: Reviewable p => p a b -> p s b
+ Control.Lens.Internal.Review: runReviewed :: Reviewed a b -> b
+ Control.Lens.Internal.Setter: Mutator :: a -> Mutator a
+ Control.Lens.Internal.Setter: class (Applicative f, Distributive f, Traversable f) => Settable f where untaintedDot g = g `seq` rmap untainted g taintedDot g = g `seq` rmap pure g
+ Control.Lens.Internal.Setter: instance (Settable f, Settable g) => Settable (Compose f g)
+ Control.Lens.Internal.Setter: instance Applicative Mutator
+ Control.Lens.Internal.Setter: instance Apply Mutator
+ Control.Lens.Internal.Setter: instance Bind Mutator
+ Control.Lens.Internal.Setter: instance Comonad Mutator
+ Control.Lens.Internal.Setter: instance ComonadApply Mutator
+ Control.Lens.Internal.Setter: instance Distributive Mutator
+ Control.Lens.Internal.Setter: instance Foldable Mutator
+ Control.Lens.Internal.Setter: instance Functor Mutator
+ Control.Lens.Internal.Setter: instance Monad Mutator
+ Control.Lens.Internal.Setter: instance Settable Identity
+ Control.Lens.Internal.Setter: instance Settable Mutator
+ Control.Lens.Internal.Setter: instance Settable f => Settable (Backwards f)
+ Control.Lens.Internal.Setter: instance Traversable Mutator
+ Control.Lens.Internal.Setter: newtype Mutator a
+ Control.Lens.Internal.Setter: runMutator :: Mutator a -> a
+ Control.Lens.Internal.Setter: taintedDot :: (Settable f, Profunctor p) => p a b -> p a (f b)
+ Control.Lens.Internal.Setter: untainted :: Settable f => f a -> a
+ Control.Lens.Internal.Setter: untaintedDot :: (Settable f, Profunctor p) => p a (f b) -> p a b
+ Control.Lens.Internal.Zipper: Ap :: Int -> Bool -> Bool -> (Last i) -> (Jacket i a) -> (Jacket i a) -> Jacket i a
+ Control.Lens.Internal.Zipper: ApL :: Int -> Bool -> Bool -> (Last i) -> !(Path i a) -> !(Jacket i a) -> Path i a
+ Control.Lens.Internal.Zipper: ApR :: Int -> Bool -> Bool -> (Last i) -> !(Jacket i a) -> !(Path i a) -> Path i a
+ Control.Lens.Internal.Zipper: Flow :: (Jacket i b -> a) -> Flow i b a
+ Control.Lens.Internal.Zipper: Leaf :: i -> a -> Jacket i a
+ Control.Lens.Internal.Zipper: Pure :: Jacket i a
+ Control.Lens.Internal.Zipper: Start :: Path i a
+ Control.Lens.Internal.Zipper: data Jacket i a
+ Control.Lens.Internal.Zipper: data Path i a
+ Control.Lens.Internal.Zipper: data Zipper h i a
+ Control.Lens.Internal.Zipper: focalPoint :: Zipper h i a -> i
+ Control.Lens.Internal.Zipper: idownward :: Ord i => AnIndexedLens' i s a -> h :> (s :@ j) -> (h :> (s :@ j)) :> (a :@ i)
+ Control.Lens.Internal.Zipper: ifromWithin :: Ord i => AnIndexedTraversal' i s a -> (h :> (s :@ j)) -> (h :> (s :@ j)) :> (a :@ i)
+ Control.Lens.Internal.Zipper: instance (Show i, Show a) => Show (Jacket i a)
+ Control.Lens.Internal.Zipper: instance (Show i, Show a) => Show (Path i a)
+ Control.Lens.Internal.Zipper: instance Applicative (Flow i b)
+ Control.Lens.Internal.Zipper: instance Apply (Flow i b)
+ Control.Lens.Internal.Zipper: instance Foldable (Jacket i)
+ Control.Lens.Internal.Zipper: instance FoldableWithIndex i (Jacket i)
+ Control.Lens.Internal.Zipper: instance Functor (Flow i b)
+ Control.Lens.Internal.Zipper: instance Functor (Jacket i)
+ Control.Lens.Internal.Zipper: instance Functor (Path i)
+ Control.Lens.Internal.Zipper: instance FunctorWithIndex i (Jacket i)
+ Control.Lens.Internal.Zipper: instance Monoid (Jacket i a)
+ Control.Lens.Internal.Zipper: instance Traversable (Jacket i)
+ Control.Lens.Internal.Zipper: instance TraversableWithIndex i (Jacket i)
+ Control.Lens.Internal.Zipper: instance Zipping h s => Zipping (Zipper h i s) a
+ Control.Lens.Internal.Zipper: iwithin :: (MonadPlus m, Ord i) => AnIndexedTraversal' i s a -> (h :> (s :@ j)) -> m ((h :> (s :@ j)) :> (a :@ i))
+ Control.Lens.Internal.Zipper: iwithins :: (MonadPlus m, Ord i) => AnIndexedTraversal' i s a -> (h :> (s :@ j)) -> m ((h :> (s :@ j)) :> (a :@ i))
+ Control.Lens.Internal.Zipper: jacket :: AnIndexedTraversal i s t a b -> Lens s t (Jacket i a) (Jacket j b)
+ Control.Lens.Internal.Zipper: jacketIns :: Bazaar (Indexed i) a b t -> Jacket i a
+ Control.Lens.Internal.Zipper: jacketOuts :: Bazaar (Indexed i) a b t -> Jacket j b -> t
+ Control.Lens.Internal.Zipper: lensed :: ALens' s a -> IndexedLens' Int s a
+ Control.Lens.Internal.Zipper: maximal :: Jacket i a -> Last i
+ Control.Lens.Internal.Zipper: moveTo :: MonadPlus m => i -> h :> (a :@ i) -> m (h :> (a :@ i))
+ Control.Lens.Internal.Zipper: moveToward :: i -> h :> (a :@ i) -> h :> (a :@ i)
+ Control.Lens.Internal.Zipper: movel :: Path i a -> Jacket i a -> r -> (Path i a -> i -> a -> r) -> r
+ Control.Lens.Internal.Zipper: mover :: Path i a -> Jacket i a -> r -> (Path i a -> i -> a -> r) -> r
+ Control.Lens.Internal.Zipper: newtype Flow i b a
+ Control.Lens.Internal.Zipper: nullLeft :: Jacket i a -> Bool
+ Control.Lens.Internal.Zipper: nullRight :: Jacket i a -> Bool
+ Control.Lens.Internal.Zipper: offset :: Path i a -> Int
+ Control.Lens.Internal.Zipper: pathsize :: Path i a -> Int
+ Control.Lens.Internal.Zipper: recompress :: Path i a -> i -> a -> Jacket i a
+ Control.Lens.Internal.Zipper: runFlow :: Flow i b a -> Jacket i b -> a
+ Control.Lens.Internal.Zipper: size :: Jacket i a -> Int
+ Control.Lens.Internal.Zipper: startl :: Path i a -> Jacket i a -> r -> (Path i a -> i -> a -> r) -> r
+ Control.Lens.Internal.Zipper: startr :: Path i a -> Jacket i a -> r -> (Path i a -> i -> a -> r) -> r
+ Control.Lens.Internal.Zipper: type (:>>) h a = Zipper h Int a
+ Control.Lens.Internal.Zoom: EffectRWS :: (st -> m (s, st, w)) -> EffectRWS w st m s a
+ Control.Lens.Internal.Zoom: Err :: Either e a -> Err e a
+ Control.Lens.Internal.Zoom: Focusing :: m (s, a) -> Focusing m s a
+ Control.Lens.Internal.Zoom: FocusingErr :: k (Err e s) a -> FocusingErr e k s a
+ Control.Lens.Internal.Zoom: FocusingMay :: k (May s) a -> FocusingMay k s a
+ Control.Lens.Internal.Zoom: FocusingOn :: k (f s) a -> FocusingOn f k s a
+ Control.Lens.Internal.Zoom: FocusingPlus :: k (s, w) a -> FocusingPlus w k s a
+ Control.Lens.Internal.Zoom: FocusingWith :: m (s, a, w) -> FocusingWith w m s a
+ Control.Lens.Internal.Zoom: May :: Maybe a -> May a
+ Control.Lens.Internal.Zoom: getEffectRWS :: EffectRWS w st m s a -> st -> m (s, st, w)
+ Control.Lens.Internal.Zoom: getErr :: Err e a -> Either e a
+ Control.Lens.Internal.Zoom: getMay :: May a -> Maybe a
+ Control.Lens.Internal.Zoom: instance (Monad m, Monoid s) => Applicative (Focusing m s)
+ Control.Lens.Internal.Zoom: instance (Monad m, Monoid s, Monoid w) => Applicative (FocusingWith w m s)
+ Control.Lens.Internal.Zoom: instance (Monad m, Semigroup s) => Apply (Focusing m s)
+ Control.Lens.Internal.Zoom: instance (Monad m, Semigroup s, Semigroup w) => Apply (FocusingWith w m s)
+ Control.Lens.Internal.Zoom: instance (Monoid s, Monoid w, Monad m) => Applicative (EffectRWS w st m s)
+ Control.Lens.Internal.Zoom: instance (Semigroup s, Semigroup w, Bind m) => Apply (EffectRWS w st m s)
+ Control.Lens.Internal.Zoom: instance Applicative (k (Err e s)) => Applicative (FocusingErr e k s)
+ Control.Lens.Internal.Zoom: instance Applicative (k (May s)) => Applicative (FocusingMay k s)
+ Control.Lens.Internal.Zoom: instance Applicative (k (f s)) => Applicative (FocusingOn f k s)
+ Control.Lens.Internal.Zoom: instance Applicative (k (s, w)) => Applicative (FocusingPlus w k s)
+ Control.Lens.Internal.Zoom: instance Apply (k (Err e s)) => Apply (FocusingErr e k s)
+ Control.Lens.Internal.Zoom: instance Apply (k (May s)) => Apply (FocusingMay k s)
+ Control.Lens.Internal.Zoom: instance Apply (k (f s)) => Apply (FocusingOn f k s)
+ Control.Lens.Internal.Zoom: instance Apply (k (s, w)) => Apply (FocusingPlus w k s)
+ Control.Lens.Internal.Zoom: instance Functor (EffectRWS w st m s)
+ Control.Lens.Internal.Zoom: instance Functor (k (Err e s)) => Functor (FocusingErr e k s)
+ Control.Lens.Internal.Zoom: instance Functor (k (May s)) => Functor (FocusingMay k s)
+ Control.Lens.Internal.Zoom: instance Functor (k (f s)) => Functor (FocusingOn f k s)
+ Control.Lens.Internal.Zoom: instance Functor (k (s, w)) => Functor (FocusingPlus w k s)
+ Control.Lens.Internal.Zoom: instance Gettable (EffectRWS w st m s)
+ Control.Lens.Internal.Zoom: instance Monad m => Functor (Focusing m s)
+ Control.Lens.Internal.Zoom: instance Monad m => Functor (FocusingWith w m s)
+ Control.Lens.Internal.Zoom: instance Monoid a => Monoid (Err e a)
+ Control.Lens.Internal.Zoom: instance Monoid a => Monoid (May a)
+ Control.Lens.Internal.Zoom: instance Semigroup a => Semigroup (Err e a)
+ Control.Lens.Internal.Zoom: instance Semigroup a => Semigroup (May a)
+ Control.Lens.Internal.Zoom: newtype EffectRWS w st m s a
+ Control.Lens.Internal.Zoom: newtype Err e a
+ Control.Lens.Internal.Zoom: newtype Focusing m s a
+ Control.Lens.Internal.Zoom: newtype FocusingErr e k s a
+ Control.Lens.Internal.Zoom: newtype FocusingMay k s a
+ Control.Lens.Internal.Zoom: newtype FocusingOn f k s a
+ Control.Lens.Internal.Zoom: newtype FocusingPlus w k s a
+ Control.Lens.Internal.Zoom: newtype FocusingWith w m s a
+ Control.Lens.Internal.Zoom: newtype May a
+ Control.Lens.Internal.Zoom: unfocusing :: Focusing m s a -> m (s, a)
+ Control.Lens.Internal.Zoom: unfocusingErr :: FocusingErr e k s a -> k (Err e s) a
+ Control.Lens.Internal.Zoom: unfocusingMay :: FocusingMay k s a -> k (May s) a
+ Control.Lens.Internal.Zoom: unfocusingOn :: FocusingOn f k s a -> k (f s) a
+ Control.Lens.Internal.Zoom: unfocusingPlus :: FocusingPlus w k s a -> k (s, w) a
+ Control.Lens.Internal.Zoom: unfocusingWith :: FocusingWith w m s a -> m (s, a, w)
+ Control.Lens.Iso: class Profunctor (p :: * -> * -> *)
+ Control.Lens.Iso: class Bifunctor p => Swapped p
+ Control.Lens.Iso: data Magma i t b a
+ Control.Lens.Iso: dimap :: Profunctor p => (a -> b) -> (c -> d) -> p b c -> p a d
+ Control.Lens.Iso: flipped :: Iso (a -> b -> c) (a' -> b' -> c') (b -> a -> c) (b' -> a' -> c')
+ Control.Lens.Iso: imagma :: Overloading (Indexed i) (->) (Molten i a b) s t a b -> Iso s t' (Magma i t b a) (Magma j t' c c)
+ Control.Lens.Iso: instance Strict ByteString ByteString
+ Control.Lens.Iso: instance Strict Text Text
+ Control.Lens.Iso: instance Swapped (,)
+ Control.Lens.Iso: instance Swapped Either
+ Control.Lens.Iso: lmap :: Profunctor p => (a -> b) -> p b c -> p a c
+ Control.Lens.Iso: magma :: LensLike (Mafic a b) s t a b -> Iso s u (Magma Int t b a) (Magma j u c c)
+ Control.Lens.Iso: rmap :: Profunctor p => (b -> c) -> p a b -> p a c
+ Control.Lens.Iso: swapped :: Swapped p => Iso (p a b) (p c d) (p b a) (p d c)
+ Control.Lens.Iso: type AnIso' s a = AnIso s s a a
+ Control.Lens.Iso: type Iso' s a = Iso s s a a
+ Control.Lens.Iso: type Iso s t a b = forall p f. (Profunctor p, Functor f) => p a (f b) -> p s (f t)
+ Control.Lens.Lens: (#%%=) :: MonadState s m => ALens s s a b -> (a -> (r, b)) -> m r
+ Control.Lens.Lens: (#%%~) :: Functor f => ALens s t a b -> (a -> f b) -> s -> f t
+ Control.Lens.Lens: (#%=) :: MonadState s m => ALens s s a b -> (a -> b) -> m ()
+ Control.Lens.Lens: (#%~) :: ALens s t a b -> (a -> b) -> s -> t
+ Control.Lens.Lens: (#=) :: MonadState s m => ALens s s a b -> b -> m ()
+ Control.Lens.Lens: (#~) :: ALens s t a b -> b -> s -> t
+ Control.Lens.Lens: (%%=) :: MonadState s m => Overloading p (->) ((,) r) s s a b -> p a (r, b) -> m r
+ Control.Lens.Lens: (%%@=) :: MonadState s m => IndexedLensLike i ((,) r) s s a b -> (i -> a -> (r, b)) -> m r
+ Control.Lens.Lens: (%%@~) :: IndexedLensLike i f s t a b -> (i -> a -> f b) -> s -> f t
+ Control.Lens.Lens: (%%~) :: Overloading p q f s t a b -> p a (f b) -> q s (f t)
+ Control.Lens.Lens: (<#%=) :: MonadState s m => ALens s s a b -> (a -> b) -> m b
+ Control.Lens.Lens: (<#%~) :: ALens s t a b -> (a -> b) -> s -> (b, t)
+ Control.Lens.Lens: (<#=) :: MonadState s m => ALens s s a b -> b -> m b
+ Control.Lens.Lens: (<#~) :: ALens s t a b -> b -> s -> (b, t)
+ Control.Lens.Lens: (<%=) :: (Profunctor p, MonadState s m) => Overloading p (->) ((,) b) s s a b -> p a b -> m b
+ Control.Lens.Lens: (<%@=) :: MonadState s m => IndexedLensLike i ((,) b) s s a b -> (i -> a -> b) -> m b
+ Control.Lens.Lens: (<%@~) :: Overloading (Indexed i) q ((,) b) s t a b -> (i -> a -> b) -> q s (b, t)
+ Control.Lens.Lens: (<%~) :: Profunctor p => Overloading p q ((,) b) s t a b -> p a b -> q s (b, t)
+ Control.Lens.Lens: (<&&=) :: MonadState s m => LensLike' ((,) Bool) s Bool -> Bool -> m Bool
+ Control.Lens.Lens: (<&&~) :: Overloading (->) q ((,) Bool) s t Bool Bool -> Bool -> q s (Bool, t)
+ Control.Lens.Lens: (<**=) :: (MonadState s m, Floating a) => LensLike' ((,) a) s a -> a -> m a
+ Control.Lens.Lens: (<**~) :: Floating a => Overloading (->) q ((,) a) s t a a -> a -> q s (a, t)
+ Control.Lens.Lens: (<*=) :: (MonadState s m, Num a) => LensLike' ((,) a) s a -> a -> m a
+ Control.Lens.Lens: (<*~) :: Num a => Overloading (->) q ((,) a) s t a a -> a -> q s (a, t)
+ Control.Lens.Lens: (<+=) :: (MonadState s m, Num a) => LensLike' ((,) a) s a -> a -> m a
+ Control.Lens.Lens: (<+~) :: Num a => Overloading (->) q ((,) a) s t a a -> a -> q s (a, t)
+ Control.Lens.Lens: (<-=) :: (MonadState s m, Num a) => LensLike' ((,) a) s a -> a -> m a
+ Control.Lens.Lens: (<-~) :: Num a => Overloading (->) q ((,) a) s t a a -> a -> q s (a, t)
+ Control.Lens.Lens: (<//=) :: (MonadState s m, Fractional a) => LensLike' ((,) a) s a -> a -> m a
+ Control.Lens.Lens: (<//~) :: Fractional a => Overloading (->) q ((,) a) s t a a -> a -> q s (a, t)
+ Control.Lens.Lens: (<<%=) :: (Strong p, MonadState s m) => Overloading p (->) ((,) a) s s a b -> p a b -> m a
+ Control.Lens.Lens: (<<%~) :: Strong p => Overloading p q ((,) a) s t a b -> p a b -> q s (a, t)
+ Control.Lens.Lens: (<<.=) :: MonadState s m => LensLike ((,) a) s s a b -> b -> m a
+ Control.Lens.Lens: (<<.~) :: Overloading (->) q ((,) a) s t a b -> b -> q s (a, t)
+ Control.Lens.Lens: (<<>=) :: (MonadState s m, Monoid r) => LensLike' ((,) r) s r -> r -> m r
+ Control.Lens.Lens: (<<>~) :: Monoid m => Overloading (->) q ((,) m) s t m m -> m -> q s (m, t)
+ Control.Lens.Lens: (<<~) :: MonadState s m => ALens s s a b -> m b -> m b
+ Control.Lens.Lens: (<^=) :: (MonadState s m, Num a, Integral e) => LensLike' ((,) a) s a -> e -> m a
+ Control.Lens.Lens: (<^^=) :: (MonadState s m, Fractional a, Integral e) => LensLike' ((,) a) s a -> e -> m a
+ Control.Lens.Lens: (<^^~) :: (Fractional a, Integral e) => Overloading (->) q ((,) a) s t a a -> e -> q s (a, t)
+ Control.Lens.Lens: (<^~) :: (Num a, Integral e) => Overloading (->) q ((,) a) s t a a -> e -> q s (a, t)
+ Control.Lens.Lens: (<||=) :: MonadState s m => LensLike' ((,) Bool) s Bool -> Bool -> m Bool
+ Control.Lens.Lens: (<||~) :: Overloading (->) q ((,) Bool) s t Bool Bool -> Bool -> q s (Bool, t)
+ Control.Lens.Lens: (^#) :: s -> ALens s t a b -> a
+ Control.Lens.Lens: Context :: (b -> t) -> a -> Context a b t
+ Control.Lens.Lens: alongside :: ALens s t a b -> ALens s' t' a' b' -> Lens (s, s') (t, t') (a, a') (b, b')
+ Control.Lens.Lens: choosing :: Functor f => LensLike f s t a b -> LensLike f s' t' a b -> LensLike f (Either s s') (Either t t') a b
+ Control.Lens.Lens: chosen :: IndexPreservingLens (Either a a) (Either b b) a b
+ Control.Lens.Lens: cloneIndexPreservingLens :: ALens s t a b -> IndexPreservingLens s t a b
+ Control.Lens.Lens: cloneIndexedLens :: AnIndexedLens i s t a b -> IndexedLens i s t a b
+ Control.Lens.Lens: cloneLens :: ALens s t a b -> Lens s t a b
+ Control.Lens.Lens: data Context a b t
+ Control.Lens.Lens: ilens :: (s -> (i, a)) -> (s -> b -> t) -> IndexedLens i s t a b
+ Control.Lens.Lens: inside :: ALens s t a b -> Lens (e -> s) (e -> t) (e -> a) (e -> b)
+ Control.Lens.Lens: iplens :: (Conjoined p, Functor f) => (s -> a) -> (s -> b -> t) -> Overloaded p f s t a b
+ Control.Lens.Lens: lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b
+ Control.Lens.Lens: locus :: IndexedComonadStore p => Lens (p a c s) (p b c s) a b
+ Control.Lens.Lens: storing :: ALens s t a b -> b -> s -> t
+ Control.Lens.Lens: type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t
+ Control.Lens.Lens: type ALens s t a b = LensLike (Pretext (->) a b) s t a b
+ Control.Lens.Lens: type ALens' s a = ALens s s a a
+ Control.Lens.Lens: type AnIndexedLens i s t a b = Overloading (Indexed i) (->) (Pretext (Indexed i) a b) s t a b
+ Control.Lens.Lens: type AnIndexedLens' i s a = AnIndexedLens i s s a a
+ Control.Lens.Lens: type Context' a = Context a a
+ Control.Lens.Lens: type IndexedLens' i s a = IndexedLens i s s a a
+ Control.Lens.Lens: type Lens' s a = Lens s s a a
+ Control.Lens.Lens: type IndexedLens i s t a b = forall f p. (Indexable i p, Functor f) => p a (f b) -> s -> f t
+ Control.Lens.Level: data Level i a
+ Control.Lens.Level: ilevels :: AnIndexedTraversal i s t a b -> IndexedTraversal Int s t (Level i a) (Level j b)
+ Control.Lens.Level: levels :: ATraversal s t a b -> IndexedTraversal Int s t (Level () a) (Level () b)
+ Control.Lens.Operators: (#%%=) :: MonadState s m => ALens s s a b -> (a -> (r, b)) -> m r
+ Control.Lens.Operators: (#%%~) :: Functor f => ALens s t a b -> (a -> f b) -> s -> f t
+ Control.Lens.Operators: (#%=) :: MonadState s m => ALens s s a b -> (a -> b) -> m ()
+ Control.Lens.Operators: (#%~) :: ALens s t a b -> (a -> b) -> s -> t
+ Control.Lens.Operators: (#=) :: MonadState s m => ALens s s a b -> b -> m ()
+ Control.Lens.Operators: (#~) :: ALens s t a b -> b -> s -> t
+ Control.Lens.Operators: (%%=) :: MonadState s m => Overloading p (->) ((,) r) s s a b -> p a (r, b) -> m r
+ Control.Lens.Operators: (%%@=) :: MonadState s m => IndexedLensLike i ((,) r) s s a b -> (i -> a -> (r, b)) -> m r
+ Control.Lens.Operators: (%%@~) :: IndexedLensLike i f s t a b -> (i -> a -> f b) -> s -> f t
+ Control.Lens.Operators: (%%~) :: Overloading p q f s t a b -> p a (f b) -> q s (f t)
+ Control.Lens.Operators: (%=) :: (Profunctor p, MonadState s m) => Setting p s s a b -> p a b -> m ()
+ Control.Lens.Operators: (%@=) :: MonadState s m => AnIndexedSetter i s s a b -> (i -> a -> b) -> m ()
+ Control.Lens.Operators: (%@~) :: AnIndexedSetter i s t a b -> (i -> a -> b) -> s -> t
+ Control.Lens.Operators: (%~) :: Profunctor p => Setting p s t a b -> p a b -> s -> t
+ Control.Lens.Operators: (&&=) :: MonadState s m => ASetter' s Bool -> Bool -> m ()
+ Control.Lens.Operators: (&&~) :: ASetter s t Bool Bool -> Bool -> s -> t
+ Control.Lens.Operators: (&) :: a -> (a -> b) -> b
+ Control.Lens.Operators: (**=) :: (MonadState s m, Floating a) => ASetter' s a -> a -> m ()
+ Control.Lens.Operators: (**~) :: Floating a => ASetter s t a a -> a -> s -> t
+ Control.Lens.Operators: (*=) :: (MonadState s m, Num a) => ASetter' s a -> a -> m ()
+ Control.Lens.Operators: (*~) :: Num a => ASetter s t a a -> a -> s -> t
+ Control.Lens.Operators: (+=) :: (MonadState s m, Num a) => ASetter' s a -> a -> m ()
+ Control.Lens.Operators: (+~) :: Num a => ASetter s t a a -> a -> s -> t
+ Control.Lens.Operators: (-=) :: (MonadState s m, Num a) => ASetter' s a -> a -> m ()
+ Control.Lens.Operators: (-~) :: Num a => ASetter s t a a -> a -> s -> t
+ Control.Lens.Operators: (.=) :: MonadState s m => ASetter s s a b -> b -> m ()
+ Control.Lens.Operators: (.>) :: (st -> r) -> (kab -> st) -> kab -> r
+ Control.Lens.Operators: (.~) :: ASetter s t a b -> b -> s -> t
+ Control.Lens.Operators: (//=) :: (MonadState s m, Fractional a) => ASetter' s a -> a -> m ()
+ Control.Lens.Operators: (//~) :: Fractional a => ASetter s t a a -> a -> s -> t
+ Control.Lens.Operators: (<#%=) :: MonadState s m => ALens s s a b -> (a -> b) -> m b
+ Control.Lens.Operators: (<#%~) :: ALens s t a b -> (a -> b) -> s -> (b, t)
+ Control.Lens.Operators: (<#=) :: MonadState s m => ALens s s a b -> b -> m b
+ Control.Lens.Operators: (<#~) :: ALens s t a b -> b -> s -> (b, t)
+ Control.Lens.Operators: (<%=) :: (Profunctor p, MonadState s m) => Overloading p (->) ((,) b) s s a b -> p a b -> m b
+ Control.Lens.Operators: (<%@=) :: MonadState s m => IndexedLensLike i ((,) b) s s a b -> (i -> a -> b) -> m b
+ Control.Lens.Operators: (<%@~) :: Overloading (Indexed i) q ((,) b) s t a b -> (i -> a -> b) -> q s (b, t)
+ Control.Lens.Operators: (<%~) :: Profunctor p => Overloading p q ((,) b) s t a b -> p a b -> q s (b, t)
+ Control.Lens.Operators: (<&&=) :: MonadState s m => LensLike' ((,) Bool) s Bool -> Bool -> m Bool
+ Control.Lens.Operators: (<&&~) :: Overloading (->) q ((,) Bool) s t Bool Bool -> Bool -> q s (Bool, t)
+ Control.Lens.Operators: (<&>) :: Functor f => f a -> (a -> b) -> f b
+ Control.Lens.Operators: (<**=) :: (MonadState s m, Floating a) => LensLike' ((,) a) s a -> a -> m a
+ Control.Lens.Operators: (<**~) :: Floating a => Overloading (->) q ((,) a) s t a a -> a -> q s (a, t)
+ Control.Lens.Operators: (<*=) :: (MonadState s m, Num a) => LensLike' ((,) a) s a -> a -> m a
+ Control.Lens.Operators: (<*~) :: Num a => Overloading (->) q ((,) a) s t a a -> a -> q s (a, t)
+ Control.Lens.Operators: (<+=) :: (MonadState s m, Num a) => LensLike' ((,) a) s a -> a -> m a
+ Control.Lens.Operators: (<+~) :: Num a => Overloading (->) q ((,) a) s t a a -> a -> q s (a, t)
+ Control.Lens.Operators: (<-=) :: (MonadState s m, Num a) => LensLike' ((,) a) s a -> a -> m a
+ Control.Lens.Operators: (<-~) :: Num a => Overloading (->) q ((,) a) s t a a -> a -> q s (a, t)
+ Control.Lens.Operators: (<.) :: Indexable i p => (Indexed i s t -> r) -> ((a -> b) -> s -> t) -> p a b -> r
+ Control.Lens.Operators: (<.=) :: MonadState s m => ASetter s s a b -> b -> m b
+ Control.Lens.Operators: (<.>) :: Indexable (i, j) p => (Indexed i s t -> r) -> (Indexed j a b -> s -> t) -> p a b -> r
+ Control.Lens.Operators: (<.~) :: ASetter s t a b -> b -> s -> (b, t)
+ Control.Lens.Operators: (<//=) :: (MonadState s m, Fractional a) => LensLike' ((,) a) s a -> a -> m a
+ Control.Lens.Operators: (<//~) :: Fractional a => Overloading (->) q ((,) a) s t a a -> a -> q s (a, t)
+ Control.Lens.Operators: (<<%=) :: (Strong p, MonadState s m) => Overloading p (->) ((,) a) s s a b -> p a b -> m a
+ Control.Lens.Operators: (<<%~) :: Strong p => Overloading p q ((,) a) s t a b -> p a b -> q s (a, t)
+ Control.Lens.Operators: (<<.=) :: MonadState s m => LensLike ((,) a) s s a b -> b -> m a
+ Control.Lens.Operators: (<<.~) :: Overloading (->) q ((,) a) s t a b -> b -> q s (a, t)
+ Control.Lens.Operators: (<<>=) :: (MonadState s m, Monoid r) => LensLike' ((,) r) s r -> r -> m r
+ Control.Lens.Operators: (<<>~) :: Monoid m => Overloading (->) q ((,) m) s t m m -> m -> q s (m, t)
+ Control.Lens.Operators: (<<~) :: MonadState s m => ALens s s a b -> m b -> m b
+ Control.Lens.Operators: (<>=) :: (MonadState s m, Monoid a) => ASetter' s a -> a -> m ()
+ Control.Lens.Operators: (<>~) :: Monoid a => ASetter s t a a -> a -> s -> t
+ Control.Lens.Operators: (<?=) :: MonadState s m => ASetter s s a (Maybe b) -> b -> m b
+ Control.Lens.Operators: (<?~) :: ASetter s t a (Maybe b) -> b -> s -> (b, t)
+ Control.Lens.Operators: (<^=) :: (MonadState s m, Num a, Integral e) => LensLike' ((,) a) s a -> e -> m a
+ Control.Lens.Operators: (<^^=) :: (MonadState s m, Fractional a, Integral e) => LensLike' ((,) a) s a -> e -> m a
+ Control.Lens.Operators: (<^^~) :: (Fractional a, Integral e) => Overloading (->) q ((,) a) s t a a -> e -> q s (a, t)
+ Control.Lens.Operators: (<^~) :: (Num a, Integral e) => Overloading (->) q ((,) a) s t a a -> e -> q s (a, t)
+ Control.Lens.Operators: (<|) :: Cons Reviewed Identity s s a a => a -> s -> s
+ Control.Lens.Operators: (<||=) :: MonadState s m => LensLike' ((,) Bool) s Bool -> Bool -> m Bool
+ Control.Lens.Operators: (<||~) :: Overloading (->) q ((,) Bool) s t Bool Bool -> Bool -> q s (Bool, t)
+ Control.Lens.Operators: (<~) :: MonadState s m => ASetter s s a b -> m b -> m ()
+ Control.Lens.Operators: (?=) :: MonadState s m => ASetter s s a (Maybe b) -> b -> m ()
+ Control.Lens.Operators: (??) :: Functor f => f (a -> b) -> a -> f b
+ Control.Lens.Operators: (?~) :: ASetter s t a (Maybe b) -> b -> s -> t
+ Control.Lens.Operators: (^!!) :: Monad m => s -> Acting m [a] s t a b -> m [a]
+ Control.Lens.Operators: (^!) :: Monad m => s -> Acting m a s t a b -> m a
+ Control.Lens.Operators: (^!?) :: Monad m => s -> Acting m (Leftmost a) s t a b -> m (Maybe a)
+ Control.Lens.Operators: (^#) :: s -> ALens s t a b -> a
+ Control.Lens.Operators: (^.) :: s -> Getting a s t a b -> a
+ Control.Lens.Operators: (^..) :: s -> Getting (Endo [a]) s t a b -> [a]
+ Control.Lens.Operators: (^=) :: (MonadState s m, Num a, Integral e) => ASetter' s a -> e -> m ()
+ Control.Lens.Operators: (^?!) :: s -> Getting (Endo a) s t a b -> a
+ Control.Lens.Operators: (^?) :: s -> Getting (First a) s t a b -> Maybe a
+ Control.Lens.Operators: (^@!!) :: Monad m => s -> IndexedActing i m [(i, a)] s t a b -> m [(i, a)]
+ Control.Lens.Operators: (^@!) :: Monad m => s -> IndexedActing i m (i, a) s t a b -> m (i, a)
+ Control.Lens.Operators: (^@!?) :: Monad m => s -> IndexedActing i m (Leftmost (i, a)) s t a b -> m (Maybe (i, a))
+ Control.Lens.Operators: (^@.) :: s -> IndexedGetting i (i, a) s t a b -> (i, a)
+ Control.Lens.Operators: (^@..) :: s -> IndexedGetting i (Endo [(i, a)]) s t a b -> [(i, a)]
+ Control.Lens.Operators: (^@?!) :: s -> IndexedGetting i (Endo (i, a)) s t a b -> (i, a)
+ Control.Lens.Operators: (^@?) :: s -> IndexedGetting i (Endo (Maybe (i, a))) s t a b -> Maybe (i, a)
+ Control.Lens.Operators: (^^=) :: (MonadState s m, Fractional a, Integral e) => ASetter' s a -> e -> m ()
+ Control.Lens.Operators: (^^~) :: (Fractional a, Integral e) => ASetter s t a a -> e -> s -> t
+ Control.Lens.Operators: (^~) :: (Num a, Integral e) => ASetter s t a a -> e -> s -> t
+ Control.Lens.Operators: (|>) :: Snoc Reviewed Identity s s a a => s -> a -> s
+ Control.Lens.Operators: (||=) :: MonadState s m => ASetter' s Bool -> Bool -> m ()
+ Control.Lens.Operators: (||~) :: ASetter s t Bool Bool -> Bool -> s -> t
+ Control.Lens.Operators: type (:>>) h a = Zipper h Int a
+ Control.Lens.Prism: _Just :: Prism (Maybe a) (Maybe b) a b
+ Control.Lens.Prism: _Left :: Prism (Either a c) (Either b c) a b
+ Control.Lens.Prism: _Right :: Prism (Either c a) (Either c b) a b
+ Control.Lens.Prism: class Profunctor p => Choice (p :: * -> * -> *)
+ Control.Lens.Prism: isn't :: APrism s t a b -> s -> Bool
+ Control.Lens.Prism: left' :: Choice p => p a b -> p (Either a c) (Either b c)
+ Control.Lens.Prism: prism' :: (a -> s) -> (s -> Maybe a) -> Prism' s a
+ Control.Lens.Prism: right' :: Choice p => p a b -> p (Either c a) (Either c b)
+ Control.Lens.Prism: type APrism' s a = APrism s s a a
+ Control.Lens.Prism: type Prism' s a = Prism s s a a
+ Control.Lens.Prism: type Prism s t a b = forall p f. (Choice p, Applicative f) => p a (f b) -> p s (f t)
+ Control.Lens.Reified: ReifyFold :: Fold s a -> ReifiedFold s a
+ Control.Lens.Reified: ReifyGetter :: Getter s a -> ReifiedGetter s a
+ Control.Lens.Reified: ReifyIndexedGetter :: IndexedGetter i s a -> ReifiedIndexedGetter i s a
+ Control.Lens.Reified: ReifyIndexedLens :: IndexedLens i s t a b -> ReifiedIndexedLens i s t a b
+ Control.Lens.Reified: ReifyIndexedSetter :: IndexedSetter i s t a b -> ReifiedIndexedSetter i s t a b
+ Control.Lens.Reified: ReifyIndexedTraversal :: IndexedTraversal i s t a b -> ReifiedIndexedTraversal i s t a b
+ Control.Lens.Reified: ReifyIso :: Iso s t a b -> ReifiedIso s t a b
+ Control.Lens.Reified: ReifyLens :: Lens s t a b -> ReifiedLens s t a b
+ Control.Lens.Reified: ReifyPrism :: Prism s t a b -> ReifiedPrism s t a b
+ Control.Lens.Reified: ReifySetter :: Setter s t a b -> ReifiedSetter s t a b
+ Control.Lens.Reified: ReifyTraversal :: Traversal s t a b -> ReifiedTraversal s t a b
+ Control.Lens.Reified: data ReifiedTraversal s t a b
+ Control.Lens.Reified: newtype ReifiedFold s a
+ Control.Lens.Reified: newtype ReifiedGetter s a
+ Control.Lens.Reified: newtype ReifiedIndexedGetter i s a
+ Control.Lens.Reified: newtype ReifiedIndexedLens i s t a b
+ Control.Lens.Reified: newtype ReifiedIndexedSetter i s t a b
+ Control.Lens.Reified: newtype ReifiedIndexedTraversal i s t a b
+ Control.Lens.Reified: newtype ReifiedIso s t a b
+ Control.Lens.Reified: newtype ReifiedLens s t a b
+ Control.Lens.Reified: newtype ReifiedPrism s t a b
+ Control.Lens.Reified: newtype ReifiedSetter s t a b
+ Control.Lens.Reified: reflectFold :: ReifiedFold s a -> Fold s a
+ Control.Lens.Reified: reflectGetter :: ReifiedGetter s a -> Getter s a
+ Control.Lens.Reified: reflectIndexedGetter :: ReifiedIndexedGetter i s a -> IndexedGetter i s a
+ Control.Lens.Reified: reflectIndexedLens :: ReifiedIndexedLens i s t a b -> IndexedLens i s t a b
+ Control.Lens.Reified: reflectIndexedSetter :: ReifiedIndexedSetter i s t a b -> IndexedSetter i s t a b
+ Control.Lens.Reified: reflectIndexedTraversal :: ReifiedIndexedTraversal i s t a b -> IndexedTraversal i s t a b
+ Control.Lens.Reified: reflectIso :: ReifiedIso s t a b -> Iso s t a b
+ Control.Lens.Reified: reflectLens :: ReifiedLens s t a b -> Lens s t a b
+ Control.Lens.Reified: reflectPrism :: ReifiedPrism s t a b -> Prism s t a b
+ Control.Lens.Reified: reflectSetter :: ReifiedSetter s t a b -> Setter s t a b
+ Control.Lens.Reified: reflectTraversal :: ReifiedTraversal s t a b -> Traversal s t a b
+ Control.Lens.Reified: type ReifiedIndexedLens' i s a = ReifiedIndexedLens i s s a a
+ Control.Lens.Reified: type ReifiedIndexedSetter' i s a = ReifiedIndexedSetter i s s a a
+ Control.Lens.Reified: type ReifiedIndexedTraversal' i s a = ReifiedIndexedTraversal i s s a a
+ Control.Lens.Reified: type ReifiedIso' s a = ReifiedIso s s a a
+ Control.Lens.Reified: type ReifiedLens' s a = ReifiedLens s s a a
+ Control.Lens.Reified: type ReifiedPrism' s a = ReifiedPrism s s a a
+ Control.Lens.Reified: type ReifiedSetter' s a = ReifiedSetter s s a a
+ Control.Lens.Reified: type ReifiedTraversal' s a = ReifiedTraversal s s a a
+ Control.Lens.Review: class Profunctor p => Reviewable p
+ Control.Lens.Review: re :: AReview s t a b -> Getter b t
+ Control.Lens.Review: retagged :: Reviewable p => p a b -> p s b
+ Control.Lens.Review: reuse :: MonadState b m => AReview s t a b -> m t
+ Control.Lens.Review: reuses :: MonadState b m => AReview s t a b -> (t -> r) -> m r
+ Control.Lens.Review: review :: MonadReader b m => AReview s t a b -> m t
+ Control.Lens.Review: reviews :: MonadReader b m => AReview s t a b -> (t -> r) -> m r
+ Control.Lens.Review: type AReview s t a b = Overloaded Reviewed Identity s t a b
+ Control.Lens.Review: type AReview' t b = AReview t t b b
+ Control.Lens.Review: type Review s t a b = forall p f. (Reviewable p, Settable f) => Overloaded p f s t a b
+ Control.Lens.Review: type Review' t b = Review t t b b
+ Control.Lens.Review: unto :: (Reviewable p, Functor f) => (b -> t) -> Overloaded p f s t a b
+ Control.Lens.Setter: (%@=) :: MonadState s m => AnIndexedSetter i s s a b -> (i -> a -> b) -> m ()
+ Control.Lens.Setter: (%@~) :: AnIndexedSetter i s t a b -> (i -> a -> b) -> s -> t
+ Control.Lens.Setter: argument :: Profunctor p => Setter (p b r) (p a r) a b
+ Control.Lens.Setter: censoring :: MonadWriter w m => Setter w w u v -> (u -> v) -> m a -> m a
+ Control.Lens.Setter: cloneIndexPreservingSetter :: ASetter s t a b -> IndexPreservingSetter s t a b
+ Control.Lens.Setter: cloneIndexedSetter :: AnIndexedSetter i s t a b -> IndexedSetter i s t a b
+ Control.Lens.Setter: cloneSetter :: ASetter s t a b -> Setter s t a b
+ Control.Lens.Setter: contramapped :: Contravariant f => Setter (f b) (f a) a b
+ Control.Lens.Setter: icensoring :: MonadWriter w m => IndexedSetter i w w u v -> (i -> u -> v) -> m a -> m a
+ Control.Lens.Setter: imapOf :: AnIndexedSetter i s t a b -> (i -> a -> b) -> s -> t
+ Control.Lens.Setter: iover :: AnIndexedSetter i s t a b -> (i -> a -> b) -> s -> t
+ Control.Lens.Setter: ipassing :: MonadWriter w m => IndexedSetter i w w u v -> m (a, i -> u -> v) -> m a
+ Control.Lens.Setter: isets :: ((i -> a -> b) -> s -> t) -> IndexedSetter i s t a b
+ Control.Lens.Setter: passing :: MonadWriter w m => Setter w w u v -> m (a, u -> v) -> m a
+ Control.Lens.Setter: scribe :: (MonadWriter t m, Monoid s) => ASetter s t a b -> b -> m ()
+ Control.Lens.Setter: setting :: ((a -> b) -> s -> t) -> IndexPreservingSetter s t a b
+ Control.Lens.Setter: type ASetter s t a b = (a -> Mutator b) -> s -> Mutator t
+ Control.Lens.Setter: type ASetter' s a = ASetter s s a a
+ Control.Lens.Setter: type AnIndexedSetter i s t a b = Indexed i a (Mutator b) -> s -> Mutator t
+ Control.Lens.Setter: type AnIndexedSetter' i s a = AnIndexedSetter i s s a a
+ Control.Lens.Setter: type IndexedSetter' i s a = IndexedSetter i s s a a
+ Control.Lens.Setter: type Setter' s a = Setter s s a a
+ Control.Lens.Setter: type Setting' p s a = Setting p s s a a
+ Control.Lens.Setter: type IndexedSetter i s t a b = forall f p. (Indexable i p, Settable f) => p a (f b) -> s -> f t
+ Control.Lens.Simple: type SimpleIndexedSetter i s a = IndexedSetter i s s a a
+ Control.Lens.Simple: type SimpleIndexedTraversal i s a = IndexedTraversal i s s a a
+ Control.Lens.Simple: type SimpleIso s a = Iso s s a a
+ Control.Lens.Simple: type SimpleLens s a = Lens s s a a
+ Control.Lens.Simple: type SimplePrism s a = Prism s s a a
+ Control.Lens.Simple: type SimpleReifiedIndexedSetter i s a = ReifiedIndexedSetter i s s a a
+ Control.Lens.Simple: type SimpleReifiedIndexedTraversal i s a = ReifiedIndexedTraversal i s s a a
+ Control.Lens.Simple: type SimpleReifiedLens s a = Lens s s a a
+ Control.Lens.Simple: type SimpleReifiedSetter s a = ReifiedSetter s s a a
+ Control.Lens.Simple: type SimpleReifiedTraversal s a = ReifiedTraversal s s a a
+ Control.Lens.Simple: type SimpleSetter s a = Setter s s a a
+ Control.Lens.Simple: type SimpleTraversal s a = Traversal s s a a
+ Control.Lens.TH: FieldRules :: (String -> Maybe String) -> (String -> String) -> (String -> Maybe String) -> (String -> Maybe String) -> FieldRules
+ Control.Lens.TH: camelCaseFields :: FieldRules
+ Control.Lens.TH: data FieldRules
+ Control.Lens.TH: defaultFieldRules :: FieldRules
+ Control.Lens.TH: makeFields :: Name -> Q [Dec]
+ Control.Lens.TH: makeFieldsWith :: FieldRules -> Name -> Q [Dec]
+ Control.Lens.TH: makeWrapped :: Name -> DecsQ
+ Control.Lens.TH: underscoreFields :: FieldRules
+ Control.Lens.Traversal: class Ord k => TraverseMax k m | m -> k
+ Control.Lens.Traversal: class Ord k => TraverseMin k m | m -> k
+ Control.Lens.Traversal: cloneIndexPreservingTraversal :: ATraversal s t a b -> IndexPreservingTraversal s t a b
+ Control.Lens.Traversal: cloneIndexedTraversal :: AnIndexedTraversal i s t a b -> IndexedTraversal i s t a b
+ Control.Lens.Traversal: element :: Traversable t => Int -> IndexedTraversal' Int (t a) a
+ Control.Lens.Traversal: elementOf :: Applicative f => LensLike (Indexing f) s t a a -> Int -> IndexedLensLike Int f s t a a
+ Control.Lens.Traversal: elements :: Traversable t => (Int -> Bool) -> IndexedTraversal' Int (t a) a
+ Control.Lens.Traversal: elementsOf :: Applicative f => LensLike (Indexing f) s t a a -> (Int -> Bool) -> IndexedLensLike Int f s t a a
+ Control.Lens.Traversal: iforMOf :: (Indexed i a (WrappedMonad m b) -> s -> WrappedMonad m t) -> s -> (i -> a -> m b) -> m t
+ Control.Lens.Traversal: iforOf :: (Indexed i a (f b) -> s -> f t) -> s -> (i -> a -> f b) -> f t
+ Control.Lens.Traversal: ignored :: Applicative f => pafb -> s -> f s
+ Control.Lens.Traversal: imapAccumLOf :: Over (Indexed i) (State acc) s t a b -> (i -> acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
+ Control.Lens.Traversal: imapAccumROf :: Over (Indexed i) (Backwards (State acc)) s t a b -> (i -> acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
+ Control.Lens.Traversal: imapMOf :: (Indexed i a (WrappedMonad m b) -> s -> WrappedMonad m t) -> (i -> a -> m b) -> s -> m t
+ Control.Lens.Traversal: instance Ord k => TraverseMax k (Map k)
+ Control.Lens.Traversal: instance Ord k => TraverseMin k (Map k)
+ Control.Lens.Traversal: instance TraverseMax Int IntMap
+ Control.Lens.Traversal: instance TraverseMin Int IntMap
+ Control.Lens.Traversal: ipartsOf :: (Indexable [i] p, Functor f) => Traversing (Indexed i) f s t a a -> Over p f s t [a] [a]
+ Control.Lens.Traversal: ipartsOf' :: (Indexable [i] p, Functor f) => Over (Indexed i) (Bazaar' (Indexed i) a) s t a a -> Over p f s t [a] [a]
+ Control.Lens.Traversal: itraverseOf :: (Indexed i a (f b) -> s -> f t) -> (i -> a -> f b) -> s -> f t
+ Control.Lens.Traversal: iunsafePartsOf :: (Indexable [i] p, Functor f) => Traversing (Indexed i) f s t a b -> Over p f s t [a] [b]
+ Control.Lens.Traversal: iunsafePartsOf' :: Over (Indexed i) (Bazaar (Indexed i) a b) s t a b -> IndexedLens [i] s t [a] [b]
+ Control.Lens.Traversal: traverseMax :: TraverseMax k m => IndexedTraversal' k (m v) v
+ Control.Lens.Traversal: traverseMin :: TraverseMin k m => IndexedTraversal' k (m v) v
+ Control.Lens.Traversal: traversed :: Traversable f => IndexedTraversal Int (f a) (f b) a b
+ Control.Lens.Traversal: traversed64 :: Traversable f => IndexedTraversal Int64 (f a) (f b) a b
+ Control.Lens.Traversal: type ATraversal s t a b = LensLike (Bazaar (->) a b) s t a b
+ Control.Lens.Traversal: type ATraversal' s a = ATraversal s s a a
+ Control.Lens.Traversal: type AnIndexedTraversal i s t a b = Over (Indexed i) (Bazaar (Indexed i) a b) s t a b
+ Control.Lens.Traversal: type AnIndexedTraversal' i s a = AnIndexedTraversal i s s a a
+ Control.Lens.Traversal: type Bazaar' p a = Bazaar p a a
+ Control.Lens.Traversal: type IndexedTraversal' i s a = IndexedTraversal i s s a a
+ Control.Lens.Traversal: type Traversal' s a = Traversal s s a a
+ Control.Lens.Traversal: type Traversing p f s t a b = Over p (BazaarT p f a b) s t a b
+ Control.Lens.Traversal: type Traversing' p f s a = Traversing p f s s a a
+ Control.Lens.Traversal: type IndexedTraversal i s t a b = forall p f. (Indexable i p, Applicative f) => p a (f b) -> s -> f t
+ Control.Lens.Tuple: instance Field1 (Identity a) (Identity b) a b
+ Control.Lens.Type: type Equality s t a b = forall p (f :: * -> *). p a (f b) -> p s (f t)
+ Control.Lens.Type: type Equality' s a = Equality s s a a
+ Control.Lens.Type: type IndexPreservingLens' s a = IndexPreservingLens s s a a
+ Control.Lens.Type: type IndexPreservingSetter' s a = IndexPreservingSetter s s a a
+ Control.Lens.Type: type IndexPreservingTraversal' s a = IndexPreservingTraversal s s a a
+ Control.Lens.Type: type IndexedLens' i s a = IndexedLens i s s a a
+ Control.Lens.Type: type IndexedLensLike' i f s a = IndexedLensLike i f s s a a
+ Control.Lens.Type: type IndexedSetter' i s a = IndexedSetter i s s a a
+ Control.Lens.Type: type IndexedTraversal' i s a = IndexedTraversal i s s a a
+ Control.Lens.Type: type Iso' s a = Iso s s a a
+ Control.Lens.Type: type Lens' s a = Lens s s a a
+ Control.Lens.Type: type LensLike' f s a = LensLike f s s a a
+ Control.Lens.Type: type Over p f s t a b = p a (f b) -> s -> f t
+ Control.Lens.Type: type Over' p f s a = Over p f s s a a
+ Control.Lens.Type: type Overloaded' p f s a = Overloaded p f s s a a
+ Control.Lens.Type: type Overloading p q f s t a b = p a (f b) -> q s (f t)
+ Control.Lens.Type: type Overloading' p q f s a = Overloading p q f s s a a
+ Control.Lens.Type: type Prism' s a = Prism s s a a
+ Control.Lens.Type: type Setter' s a = Setter s s a a
+ Control.Lens.Type: type Traversal' s a = Traversal s s a a
+ Control.Lens.Type: type IndexedLensLike i f s t a b = forall p. Indexable i p => p a (f b) -> s -> f t
+ Control.Lens.Wrapped: instance Wrapped (a -> Bool) (a' -> Bool) (Predicate a) (Predicate a')
+ Control.Lens.Wrapped: instance Wrapped (a -> a -> Bool) (a' -> a' -> Bool) (Equivalence a) (Equivalence a')
+ Control.Lens.Wrapped: instance Wrapped (a -> a -> Ordering) (a' -> a' -> Ordering) (Comparison a) (Comparison a')
+ Control.Lens.Wrapped: instance Wrapped (b -> a) (b' -> a') (Op a b) (Op a' b')
+ Control.Lens.Wrapped: instance Wrapped (f (g a)) (f' (g' a')) (ComposeCF f g a) (ComposeFC f' g' a')
+ Control.Lens.Wrapped: instance Wrapped (f (g a)) (f' (g' a')) (ComposeFC f g a) (ComposeFC f' g' a')
+ Control.Lens.Wrapped: instance Wrapped a b (Dual a) (Dual b)
+ Control.Lens.Wrapped: instance Wrapped a b (Reviewed s a) (Reviewed t b)
+ Control.Lens.Wrapped: instance Wrapped a b (Tagged k s a) (Tagged k1 t b)
+ Control.Lens.Wrapped: unwrapped' :: Wrapped s s a a => Iso' a s
+ Control.Lens.Wrapped: wrapped' :: Wrapped s s a a => Iso' s a
+ Control.Lens.Zipper: data Zipper h i a
+ Control.Lens.Zipper: idownward :: Ord i => AnIndexedLens' i s a -> h :> (s :@ j) -> (h :> (s :@ j)) :> (a :@ i)
+ Control.Lens.Zipper: ifromWithin :: Ord i => AnIndexedTraversal' i s a -> (h :> (s :@ j)) -> (h :> (s :@ j)) :> (a :@ i)
+ Control.Lens.Zipper: iwithin :: (MonadPlus m, Ord i) => AnIndexedTraversal' i s a -> (h :> (s :@ j)) -> m ((h :> (s :@ j)) :> (a :@ i))
+ Control.Lens.Zipper: iwithins :: (MonadPlus m, Ord i) => AnIndexedTraversal' i s a -> (h :> (s :@ j)) -> m ((h :> (s :@ j)) :> (a :@ i))
+ Control.Lens.Zipper: moveTo :: MonadPlus m => i -> h :> (a :@ i) -> m (h :> (a :@ i))
+ Control.Lens.Zipper: moveToward :: i -> h :> (a :@ i) -> h :> (a :@ i)
+ Control.Lens.Zipper: type (:>>) h a = Zipper h Int a
+ Control.Lens.Zoom: instance (Error e, Zoom m n s t) => Zoom (ErrorT e m) (ErrorT e n) s t
+ Control.Lens.Zoom: instance (Monad m, Monoid w) => Magnify (RWST b w s m) (RWST a w s m) b a
+ Control.Lens.Zoom: instance (Monoid w, Monad z) => Zoom (RWST r w s z) (RWST r w t z) s t
+ Control.Lens.Zoom: instance (Monoid w, Zoom m n s t) => Zoom (WriterT w m) (WriterT w n) s t
+ Control.Lens.Zoom: instance Magnify ((->) b) ((->) a) b a
+ Control.Lens.Zoom: instance Magnify m n b a => Magnify (IdentityT m) (IdentityT n) b a
+ Control.Lens.Zoom: instance Monad m => Magnify (ReaderT b m) (ReaderT a m) b a
+ Control.Lens.Zoom: instance Monad z => Zoom (StateT s z) (StateT t z) s t
+ Control.Lens.Zoom: instance Zoom m n s t => Zoom (IdentityT m) (IdentityT n) s t
+ Control.Lens.Zoom: instance Zoom m n s t => Zoom (ListT m) (ListT n) s t
+ Control.Lens.Zoom: instance Zoom m n s t => Zoom (MaybeT m) (MaybeT n) s t
+ Control.Lens.Zoom: instance Zoom m n s t => Zoom (ReaderT e m) (ReaderT e n) s t
+ Control.Monad.Error.Lens: catching :: MonadError e m => Getting (First a) e t a b -> m r -> (a -> m r) -> m r
+ Control.Monad.Error.Lens: catching_ :: MonadError e m => Getting (First a) e t a b -> m r -> m r -> m r
+ Control.Monad.Error.Lens: handling :: MonadError e m => Getting (First a) e t a b -> (a -> m r) -> m r -> m r
+ Control.Monad.Error.Lens: handling_ :: MonadError e m => Getting (First a) e t a b -> m r -> m r -> m r
+ Control.Monad.Error.Lens: throwing :: MonadError e m => AReview e e t t -> t -> m x
+ Control.Monad.Error.Lens: trying :: MonadError e m => Getting (First a) e t a b -> m r -> m (Either a r)
+ Data.Bits.Lens: byteAt :: (Integral b, Bits b) => Int -> IndexedLens' Int b Word8
+ Data.Dynamic.Lens: _Dynamic :: (AsDynamic t, Typeable a) => Prism' t a
+ Data.Dynamic.Lens: class AsDynamic t
+ Data.Dynamic.Lens: instance AsDynamic Dynamic
+ Data.Dynamic.Lens: instance AsDynamic SomeException
+ Data.Text.Lazy.Lens: builder :: Iso' Text Builder
+ Data.Text.Lens: builder :: IsText t => Iso' t Builder
+ Data.Text.Strict.Lens: builder :: Iso' Text Builder
+ Numeric.Lens: base :: (Integral a, Show a) => a -> Prism' String a
+ Numeric.Lens: integral :: (Integral a, Integral b) => Prism Integer Integer a b
+ System.Exit.Lens: _ExitCode :: AsExitCode p f t => Overloaded' p f t ExitCode
+ System.Exit.Lens: _ExitFailure :: (AsExitCode p f t, Choice p, Applicative f) => Overloaded' p f t Int
+ System.Exit.Lens: _ExitSuccess :: (AsExitCode p f t, Choice p, Applicative f) => Overloaded' p f t ()
+ System.Exit.Lens: class AsExitCode p f t
+ System.Exit.Lens: instance (Choice p, Applicative f) => AsExitCode p f SomeException
+ System.Exit.Lens: instance AsExitCode p f ExitCode
+ System.IO.Error.Lens: _AlreadyExists :: Prism' IOErrorType ()
+ System.IO.Error.Lens: _EOF :: Prism' IOErrorType ()
+ System.IO.Error.Lens: _HardwareFault :: Prism' IOErrorType ()
+ System.IO.Error.Lens: _IllegalOperation :: Prism' IOErrorType ()
+ System.IO.Error.Lens: _InappropriateType :: Prism' IOErrorType ()
+ System.IO.Error.Lens: _Interrupted :: Prism' IOErrorType ()
+ System.IO.Error.Lens: _InvalidArgument :: Prism' IOErrorType ()
+ System.IO.Error.Lens: _NoSuchThing :: Prism' IOErrorType ()
+ System.IO.Error.Lens: _OtherError :: Prism' IOErrorType ()
+ System.IO.Error.Lens: _PermissionDenied :: Prism' IOErrorType ()
+ System.IO.Error.Lens: _ProtocolError :: Prism' IOErrorType ()
+ System.IO.Error.Lens: _ResourceBusy :: Prism' IOErrorType ()
+ System.IO.Error.Lens: _ResourceExhausted :: Prism' IOErrorType ()
+ System.IO.Error.Lens: _ResourceVanished :: Prism' IOErrorType ()
+ System.IO.Error.Lens: _SystemError :: Prism' IOErrorType ()
+ System.IO.Error.Lens: _TimeExpired :: Prism' IOErrorType ()
+ System.IO.Error.Lens: _UnsatisfiedConstraints :: Prism' IOErrorType ()
+ System.IO.Error.Lens: _UnsupportedOperation :: Prism' IOErrorType ()
+ System.IO.Error.Lens: _UserError :: Prism' IOErrorType ()
+ System.IO.Error.Lens: description :: (AsIOException (->) f t, Functor f) => LensLike' f t String
+ System.IO.Error.Lens: errno :: (AsIOException (->) f t, Functor f) => LensLike' f t (Maybe CInt)
+ System.IO.Error.Lens: errorType :: (AsIOException (->) f t, Functor f) => LensLike' f t IOErrorType
+ System.IO.Error.Lens: fileName :: (AsIOException (->) f t, Functor f) => LensLike' f t (Maybe FilePath)
+ System.IO.Error.Lens: handle :: (AsIOException (->) f t, Functor f) => LensLike' f t (Maybe Handle)
+ System.IO.Error.Lens: location :: (AsIOException (->) f t, Functor f) => LensLike' f t String
- Control.Exception.Lens: exception :: Exception a => Simple Prism SomeException a
+ Control.Exception.Lens: exception :: Exception a => Prism' SomeException a
- Control.Lens.Action: act :: Monad m => (s -> m a) -> Action m s a
+ Control.Lens.Action: act :: Monad m => (s -> m a) -> IndexPreservingAction m s a
- Control.Lens.Action: performs :: Monad m => Acting m e s t a b -> (a -> e) -> s -> m e
+ Control.Lens.Action: performs :: (Profunctor p, Monad m) => Over p (Effect m e) s t a b -> p a e -> s -> m e
- Control.Lens.Action: type Acting m r s t a b = (a -> Effect m r b) -> s -> Effect m r t
+ Control.Lens.Action: type Acting m r s t a b = LensLike (Effect m r) s t a b
- Control.Lens.Each: class Each i s t a b | s -> i a, t -> i b, s b -> t, t a -> s where each = traversed
+ Control.Lens.Each: class (Functor f, Index s ~ Index t) => Each f s t a b | s -> a, t -> b, s b -> t, t a -> s where each = traversed
- Control.Lens.Each: each :: Each i s t a b => IndexedTraversal i s t a b
+ Control.Lens.Each: each :: Each f s t a b => IndexedLensLike (Index s) f s t a b
- Control.Lens.Fold: (^?!) :: s -> Getting (First a) s t a b -> a
+ Control.Lens.Fold: (^?!) :: s -> Getting (Endo a) s t a b -> a
- Control.Lens.Fold: allOf :: Getting All s t a b -> (a -> Bool) -> s -> Bool
+ Control.Lens.Fold: allOf :: Profunctor p => Accessing p All s t a b -> p a Bool -> s -> Bool
- Control.Lens.Fold: anyOf :: Getting Any s t a b -> (a -> Bool) -> s -> Bool
+ Control.Lens.Fold: anyOf :: Profunctor p => Accessing p Any s t a b -> p a Bool -> s -> Bool
- Control.Lens.Fold: backwards :: LensLike (Backwards f) s t a b -> LensLike f s t a b
+ Control.Lens.Fold: backwards :: (Profunctor p, Profunctor q) => Overloading p q (Backwards f) s t a b -> Overloading p q f s t a b
- Control.Lens.Fold: concatMapOf :: Getting [r] s t a b -> (a -> [r]) -> s -> [r]
+ Control.Lens.Fold: concatMapOf :: Profunctor p => Accessing p [r] s t a b -> p a [r] -> s -> [r]
- Control.Lens.Fold: droppingWhile :: (Gettable f, Applicative f) => (a -> Bool) -> Getting (Endo (f s, f s)) s s a a -> LensLike f s s a a
+ Control.Lens.Fold: droppingWhile :: (Conjoined p, Profunctor q, Applicative f) => (a -> Bool) -> Overloading p q (Compose (State Bool) f) s t a a -> Overloading p q f s t a a
- Control.Lens.Fold: filtered :: Applicative f => (a -> Bool) -> SimpleLensLike f a a
+ Control.Lens.Fold: filtered :: (Choice p, Applicative f) => (a -> Bool) -> Overloaded' p f a a
- Control.Lens.Fold: findOf :: Getting (First a) s t a b -> (a -> Bool) -> s -> Maybe a
+ Control.Lens.Fold: findOf :: Conjoined p => Accessing p (Endo (Maybe a)) s t a b -> p a Bool -> s -> Maybe a
- Control.Lens.Fold: firstOf :: Getting (First a) s t a b -> s -> Maybe a
+ Control.Lens.Fold: firstOf :: Getting (Leftmost a) s t a b -> s -> Maybe a
- Control.Lens.Fold: foldMapOf :: Getting r s t a b -> (a -> r) -> s -> r
+ Control.Lens.Fold: foldMapOf :: Profunctor p => Accessing p r s t a b -> p a r -> s -> r
- Control.Lens.Fold: foldlOf' :: Getting (Endo (r -> r)) s t a b -> (r -> a -> r) -> r -> s -> r
+ Control.Lens.Fold: foldlOf' :: Getting (Endo (Endo r)) s t a b -> (r -> a -> r) -> r -> s -> r
- Control.Lens.Fold: foldrOf :: Getting (Endo r) s t a b -> (a -> r -> r) -> r -> s -> r
+ Control.Lens.Fold: foldrOf :: Profunctor p => Accessing p (Endo r) s t a b -> p a (r -> r) -> r -> s -> r
- Control.Lens.Fold: foldrOf' :: Getting (Dual (Endo (r -> r))) s t a b -> (a -> r -> r) -> r -> s -> r
+ Control.Lens.Fold: foldrOf' :: Getting (Dual (Endo (Endo r))) s t a b -> (a -> r -> r) -> r -> s -> r
- Control.Lens.Fold: forMOf_ :: Monad m => Getting (Sequenced m) s t a b -> s -> (a -> m r) -> m ()
+ Control.Lens.Fold: forMOf_ :: (Profunctor p, Monad m) => Accessing p (Sequenced r m) s t a b -> s -> p a (m r) -> m ()
- Control.Lens.Fold: forOf_ :: Functor f => Getting (Traversed f) s t a b -> s -> (a -> f r) -> f ()
+ Control.Lens.Fold: forOf_ :: (Profunctor p, Functor f) => Accessing p (Traversed r f) s t a b -> s -> p a (f r) -> f ()
- Control.Lens.Fold: lastOf :: Getting (Last a) s t a b -> s -> Maybe a
+ Control.Lens.Fold: lastOf :: Getting (Rightmost a) s t a b -> s -> Maybe a
- Control.Lens.Fold: lengthOf :: Getting (Sum Int) s t a b -> s -> Int
+ Control.Lens.Fold: lengthOf :: Getting (Endo (Endo Int)) s t a b -> s -> Int
- Control.Lens.Fold: mapMOf_ :: Monad m => Getting (Sequenced m) s t a b -> (a -> m r) -> s -> m ()
+ Control.Lens.Fold: mapMOf_ :: (Profunctor p, Monad m) => Accessing p (Sequenced r m) s t a b -> p a (m r) -> s -> m ()
- Control.Lens.Fold: maximumByOf :: Getting (Endo (Maybe a)) s t a b -> (a -> a -> Ordering) -> s -> Maybe a
+ Control.Lens.Fold: maximumByOf :: Getting (Endo (Endo (Maybe a))) s t a b -> (a -> a -> Ordering) -> s -> Maybe a
- Control.Lens.Fold: maximumOf :: Getting (Max a) s t a b -> s -> Maybe a
+ Control.Lens.Fold: maximumOf :: Ord a => Getting (Endo (Endo (Maybe a))) s t a b -> s -> Maybe a
- Control.Lens.Fold: minimumByOf :: Getting (Endo (Maybe a)) s t a b -> (a -> a -> Ordering) -> s -> Maybe a
+ Control.Lens.Fold: minimumByOf :: Getting (Endo (Endo (Maybe a))) s t a b -> (a -> a -> Ordering) -> s -> Maybe a
- Control.Lens.Fold: minimumOf :: Getting (Min a) s t a b -> s -> Maybe a
+ Control.Lens.Fold: minimumOf :: Ord a => Getting (Endo (Endo (Maybe a))) s t a b -> s -> Maybe a
- Control.Lens.Fold: productOf :: Getting (Product a) s t a b -> s -> a
+ Control.Lens.Fold: productOf :: Num a => Getting (Endo (Endo a)) s t a b -> s -> a
- Control.Lens.Fold: sequenceAOf_ :: Functor f => Getting (Traversed f) s t (f a) b -> s -> f ()
+ Control.Lens.Fold: sequenceAOf_ :: Functor f => Getting (Traversed a f) s t (f a) b -> s -> f ()
- Control.Lens.Fold: sequenceOf_ :: Monad m => Getting (Sequenced m) s t (m a) b -> s -> m ()
+ Control.Lens.Fold: sequenceOf_ :: Monad m => Getting (Sequenced a m) s t (m a) b -> s -> m ()
- Control.Lens.Fold: sumOf :: Getting (Sum a) s t a b -> s -> a
+ Control.Lens.Fold: sumOf :: Num a => Getting (Endo (Endo a)) s t a b -> s -> a
- Control.Lens.Fold: takingWhile :: (Gettable f, Applicative f) => (a -> Bool) -> Getting (Endo (f s)) s s a a -> LensLike f s s a a
+ Control.Lens.Fold: takingWhile :: (Conjoined p, Applicative f) => (a -> Bool) -> Over p (TakingWhile p f a a) s t a a -> Over p f s t a a
- Control.Lens.Fold: traverseOf_ :: Functor f => Getting (Traversed f) s t a b -> (a -> f r) -> s -> f ()
+ Control.Lens.Fold: traverseOf_ :: (Profunctor p, Functor f) => Accessing p (Traversed r f) s t a b -> p a (f r) -> s -> f ()
- Control.Lens.Getter: to :: (s -> a) -> Getter s a
+ Control.Lens.Getter: to :: (s -> a) -> IndexPreservingGetter s a
- Control.Lens.Getter: uses :: MonadState s m => Getting r s t a b -> (a -> r) -> m r
+ Control.Lens.Getter: uses :: (Profunctor p, MonadState s m) => Overloading p (->) (Accessor r) s t a b -> p a r -> m r
- Control.Lens.Getter: uses' :: MonadState s m => Getting r s s a a -> (a -> r) -> m r
+ Control.Lens.Getter: uses' :: (Profunctor p, MonadState s m) => Overloading' p (->) (Accessor r) s a -> p a r -> m r
- Control.Lens.Getter: views :: MonadReader s m => Getting r s t a b -> (a -> r) -> m r
+ Control.Lens.Getter: views :: (Profunctor p, MonadReader s m) => Overloading p (->) (Accessor r) s t a b -> p a r -> m r
- Control.Lens.Getter: views' :: MonadReader s m => Getting r s s a a -> (a -> r) -> m r
+ Control.Lens.Getter: views' :: (Profunctor p, MonadReader s m) => Overloading' p (->) (Accessor r) s a -> p a r -> m r
- Control.Lens.Indexed: (.>) :: Indexable i k => (b -> c) -> Indexed i a b -> k a c
+ Control.Lens.Indexed: (.>) :: (st -> r) -> (kab -> st) -> kab -> r
- Control.Lens.Indexed: (<.) :: Indexable i k => Indexed i b c -> (a -> b) -> k a c
+ Control.Lens.Indexed: (<.) :: Indexable i p => (Indexed i s t -> r) -> ((a -> b) -> s -> t) -> p a b -> r
- Control.Lens.Indexed: (<.>) :: Indexable (i, j) k => Indexed i b c -> Indexed j a b -> k a c
+ Control.Lens.Indexed: (<.>) :: Indexable (i, j) p => (Indexed i s t -> r) -> (Indexed j a b -> s -> t) -> p a b -> r
- Control.Lens.Indexed: Indexed :: ((i -> a) -> b) -> Indexed i a b
+ Control.Lens.Indexed: Indexed :: (i -> a -> b) -> Indexed i a b
- Control.Lens.Indexed: class Indexable i k
+ Control.Lens.Indexed: class Conjoined p => Indexable i p
- Control.Lens.Indexed: icompose :: Indexable k r => (i -> j -> k) -> Indexed i b c -> Indexed j a b -> r a c
+ Control.Lens.Indexed: icompose :: Indexable p c => (i -> j -> p) -> (Indexed i s t -> r) -> (Indexed j a b -> s -> t) -> c a b -> r
- Control.Lens.Indexed: indexed :: Indexable i k => ((i -> a) -> b) -> k a b
+ Control.Lens.Indexed: indexed :: Indexable i p => p a b -> i -> a -> b
- Control.Lens.Indexed: indexing :: Indexable Int k => ((a -> Indexing f b) -> s -> Indexing f t) -> k (a -> f b) (s -> f t)
+ Control.Lens.Indexed: indexing :: Indexable Int p => ((a -> Indexing f b) -> s -> Indexing f t) -> p a (f b) -> s -> f t
- Control.Lens.Indexed: indexing64 :: Indexable Int64 k => ((a -> Indexing64 f b) -> s -> Indexing64 f t) -> k (a -> f b) (s -> f t)
+ Control.Lens.Indexed: indexing64 :: Indexable Int64 p => ((a -> Indexing64 f b) -> s -> Indexing64 f t) -> p a (f b) -> s -> f t
- Control.Lens.Indexed: reindexed :: Indexable j k => (i -> j) -> Indexed i a b -> k a b
+ Control.Lens.Indexed: reindexed :: Indexable j p => (i -> j) -> (Indexed i a b -> r) -> p a b -> r
- Control.Lens.Indexed: withIndex :: Indexed i a b -> (i -> a) -> b
+ Control.Lens.Indexed: withIndex :: (Indexable i p, Functor f) => Overloading p (Indexed i) f s t (i, s) (j, t)
- Control.Lens.Internal.Zipper: Coil :: Coil Top a
+ Control.Lens.Internal.Zipper: Coil :: Coil Top Int a
- Control.Lens.Internal.Zipper: Fork :: Track h s -> {-# UNPACK #-} !Int -> SimpleLensLike (Bazaar a a) s a -> Track (h :> s) a
+ Control.Lens.Internal.Zipper: Fork :: Track h j s -> j -> AnIndexedTraversal' i s a -> Track (Zipper h j s) i a
- Control.Lens.Internal.Zipper: Snoc :: Coil h s -> SimpleLensLike (Bazaar a a) s a -> {-# UNPACK #-} !Int -> [s] -> ([a] -> s) -> [s] -> Coil (h :> s) a
+ Control.Lens.Internal.Zipper: Snoc :: !(Coil h j s) -> AnIndexedTraversal' i s a -> Int -> !Int -> !(Path j s) -> j -> (Jacket i a -> s) -> Coil (Zipper h j s) i a
- Control.Lens.Internal.Zipper: Tape :: Track h a -> {-# UNPACK #-} !Int -> Tape (h :> a)
+ Control.Lens.Internal.Zipper: Tape :: Track h i a -> i -> Tape h i a
- Control.Lens.Internal.Zipper: Track :: Track Top a
+ Control.Lens.Internal.Zipper: Track :: Track Top Int a
- Control.Lens.Internal.Zipper: Zipper :: (Coil h a) -> {-# UNPACK #-} !Int -> [a] -> a -> [a] -> :> h a
+ Control.Lens.Internal.Zipper: Zipper :: !(Coil h i a) -> Int -> !Int -> !(Path i a) -> i -> a -> Zipper h i a
- Control.Lens.Internal.Zipper: data (:>) h a
+ Control.Lens.Internal.Zipper: data (:@) a i
- Control.Lens.Internal.Zipper: data Coil :: * -> * -> *
+ Control.Lens.Internal.Zipper: data Coil t i a
- Control.Lens.Internal.Zipper: data Tape k
+ Control.Lens.Internal.Zipper: data Tape h i a
- Control.Lens.Internal.Zipper: data Track :: * -> * -> *
+ Control.Lens.Internal.Zipper: data Track t i a
- Control.Lens.Internal.Zipper: downward :: SimpleLensLike (Context a a) s a -> (h :> s) -> (h :> s) :> a
+ Control.Lens.Internal.Zipper: downward :: ALens' s a -> h :> (s :@ j) -> (h :> (s :@ j)) :>> a
- Control.Lens.Internal.Zipper: focus :: SimpleIndexedLens (Tape (h :> a)) (h :> a) a
+ Control.Lens.Internal.Zipper: focus :: IndexedLens' i (Zipper h i a) a
- Control.Lens.Internal.Zipper: focusedContext :: Zipping h a => (h :> a) -> Context a a (Zipped h a)
+ Control.Lens.Internal.Zipper: focusedContext :: (Indexable i p, Zipping h a) => (h :> (a :@ i)) -> Pretext p a a (Zipped h a)
- Control.Lens.Internal.Zipper: fromWithin :: SimpleLensLike (Bazaar a a) s a -> (h :> s) -> (h :> s) :> a
+ Control.Lens.Internal.Zipper: fromWithin :: LensLike' (Indexing (Bazaar' (Indexed Int) a)) s a -> (h :> (s :@ j)) -> (h :> (s :@ j)) :>> a
- Control.Lens.Internal.Zipper: jerkTo :: MonadPlus m => Int -> (h :> a) -> m (h :> a)
+ Control.Lens.Internal.Zipper: jerkTo :: MonadPlus m => Int -> (h :> (a :@ i)) -> m (h :> (a :@ i))
- Control.Lens.Internal.Zipper: leftmost :: (a :> b) -> a :> b
+ Control.Lens.Internal.Zipper: leftmost :: a :> (b :@ i) -> a :> (b :@ i)
- Control.Lens.Internal.Zipper: leftward :: MonadPlus m => (h :> a) -> m (h :> a)
+ Control.Lens.Internal.Zipper: leftward :: MonadPlus m => h :> (a :@ i) -> m (h :> (a :@ i))
- Control.Lens.Internal.Zipper: peel :: Coil h a -> Track h a
+ Control.Lens.Internal.Zipper: peel :: Coil h i a -> Track h i a
- Control.Lens.Internal.Zipper: recoil :: Zipping h a => Coil h a -> [a] -> Zipped h a
+ Control.Lens.Internal.Zipper: recoil :: Zipping h a => Coil h i a -> Jacket i a -> Zipped h a
- Control.Lens.Internal.Zipper: restoreNearTape :: MonadPlus m => Tape (h :> a) -> Zipped h a -> m (h :> a)
+ Control.Lens.Internal.Zipper: restoreNearTape :: MonadPlus m => Tape h i a -> Zipped h a -> m (Zipper h i a)
- Control.Lens.Internal.Zipper: restoreNearTrack :: MonadPlus m => Track h a -> Zipped h a -> m (h :> a)
+ Control.Lens.Internal.Zipper: restoreNearTrack :: MonadPlus m => Track h i a -> Zipped h a -> m (Zipper h i a)
- Control.Lens.Internal.Zipper: restoreTape :: MonadPlus m => Tape (h :> a) -> Zipped h a -> m (h :> a)
+ Control.Lens.Internal.Zipper: restoreTape :: MonadPlus m => Tape h i a -> Zipped h a -> m (Zipper h i a)
- Control.Lens.Internal.Zipper: restoreTrack :: MonadPlus m => Track h a -> Zipped h a -> m (h :> a)
+ Control.Lens.Internal.Zipper: restoreTrack :: MonadPlus m => Track h i a -> Zipped h a -> m (Zipper h i a)
- Control.Lens.Internal.Zipper: rezip :: Zipping h a => (h :> a) -> Zipped h a
+ Control.Lens.Internal.Zipper: rezip :: Zipping h a => (h :> (a :@ i)) -> Zipped h a
- Control.Lens.Internal.Zipper: rightmost :: (a :> b) -> a :> b
+ Control.Lens.Internal.Zipper: rightmost :: a :> (b :@ i) -> a :> (b :@ i)
- Control.Lens.Internal.Zipper: rightward :: MonadPlus m => (h :> a) -> m (h :> a)
+ Control.Lens.Internal.Zipper: rightward :: MonadPlus m => h :> (a :@ i) -> m (h :> (a :@ i))
- Control.Lens.Internal.Zipper: saveTape :: (h :> a) -> Tape (h :> a)
+ Control.Lens.Internal.Zipper: saveTape :: Zipper h i a -> Tape h i a
- Control.Lens.Internal.Zipper: teeth :: (h :> a) -> Int
+ Control.Lens.Internal.Zipper: teeth :: h :> (a :@ i) -> Int
- Control.Lens.Internal.Zipper: tooth :: (h :> a) -> Int
+ Control.Lens.Internal.Zipper: tooth :: Zipper h i a -> Int
- Control.Lens.Internal.Zipper: tugTo :: Int -> (h :> a) -> h :> a
+ Control.Lens.Internal.Zipper: tugTo :: Int -> h :> (a :@ i) -> h :> (a :@ i)
- Control.Lens.Internal.Zipper: unsafelyRestoreTape :: Tape (h :> a) -> Zipped h a -> h :> a
+ Control.Lens.Internal.Zipper: unsafelyRestoreTape :: Tape h i a -> Zipped h a -> Zipper h i a
- Control.Lens.Internal.Zipper: unsafelyRestoreTrack :: Track h a -> Zipped h a -> h :> a
+ Control.Lens.Internal.Zipper: unsafelyRestoreTrack :: Track h i a -> Zipped h a -> Zipper h i a
- Control.Lens.Internal.Zipper: upward :: ((h :> s) :> a) -> h :> s
+ Control.Lens.Internal.Zipper: upward :: Ord j => (h :> (s :@ j)) :> (a :@ i) -> h :> (s :@ j)
- Control.Lens.Internal.Zipper: within :: MonadPlus m => SimpleLensLike (Bazaar a a) s a -> (h :> s) -> m ((h :> s) :> a)
+ Control.Lens.Internal.Zipper: within :: MonadPlus m => LensLike' (Indexing (Bazaar' (Indexed Int) a)) s a -> (h :> (s :@ j)) -> m ((h :> (s :@ j)) :>> a)
- Control.Lens.Internal.Zipper: withins :: SimpleLensLike (Bazaar a a) s a -> (h :> s) -> [(h :> s) :> a]
+ Control.Lens.Internal.Zipper: withins :: MonadPlus m => LensLike' (Indexing (Bazaar' (Indexed Int) a)) s a -> (h :> (s :@ j)) -> m ((h :> (s :@ j)) :>> a)
- Control.Lens.Internal.Zipper: zipper :: a -> Top :> a
+ Control.Lens.Internal.Zipper: zipper :: a -> Top :>> a
- Control.Lens.Iso: anon :: a -> (a -> Bool) -> Simple Iso (Maybe a) a
+ Control.Lens.Iso: anon :: a -> (a -> Bool) -> Iso' (Maybe a) a
- Control.Lens.Iso: class Strict s t a b | s -> a, a -> s, b -> t, t -> b, s b -> a t, a t -> s b
+ Control.Lens.Iso: class Strict s a | s -> a, a -> s
- Control.Lens.Iso: enum :: Enum a => Simple Iso Int a
+ Control.Lens.Iso: enum :: Enum a => Iso' Int a
- Control.Lens.Iso: iso :: (Isomorphic k, Functor f) => (s -> a) -> (b -> t) -> k (a -> f b) (s -> f t)
+ Control.Lens.Iso: iso :: (s -> a) -> (b -> t) -> Iso s t a b
- Control.Lens.Iso: non :: Eq a => a -> Simple Iso (Maybe a) a
+ Control.Lens.Iso: non :: Eq a => a -> Iso' (Maybe a) a
- Control.Lens.Iso: simple :: Simple Iso a a
+ Control.Lens.Iso: simple :: Iso' a a
- Control.Lens.Iso: strict :: Strict s t a b => Iso s t a b
+ Control.Lens.Iso: strict :: Strict s a => Iso' s a
- Control.Lens.Iso: type AnIso s t a b = Overloaded Isoid Mutator s t a b
+ Control.Lens.Iso: type AnIso s t a b = Exchange a b a (Mutator b) -> Exchange a b s (Mutator t)
- Control.Lens.Loupe: (#%%=) :: MonadState s m => Loupe s s a b -> (a -> (r, b)) -> m r
+ Control.Lens.Loupe: (#%%=) :: MonadState s m => ALens s s a b -> (a -> (r, b)) -> m r
- Control.Lens.Loupe: (#%%~) :: Functor f => Loupe s t a b -> (a -> f b) -> s -> f t
+ Control.Lens.Loupe: (#%%~) :: Functor f => ALens s t a b -> (a -> f b) -> s -> f t
- Control.Lens.Loupe: (#%=) :: MonadState s m => Loupe s s a b -> (a -> b) -> m ()
+ Control.Lens.Loupe: (#%=) :: MonadState s m => ALens s s a b -> (a -> b) -> m ()
- Control.Lens.Loupe: (#%~) :: Loupe s t a b -> (a -> b) -> s -> t
+ Control.Lens.Loupe: (#%~) :: ALens s t a b -> (a -> b) -> s -> t
- Control.Lens.Loupe: (#=) :: MonadState s m => Loupe s s a b -> b -> m ()
+ Control.Lens.Loupe: (#=) :: MonadState s m => ALens s s a b -> b -> m ()
- Control.Lens.Loupe: (#~) :: Loupe s t a b -> b -> s -> t
+ Control.Lens.Loupe: (#~) :: ALens s t a b -> b -> s -> t
- Control.Lens.Loupe: (<#%=) :: MonadState s m => Loupe s s a b -> (a -> b) -> m b
+ Control.Lens.Loupe: (<#%=) :: MonadState s m => ALens s s a b -> (a -> b) -> m b
- Control.Lens.Loupe: (<#%~) :: Loupe s t a b -> (a -> b) -> s -> (b, t)
+ Control.Lens.Loupe: (<#%~) :: ALens s t a b -> (a -> b) -> s -> (b, t)
- Control.Lens.Loupe: (<#=) :: MonadState s m => Loupe s s a b -> b -> m b
+ Control.Lens.Loupe: (<#=) :: MonadState s m => ALens s s a b -> b -> m b
- Control.Lens.Loupe: (<#~) :: Loupe s t a b -> b -> s -> (b, t)
+ Control.Lens.Loupe: (<#~) :: ALens s t a b -> b -> s -> (b, t)
- Control.Lens.Loupe: (^#) :: s -> Loupe s t a b -> a
+ Control.Lens.Loupe: (^#) :: s -> ALens s t a b -> a
- Control.Lens.Loupe: cloneLens :: Functor f => LensLike (Context a b) s t a b -> (a -> f b) -> s -> f t
+ Control.Lens.Loupe: cloneLens :: ALens s t a b -> Lens s t a b
- Control.Lens.Loupe: storing :: Loupe s t a b -> b -> s -> t
+ Control.Lens.Loupe: storing :: ALens s t a b -> b -> s -> t
- Control.Lens.Loupe: type ALens s t a b = Loupe s t a b
+ Control.Lens.Loupe: type ALens s t a b = LensLike (Pretext (->) a b) s t a b
- Control.Lens.Loupe: type ALens' s a = Loupe s s a a
+ Control.Lens.Loupe: type ALens' s a = ALens s s a a
- Control.Lens.Loupe: type Loupe s t a b = LensLike (Context a b) s t a b
+ Control.Lens.Loupe: type Loupe s t a b = LensLike (Pretext (->) a b) s t a b
- Control.Lens.Plated: contextsOf :: SimpleLensLike (Bazaar a a) a a -> a -> [Context a a a]
+ Control.Lens.Plated: contextsOf :: ATraversal' a a -> a -> [Context a a a]
- Control.Lens.Plated: contextsOn :: Plated a => LensLike (Bazaar a a) s t a a -> s -> [Context a a t]
+ Control.Lens.Plated: contextsOn :: Plated a => ATraversal s t a a -> s -> [Context a a t]
- Control.Lens.Plated: contextsOnOf :: LensLike (Bazaar a a) s t a a -> SimpleLensLike (Bazaar a a) a a -> s -> [Context a a t]
+ Control.Lens.Plated: contextsOnOf :: ATraversal s t a a -> ATraversal' a a -> s -> [Context a a t]
- Control.Lens.Plated: holes :: Plated a => a -> [Context a a a]
+ Control.Lens.Plated: holes :: Plated a => a -> [Pretext (->) a a a]
- Control.Lens.Plated: holesOn :: LensLike (Bazaar a a) s t a a -> s -> [Context a a t]
+ Control.Lens.Plated: holesOn :: Conjoined p => Overloading p (->) (Bazaar p a a) s t a a -> s -> [Pretext p a a t]
- Control.Lens.Plated: holesOnOf :: LensLike (Bazaar r r) s t a b -> LensLike (Bazaar r r) a b r r -> s -> [Context r r t]
+ Control.Lens.Plated: holesOnOf :: Conjoined p => LensLike (Bazaar p r r) s t a b -> Overloading p (->) (Bazaar p r r) a b r r -> s -> [Pretext p r r t]
- Control.Lens.Plated: parts :: Plated a => Simple Lens a [a]
+ Control.Lens.Plated: parts :: Plated a => Lens' a [a]
- Control.Lens.Plated: plate :: Plated a => Simple Traversal a a
+ Control.Lens.Plated: plate :: Plated a => Traversal' a a
- Control.Lens.Plated: rewriteMOf :: Monad m => SimpleLensLike (WrappedMonad m) a a -> (a -> m (Maybe a)) -> a -> m a
+ Control.Lens.Plated: rewriteMOf :: Monad m => LensLike' (WrappedMonad m) a a -> (a -> m (Maybe a)) -> a -> m a
- Control.Lens.Plated: rewriteMOnOf :: Monad m => LensLike (WrappedMonad m) s t a a -> SimpleLensLike (WrappedMonad m) a a -> (a -> m (Maybe a)) -> s -> m t
+ Control.Lens.Plated: rewriteMOnOf :: Monad m => LensLike (WrappedMonad m) s t a a -> LensLike' (WrappedMonad m) a a -> (a -> m (Maybe a)) -> s -> m t
- Control.Lens.Plated: rewriteOf :: SimpleSetting a a -> (a -> Maybe a) -> a -> a
+ Control.Lens.Plated: rewriteOf :: ASetter' a a -> (a -> Maybe a) -> a -> a
- Control.Lens.Plated: rewriteOn :: Plated a => Setting s t a a -> (a -> Maybe a) -> s -> t
+ Control.Lens.Plated: rewriteOn :: Plated a => ASetter s t a a -> (a -> Maybe a) -> s -> t
- Control.Lens.Plated: rewriteOnOf :: Setting s t a a -> SimpleSetting a a -> (a -> Maybe a) -> s -> t
+ Control.Lens.Plated: rewriteOnOf :: ASetter s t a a -> ASetter' a a -> (a -> Maybe a) -> s -> t
- Control.Lens.Plated: transformMOf :: Monad m => SimpleLensLike (WrappedMonad m) a a -> (a -> m a) -> a -> m a
+ Control.Lens.Plated: transformMOf :: Monad m => LensLike' (WrappedMonad m) a a -> (a -> m a) -> a -> m a
- Control.Lens.Plated: transformMOnOf :: Monad m => LensLike (WrappedMonad m) s a a a -> SimpleLensLike (WrappedMonad m) a a -> (a -> m a) -> s -> m a
+ Control.Lens.Plated: transformMOnOf :: Monad m => LensLike (WrappedMonad m) s a a a -> LensLike' (WrappedMonad m) a a -> (a -> m a) -> s -> m a
- Control.Lens.Plated: transformOf :: SimpleSetting a a -> (a -> a) -> a -> a
+ Control.Lens.Plated: transformOf :: ASetter' a a -> (a -> a) -> a -> a
- Control.Lens.Plated: transformOn :: Plated a => Setting s t a a -> (a -> a) -> s -> t
+ Control.Lens.Plated: transformOn :: Plated a => ASetter s t a a -> (a -> a) -> s -> t
- Control.Lens.Plated: transformOnOf :: Setting s t a a -> SimpleSetting a a -> (a -> a) -> s -> t
+ Control.Lens.Plated: transformOnOf :: ASetter s t a a -> ASetter' a a -> (a -> a) -> s -> t
- Control.Lens.Prism: prism :: (Prismatic k, Applicative f) => (b -> t) -> (s -> Either t a) -> k (a -> f b) (s -> f t)
+ Control.Lens.Prism: prism :: (b -> t) -> (s -> Either t a) -> Prism s t a b
- Control.Lens.Prism: type APrism s t a b = Overloaded Prismoid Mutator s t a b
+ Control.Lens.Prism: type APrism s t a b = Market a b a (Mutator b) -> Market a b s (Mutator t)
- Control.Lens.Setter: (%=) :: MonadState s m => Setting s s a b -> (a -> b) -> m ()
+ Control.Lens.Setter: (%=) :: (Profunctor p, MonadState s m) => Setting p s s a b -> p a b -> m ()
- Control.Lens.Setter: (%~) :: Setting s t a b -> (a -> b) -> s -> t
+ Control.Lens.Setter: (%~) :: Profunctor p => Setting p s t a b -> p a b -> s -> t
- Control.Lens.Setter: (&&=) :: MonadState s m => SimpleSetting s Bool -> Bool -> m ()
+ Control.Lens.Setter: (&&=) :: MonadState s m => ASetter' s Bool -> Bool -> m ()
- Control.Lens.Setter: (&&~) :: Setting s t Bool Bool -> Bool -> s -> t
+ Control.Lens.Setter: (&&~) :: ASetter s t Bool Bool -> Bool -> s -> t
- Control.Lens.Setter: (**=) :: (MonadState s m, Floating a) => SimpleSetting s a -> a -> m ()
+ Control.Lens.Setter: (**=) :: (MonadState s m, Floating a) => ASetter' s a -> a -> m ()
- Control.Lens.Setter: (**~) :: Floating a => Setting s t a a -> a -> s -> t
+ Control.Lens.Setter: (**~) :: Floating a => ASetter s t a a -> a -> s -> t
- Control.Lens.Setter: (*=) :: (MonadState s m, Num a) => SimpleSetting s a -> a -> m ()
+ Control.Lens.Setter: (*=) :: (MonadState s m, Num a) => ASetter' s a -> a -> m ()
- Control.Lens.Setter: (*~) :: Num a => Setting s t a a -> a -> s -> t
+ Control.Lens.Setter: (*~) :: Num a => ASetter s t a a -> a -> s -> t
- Control.Lens.Setter: (+=) :: (MonadState s m, Num a) => SimpleSetting s a -> a -> m ()
+ Control.Lens.Setter: (+=) :: (MonadState s m, Num a) => ASetter' s a -> a -> m ()
- Control.Lens.Setter: (+~) :: Num a => Setting s t a a -> a -> s -> t
+ Control.Lens.Setter: (+~) :: Num a => ASetter s t a a -> a -> s -> t
- Control.Lens.Setter: (-=) :: (MonadState s m, Num a) => SimpleSetting s a -> a -> m ()
+ Control.Lens.Setter: (-=) :: (MonadState s m, Num a) => ASetter' s a -> a -> m ()
- Control.Lens.Setter: (-~) :: Num a => Setting s t a a -> a -> s -> t
+ Control.Lens.Setter: (-~) :: Num a => ASetter s t a a -> a -> s -> t
- Control.Lens.Setter: (.=) :: MonadState s m => Setting s s a b -> b -> m ()
+ Control.Lens.Setter: (.=) :: MonadState s m => ASetter s s a b -> b -> m ()
- Control.Lens.Setter: (.~) :: Setting s t a b -> b -> s -> t
+ Control.Lens.Setter: (.~) :: ASetter s t a b -> b -> s -> t
- Control.Lens.Setter: (//=) :: (MonadState s m, Fractional a) => SimpleSetting s a -> a -> m ()
+ Control.Lens.Setter: (//=) :: (MonadState s m, Fractional a) => ASetter' s a -> a -> m ()
- Control.Lens.Setter: (//~) :: Fractional s => Setting a b s s -> s -> a -> b
+ Control.Lens.Setter: (//~) :: Fractional a => ASetter s t a a -> a -> s -> t
- Control.Lens.Setter: (<.=) :: MonadState s m => Setting s s a b -> b -> m b
+ Control.Lens.Setter: (<.=) :: MonadState s m => ASetter s s a b -> b -> m b
- Control.Lens.Setter: (<.~) :: Setting s t a b -> b -> s -> (b, t)
+ Control.Lens.Setter: (<.~) :: ASetter s t a b -> b -> s -> (b, t)
- Control.Lens.Setter: (<>=) :: (MonadState s m, Monoid a) => SimpleSetting s a -> a -> m ()
+ Control.Lens.Setter: (<>=) :: (MonadState s m, Monoid a) => ASetter' s a -> a -> m ()
- Control.Lens.Setter: (<>~) :: Monoid a => Setting s t a a -> a -> s -> t
+ Control.Lens.Setter: (<>~) :: Monoid a => ASetter s t a a -> a -> s -> t
- Control.Lens.Setter: (<?=) :: MonadState s m => Setting s s a (Maybe b) -> b -> m b
+ Control.Lens.Setter: (<?=) :: MonadState s m => ASetter s s a (Maybe b) -> b -> m b
- Control.Lens.Setter: (<?~) :: Setting s t a (Maybe b) -> b -> s -> (b, t)
+ Control.Lens.Setter: (<?~) :: ASetter s t a (Maybe b) -> b -> s -> (b, t)
- Control.Lens.Setter: (<~) :: MonadState s m => Setting s s a b -> m b -> m ()
+ Control.Lens.Setter: (<~) :: MonadState s m => ASetter s s a b -> m b -> m ()
- Control.Lens.Setter: (?=) :: MonadState s m => Setting s s a (Maybe b) -> b -> m ()
+ Control.Lens.Setter: (?=) :: MonadState s m => ASetter s s a (Maybe b) -> b -> m ()
- Control.Lens.Setter: (?~) :: Setting s t a (Maybe b) -> b -> s -> t
+ Control.Lens.Setter: (?~) :: ASetter s t a (Maybe b) -> b -> s -> t
- Control.Lens.Setter: (^=) :: (MonadState s m, Num a, Integral e) => SimpleSetting s a -> e -> m ()
+ Control.Lens.Setter: (^=) :: (MonadState s m, Num a, Integral e) => ASetter' s a -> e -> m ()
- Control.Lens.Setter: (^^=) :: (MonadState s m, Fractional a, Integral e) => SimpleSetting s a -> e -> m ()
+ Control.Lens.Setter: (^^=) :: (MonadState s m, Fractional a, Integral e) => ASetter' s a -> e -> m ()
- Control.Lens.Setter: (^^~) :: (Fractional a, Integral e) => Setting s t a a -> e -> s -> t
+ Control.Lens.Setter: (^^~) :: (Fractional a, Integral e) => ASetter s t a a -> e -> s -> t
- Control.Lens.Setter: (^~) :: (Num a, Integral e) => Setting s t a a -> e -> s -> t
+ Control.Lens.Setter: (^~) :: (Num a, Integral e) => ASetter s t a a -> e -> s -> t
- Control.Lens.Setter: (||=) :: MonadState s m => SimpleSetting s Bool -> Bool -> m ()
+ Control.Lens.Setter: (||=) :: MonadState s m => ASetter' s Bool -> Bool -> m ()
- Control.Lens.Setter: (||~) :: Setting s t Bool Bool -> Bool -> s -> t
+ Control.Lens.Setter: (||~) :: ASetter s t Bool Bool -> Bool -> s -> t
- Control.Lens.Setter: assign :: MonadState s m => Setting s s a b -> b -> m ()
+ Control.Lens.Setter: assign :: MonadState s m => ASetter s s a b -> b -> m ()
- Control.Lens.Setter: class Applicative f => Settable f where untainted# g = g `seq` \ x -> untainted (g x) tainted# g = g `seq` \ x -> pure (g x)
+ Control.Lens.Setter: class (Applicative f, Distributive f, Traversable f) => Settable f where untaintedDot g = g `seq` rmap untainted g taintedDot g = g `seq` rmap pure g
- Control.Lens.Setter: mapOf :: Setting s t a b -> (a -> b) -> s -> t
+ Control.Lens.Setter: mapOf :: Profunctor p => Setting p s t a b -> p a b -> s -> t
- Control.Lens.Setter: over :: Setting s t a b -> (a -> b) -> s -> t
+ Control.Lens.Setter: over :: Profunctor p => Setting p s t a b -> p a b -> s -> t
- Control.Lens.Setter: set :: Setting s t a b -> b -> s -> t
+ Control.Lens.Setter: set :: ASetter s t a b -> b -> s -> t
- Control.Lens.Setter: set' :: Setting s s a a -> a -> s -> s
+ Control.Lens.Setter: set' :: ASetter' s a -> a -> s -> s
- Control.Lens.Setter: sets :: ((a -> b) -> s -> t) -> Setter s t a b
+ Control.Lens.Setter: sets :: (Profunctor p, Profunctor q, Settable f) => (p a b -> q s t) -> Overloading p q f s t a b
- Control.Lens.Setter: type Setting s t a b = (a -> Mutator b) -> s -> Mutator t
+ Control.Lens.Setter: type Setting p s t a b = p a (Mutator b) -> s -> Mutator t
- Control.Lens.TH: buildTraversals :: Simple Lens LensRules Bool
+ Control.Lens.TH: buildTraversals :: Lens' LensRules Bool
- Control.Lens.TH: classRequired :: Simple Lens LensRules Bool
+ Control.Lens.TH: classRequired :: Lens' LensRules Bool
- Control.Lens.TH: createClass :: Simple Lens LensRules Bool
+ Control.Lens.TH: createClass :: Lens' LensRules Bool
- Control.Lens.TH: createInstance :: Simple Lens LensRules Bool
+ Control.Lens.TH: createInstance :: Lens' LensRules Bool
- Control.Lens.TH: generateSignatures :: Simple Lens LensRules Bool
+ Control.Lens.TH: generateSignatures :: Lens' LensRules Bool
- Control.Lens.TH: handleSingletons :: Simple Lens LensRules Bool
+ Control.Lens.TH: handleSingletons :: Lens' LensRules Bool
- Control.Lens.TH: lensClass :: Simple Lens LensRules (String -> Maybe (String, String))
+ Control.Lens.TH: lensClass :: Lens' LensRules (String -> Maybe (String, String))
- Control.Lens.TH: lensField :: Simple Lens LensRules (String -> Maybe String)
+ Control.Lens.TH: lensField :: Lens' LensRules (String -> Maybe String)
- Control.Lens.TH: lensFlags :: Simple Lens LensRules (Set LensFlag)
+ Control.Lens.TH: lensFlags :: Lens' LensRules (Set LensFlag)
- Control.Lens.TH: lensIso :: Simple Lens LensRules (String -> Maybe String)
+ Control.Lens.TH: lensIso :: Lens' LensRules (String -> Maybe String)
- Control.Lens.TH: partialLenses :: Simple Lens LensRules Bool
+ Control.Lens.TH: partialLenses :: Lens' LensRules Bool
- Control.Lens.TH: simpleLenses :: Simple Lens LensRules Bool
+ Control.Lens.TH: simpleLenses :: Lens' LensRules Bool
- Control.Lens.TH: singletonAndField :: Simple Lens LensRules Bool
+ Control.Lens.TH: singletonAndField :: Lens' LensRules Bool
- Control.Lens.TH: singletonIso :: Simple Lens LensRules Bool
+ Control.Lens.TH: singletonIso :: Lens' LensRules Bool
- Control.Lens.TH: singletonRequired :: Simple Lens LensRules Bool
+ Control.Lens.TH: singletonRequired :: Lens' LensRules Bool
- Control.Lens.Traversal: Bazaar :: (forall f. Applicative f => (a -> f b) -> f t) -> Bazaar a b t
+ Control.Lens.Traversal: Bazaar :: (forall f. Applicative f => p a (f b) -> f t) -> Bazaar p a b t
- Control.Lens.Traversal: beside :: Applicative f => LensLike f s t a b -> LensLike f s' t' a b -> LensLike f (s, s') (t, t') a b
+ Control.Lens.Traversal: beside :: (Representable q, Applicative (Rep q), Applicative f) => Overloading p q f s t a b -> Overloading p q f s' t' a b -> Overloading p q f (s, s') (t, t') a b
- Control.Lens.Traversal: cloneTraversal :: Applicative f => ((a -> Bazaar a b b) -> s -> Bazaar a b t) -> (a -> f b) -> s -> f t
+ Control.Lens.Traversal: cloneTraversal :: ATraversal s t a b -> Traversal s t a b
- Control.Lens.Traversal: dropping :: Applicative f => Int -> SimpleLensLike (Indexing f) s a -> SimpleLensLike f s a
+ Control.Lens.Traversal: dropping :: (Conjoined p, Applicative f) => Int -> Over p (Indexing f) s t a a -> Over p f s t a a
- Control.Lens.Traversal: forMOf :: LensLike (WrappedMonad m) s t a b -> s -> (a -> m b) -> m t
+ Control.Lens.Traversal: forMOf :: Profunctor p => Over p (WrappedMonad m) s t a b -> s -> p a (m b) -> m t
- Control.Lens.Traversal: forOf :: LensLike f s t a b -> s -> (a -> f b) -> f t
+ Control.Lens.Traversal: forOf :: Over p f s t a b -> s -> p a (f b) -> f t
- Control.Lens.Traversal: holesOf :: LensLike (Bazaar a a) s t a a -> s -> [Context a a t]
+ Control.Lens.Traversal: holesOf :: Conjoined p => Over p (Bazaar p a a) s t a a -> s -> [Pretext p a a t]
- Control.Lens.Traversal: loci :: Traversal (Bazaar a c s) (Bazaar b c s) a b
+ Control.Lens.Traversal: loci :: Traversal (Bazaar (->) a c s) (Bazaar (->) b c s) a b
- Control.Lens.Traversal: mapAccumLOf :: LensLike (State acc) s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
+ Control.Lens.Traversal: mapAccumLOf :: Conjoined p => Over p (State acc) s t a b -> p acc (a -> (acc, b)) -> acc -> s -> (acc, t)
- Control.Lens.Traversal: mapAccumROf :: LensLike (Backwards (State acc)) s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
+ Control.Lens.Traversal: mapAccumROf :: Conjoined p => Over p (Backwards (State acc)) s t a b -> p acc (a -> (acc, b)) -> acc -> s -> (acc, t)
- Control.Lens.Traversal: mapMOf :: LensLike (WrappedMonad m) s t a b -> (a -> m b) -> s -> m t
+ Control.Lens.Traversal: mapMOf :: Profunctor p => Over p (WrappedMonad m) s t a b -> p a (m b) -> s -> m t
- Control.Lens.Traversal: newtype Bazaar a b t
+ Control.Lens.Traversal: newtype Bazaar p a b t
- Control.Lens.Traversal: partsOf :: Functor f => LensLike (BazaarT a a f) s t a a -> LensLike f s t [a] [a]
+ Control.Lens.Traversal: partsOf :: Functor f => Traversing (->) f s t a a -> LensLike f s t [a] [a]
- Control.Lens.Traversal: partsOf' :: LensLike (Bazaar a a) s t a a -> Lens s t [a] [a]
+ Control.Lens.Traversal: partsOf' :: ATraversal s t a a -> Lens s t [a] [a]
- Control.Lens.Traversal: runBazaar :: Bazaar a b t -> forall f. Applicative f => (a -> f b) -> f t
+ Control.Lens.Traversal: runBazaar :: Bazaar p a b t -> forall f. Applicative f => p a (f b) -> f t
- Control.Lens.Traversal: singular :: Functor f => LensLike (BazaarT a a f) s t a a -> LensLike f s t a a
+ Control.Lens.Traversal: singular :: (Conjoined p, Functor f) => Over p (BazaarT p f a a) s t a a -> Over p f s t a a
- Control.Lens.Traversal: taking :: Applicative f => Int -> SimpleLensLike (BazaarT a a f) s a -> SimpleLensLike f s a
+ Control.Lens.Traversal: taking :: (Conjoined p, Applicative f) => Int -> Over p (BazaarT p f a a) s t a a -> Over p f s t a a
- Control.Lens.Traversal: traverseOf :: LensLike f s t a b -> (a -> f b) -> s -> f t
+ Control.Lens.Traversal: traverseOf :: Over p f s t a b -> p a (f b) -> s -> f t
- Control.Lens.Traversal: unsafePartsOf :: Functor f => LensLike (BazaarT a b f) s t a b -> LensLike f s t [a] [b]
+ Control.Lens.Traversal: unsafePartsOf :: Functor f => Traversing (->) f s t a b -> LensLike f s t [a] [b]
- Control.Lens.Traversal: unsafePartsOf' :: LensLike (Bazaar a b) s t a b -> Lens s t [a] [b]
+ Control.Lens.Traversal: unsafePartsOf' :: ATraversal s t a b -> Lens s t [a] [b]
- Control.Lens.Traversal: unsafeSingular :: Functor f => LensLike (BazaarT a b f) s t a b -> LensLike f s t a b
+ Control.Lens.Traversal: unsafeSingular :: (Conjoined p, Functor f) => Over p (BazaarT p f a b) s t a b -> Over p f s t a b
- Control.Lens.Tuple: _1 :: Field1 s t a b => Lens s t a b
+ Control.Lens.Tuple: _1 :: Field1 s t a b => IndexedLens Int s t a b
- Control.Lens.Tuple: _2 :: Field2 s t a b => Lens s t a b
+ Control.Lens.Tuple: _2 :: Field2 s t a b => IndexedLens Int s t a b
- Control.Lens.Tuple: _3 :: Field3 s t a b => Lens s t a b
+ Control.Lens.Tuple: _3 :: Field3 s t a b => IndexedLens Int s t a b
- Control.Lens.Tuple: _4 :: Field4 s t a b => Lens s t a b
+ Control.Lens.Tuple: _4 :: Field4 s t a b => IndexedLens Int s t a b
- Control.Lens.Tuple: _5 :: Field5 s t a b => Lens s t a b
+ Control.Lens.Tuple: _5 :: Field5 s t a b => IndexedLens Int s t a b
- Control.Lens.Tuple: _6 :: Field6 s t a b => Lens s t a b
+ Control.Lens.Tuple: _6 :: Field6 s t a b => IndexedLens Int s t a b
- Control.Lens.Tuple: _7 :: Field7 s t a b => Lens s t a b
+ Control.Lens.Tuple: _7 :: Field7 s t a b => IndexedLens Int s t a b
- Control.Lens.Tuple: _8 :: Field8 s t a b => Lens s t a b
+ Control.Lens.Tuple: _8 :: Field8 s t a b => IndexedLens Int s t a b
- Control.Lens.Tuple: _9 :: Field9 s t a b => Lens s t a b
+ Control.Lens.Tuple: _9 :: Field9 s t a b => IndexedLens Int s t a b
- Control.Lens.Type: type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t
+ Control.Lens.Type: type MonadicFold m s a = forall f r. (Effective m r f, Applicative f) => (a -> f a) -> s -> f s
- Control.Lens.Type: type Overloaded k f s t a b = k (a -> f b) (s -> f t)
+ Control.Lens.Type: type Overloaded p f s t a b = p a (f b) -> p s (f t)
- Control.Lens.Zipper: data (:>) h a
+ Control.Lens.Zipper: data (:@) a i
- Control.Lens.Zipper: data Tape k
+ Control.Lens.Zipper: data Tape h i a
- Control.Lens.Zipper: downward :: SimpleLensLike (Context a a) s a -> (h :> s) -> (h :> s) :> a
+ Control.Lens.Zipper: downward :: ALens' s a -> h :> (s :@ j) -> (h :> (s :@ j)) :>> a
- Control.Lens.Zipper: focus :: SimpleIndexedLens (Tape (h :> a)) (h :> a) a
+ Control.Lens.Zipper: focus :: IndexedLens' i (Zipper h i a) a
- Control.Lens.Zipper: focusedContext :: Zipping h a => (h :> a) -> Context a a (Zipped h a)
+ Control.Lens.Zipper: focusedContext :: (Indexable i p, Zipping h a) => (h :> (a :@ i)) -> Pretext p a a (Zipped h a)
- Control.Lens.Zipper: fromWithin :: SimpleLensLike (Bazaar a a) s a -> (h :> s) -> (h :> s) :> a
+ Control.Lens.Zipper: fromWithin :: LensLike' (Indexing (Bazaar' (Indexed Int) a)) s a -> (h :> (s :@ j)) -> (h :> (s :@ j)) :>> a
- Control.Lens.Zipper: jerkTo :: MonadPlus m => Int -> (h :> a) -> m (h :> a)
+ Control.Lens.Zipper: jerkTo :: MonadPlus m => Int -> (h :> (a :@ i)) -> m (h :> (a :@ i))
- Control.Lens.Zipper: leftmost :: (a :> b) -> a :> b
+ Control.Lens.Zipper: leftmost :: a :> (b :@ i) -> a :> (b :@ i)
- Control.Lens.Zipper: leftward :: MonadPlus m => (h :> a) -> m (h :> a)
+ Control.Lens.Zipper: leftward :: MonadPlus m => h :> (a :@ i) -> m (h :> (a :@ i))
- Control.Lens.Zipper: restoreNearTape :: MonadPlus m => Tape (h :> a) -> Zipped h a -> m (h :> a)
+ Control.Lens.Zipper: restoreNearTape :: MonadPlus m => Tape h i a -> Zipped h a -> m (Zipper h i a)
- Control.Lens.Zipper: restoreTape :: MonadPlus m => Tape (h :> a) -> Zipped h a -> m (h :> a)
+ Control.Lens.Zipper: restoreTape :: MonadPlus m => Tape h i a -> Zipped h a -> m (Zipper h i a)
- Control.Lens.Zipper: rezip :: Zipping h a => (h :> a) -> Zipped h a
+ Control.Lens.Zipper: rezip :: Zipping h a => (h :> (a :@ i)) -> Zipped h a
- Control.Lens.Zipper: rightmost :: (a :> b) -> a :> b
+ Control.Lens.Zipper: rightmost :: a :> (b :@ i) -> a :> (b :@ i)
- Control.Lens.Zipper: rightward :: MonadPlus m => (h :> a) -> m (h :> a)
+ Control.Lens.Zipper: rightward :: MonadPlus m => h :> (a :@ i) -> m (h :> (a :@ i))
- Control.Lens.Zipper: saveTape :: (h :> a) -> Tape (h :> a)
+ Control.Lens.Zipper: saveTape :: Zipper h i a -> Tape h i a
- Control.Lens.Zipper: teeth :: (h :> a) -> Int
+ Control.Lens.Zipper: teeth :: h :> (a :@ i) -> Int
- Control.Lens.Zipper: tooth :: (h :> a) -> Int
+ Control.Lens.Zipper: tooth :: Zipper h i a -> Int
- Control.Lens.Zipper: tugTo :: Int -> (h :> a) -> h :> a
+ Control.Lens.Zipper: tugTo :: Int -> h :> (a :@ i) -> h :> (a :@ i)
- Control.Lens.Zipper: unsafelyRestoreTape :: Tape (h :> a) -> Zipped h a -> h :> a
+ Control.Lens.Zipper: unsafelyRestoreTape :: Tape h i a -> Zipped h a -> Zipper h i a
- Control.Lens.Zipper: upward :: ((h :> s) :> a) -> h :> s
+ Control.Lens.Zipper: upward :: Ord j => (h :> (s :@ j)) :> (a :@ i) -> h :> (s :@ j)
- Control.Lens.Zipper: within :: MonadPlus m => SimpleLensLike (Bazaar a a) s a -> (h :> s) -> m ((h :> s) :> a)
+ Control.Lens.Zipper: within :: MonadPlus m => LensLike' (Indexing (Bazaar' (Indexed Int) a)) s a -> (h :> (s :@ j)) -> m ((h :> (s :@ j)) :>> a)
- Control.Lens.Zipper: withins :: SimpleLensLike (Bazaar a a) s a -> (h :> s) -> [(h :> s) :> a]
+ Control.Lens.Zipper: withins :: MonadPlus m => LensLike' (Indexing (Bazaar' (Indexed Int) a)) s a -> (h :> (s :@ j)) -> m ((h :> (s :@ j)) :>> a)
- Control.Lens.Zipper: zipper :: a -> Top :> a
+ Control.Lens.Zipper: zipper :: a -> Top :>> a
- Control.Lens.Zoom: class (MonadReader b m, MonadReader a n) => Magnify m n k b a | m -> b k, n -> a k, m a -> n, n b -> m
+ Control.Lens.Zoom: class (Magnified m ~ Magnified n, MonadReader b m, MonadReader a n) => Magnify m n b a | m -> b, n -> a, m a -> n, n b -> m
- Control.Lens.Zoom: class (MonadState s m, MonadState t n) => Zoom m n k s t | m -> s k, n -> t k, m t -> n, n s -> m
+ Control.Lens.Zoom: class (Zoomed m ~ Zoomed n, MonadState s m, MonadState t n) => Zoom m n s t | m -> s, n -> t, m t -> n, n s -> m
- Control.Lens.Zoom: magnify :: Magnify m n k b a => ((b -> k c b) -> a -> k c a) -> m c -> n c
+ Control.Lens.Zoom: magnify :: Magnify m n b a => LensLike' (Magnified m c) a b -> m c -> n c
- Control.Lens.Zoom: zoom :: Zoom m n k s t => SimpleLensLike (k c) t s -> m c -> n c
+ Control.Lens.Zoom: zoom :: Zoom m n s t => LensLike' (Zoomed m c) t s -> m c -> n c
- Control.Parallel.Strategies.Lens: evalOf :: SimpleLensLike Eval s a -> Strategy a -> Strategy s
+ Control.Parallel.Strategies.Lens: evalOf :: LensLike' Eval s a -> Strategy a -> Strategy s
- Control.Parallel.Strategies.Lens: parOf :: SimpleLensLike Eval s a -> Strategy a -> Strategy s
+ Control.Parallel.Strategies.Lens: parOf :: LensLike' Eval s a -> Strategy a -> Strategy s
- Data.Array.Lens: ixmapped :: (IArray a e, Ix i, Ix j) => (i, i) -> Setter (a j e) (a i e) i j
+ Data.Array.Lens: ixmapped :: (IArray a e, Ix i, Ix j) => (i, i) -> IndexPreservingSetter (a j e) (a i e) i j
- Data.Bits.Lens: (.&.=) :: (MonadState s m, Bits a) => Simple Setting s a -> a -> m ()
+ Data.Bits.Lens: (.&.=) :: (MonadState s m, Bits a) => ASetter' s a -> a -> m ()
- Data.Bits.Lens: (.&.~) :: Bits a => Setting s t a a -> a -> s -> t
+ Data.Bits.Lens: (.&.~) :: Bits a => ASetter s t a a -> a -> s -> t
- Data.Bits.Lens: (.|.=) :: (MonadState s m, Bits a) => Simple Setting s a -> a -> m ()
+ Data.Bits.Lens: (.|.=) :: (MonadState s m, Bits a) => ASetter' s a -> a -> m ()
- Data.Bits.Lens: (.|.~) :: Bits a => Setting s t a a -> a -> s -> t
+ Data.Bits.Lens: (.|.~) :: Bits a => ASetter s t a a -> a -> s -> t
- Data.Bits.Lens: (<.&.=) :: (MonadState s m, Bits a) => SimpleLensLike ((,) a) s a -> a -> m a
+ Data.Bits.Lens: (<.&.=) :: (MonadState s m, Bits a) => LensLike' ((,) a) s a -> a -> m a
- Data.Bits.Lens: (<.|.=) :: (MonadState s m, Bits a) => SimpleLensLike ((,) a) s a -> a -> m a
+ Data.Bits.Lens: (<.|.=) :: (MonadState s m, Bits a) => LensLike' ((,) a) s a -> a -> m a
- Data.Bits.Lens: bitAt :: Bits b => Int -> SimpleIndexedLens Int b Bool
+ Data.Bits.Lens: bitAt :: Bits b => Int -> IndexedLens' Int b Bool
- Data.Bits.Lens: bits :: (Num b, Bits b) => SimpleIndexedTraversal Int b Bool
+ Data.Bits.Lens: bits :: (Num b, Bits b) => IndexedTraversal' Int b Bool
- Data.ByteString.Lazy.Lens: bytes :: SimpleIndexedTraversal Int ByteString Word8
+ Data.ByteString.Lazy.Lens: bytes :: IndexedTraversal' Int64 ByteString Word8
- Data.ByteString.Lazy.Lens: chars :: SimpleIndexedTraversal Int ByteString Char
+ Data.ByteString.Lazy.Lens: chars :: IndexedTraversal' Int64 ByteString Char
- Data.ByteString.Lazy.Lens: packedBytes :: Simple Iso [Word8] ByteString
+ Data.ByteString.Lazy.Lens: packedBytes :: Iso' [Word8] ByteString
- Data.ByteString.Lazy.Lens: packedChars :: Simple Iso String ByteString
+ Data.ByteString.Lazy.Lens: packedChars :: Iso' String ByteString
- Data.ByteString.Lens: bytes :: IsByteString t => SimpleIndexedTraversal Int t Word8
+ Data.ByteString.Lens: bytes :: IsByteString t => IndexedTraversal' Int t Word8
- Data.ByteString.Lens: chars :: IsByteString t => SimpleIndexedTraversal Int t Char
+ Data.ByteString.Lens: chars :: IsByteString t => IndexedTraversal' Int t Char
- Data.ByteString.Lens: class IsByteString t where bytes = from packedBytes .> itraversed chars = from packedChars .> itraversed
+ Data.ByteString.Lens: class IsByteString t where bytes = from packedBytes . traversed chars = from packedChars . traversed
- Data.ByteString.Lens: packedBytes :: IsByteString t => Simple Iso [Word8] t
+ Data.ByteString.Lens: packedBytes :: IsByteString t => Iso' [Word8] t
- Data.ByteString.Lens: packedChars :: IsByteString t => Simple Iso String t
+ Data.ByteString.Lens: packedChars :: IsByteString t => Iso' String t
- Data.ByteString.Strict.Lens: bytes :: SimpleIndexedTraversal Int ByteString Word8
+ Data.ByteString.Strict.Lens: bytes :: IndexedTraversal' Int ByteString Word8
- Data.ByteString.Strict.Lens: chars :: SimpleIndexedTraversal Int ByteString Char
+ Data.ByteString.Strict.Lens: chars :: IndexedTraversal' Int ByteString Char
- Data.ByteString.Strict.Lens: packedBytes :: Simple Iso [Word8] ByteString
+ Data.ByteString.Strict.Lens: packedBytes :: Iso' [Word8] ByteString
- Data.ByteString.Strict.Lens: packedChars :: Simple Iso String ByteString
+ Data.ByteString.Strict.Lens: packedChars :: Iso' String ByteString
- Data.Complex.Lens: _conjugate :: RealFloat a => Simple Iso (Complex a) (Complex a)
+ Data.Complex.Lens: _conjugate :: RealFloat a => Iso' (Complex a) (Complex a)
- Data.Complex.Lens: _imagPart :: Simple Lens (Complex a) a
+ Data.Complex.Lens: _imagPart :: Lens' (Complex a) a
- Data.Complex.Lens: _magnitude :: RealFloat a => Simple Lens (Complex a) a
+ Data.Complex.Lens: _magnitude :: RealFloat a => Lens' (Complex a) a
- Data.Complex.Lens: _phase :: RealFloat a => Simple Lens (Complex a) a
+ Data.Complex.Lens: _phase :: RealFloat a => Lens' (Complex a) a
- Data.Complex.Lens: _polar :: RealFloat a => Simple Iso (Complex a) (a, a)
+ Data.Complex.Lens: _polar :: RealFloat a => Iso' (Complex a) (a, a)
- Data.Complex.Lens: _realPart :: Simple Lens (Complex a) a
+ Data.Complex.Lens: _realPart :: Lens' (Complex a) a
- Data.Data.Lens: biplate :: (Data s, Typeable a) => Simple Traversal s a
+ Data.Data.Lens: biplate :: (Data s, Typeable a) => Traversal' s a
- Data.Data.Lens: onceUpon :: (Data s, Typeable a) => (s -> a) -> SimpleIndexedTraversal Int s a
+ Data.Data.Lens: onceUpon :: (Data s, Typeable a) => (s -> a) -> IndexedTraversal' Int s a
- Data.Data.Lens: onceUpon' :: (Data s, Typeable a) => (s -> a) -> SimpleIndexedLens Int s a
+ Data.Data.Lens: onceUpon' :: (Data s, Typeable a) => (s -> a) -> IndexedLens' Int s a
- Data.Data.Lens: template :: (Data s, Typeable a) => Simple Traversal s a
+ Data.Data.Lens: template :: (Data s, Typeable a) => Traversal' s a
- Data.Data.Lens: tinplate :: (Data s, Typeable a) => Simple Traversal s a
+ Data.Data.Lens: tinplate :: (Data s, Typeable a) => Traversal' s a
- Data.Data.Lens: uniplate :: Data a => Simple Traversal a a
+ Data.Data.Lens: uniplate :: Data a => Traversal' a a
- Data.Data.Lens: upon :: (Indexable [Int] k, Applicative f, Data s, Data a) => (s -> a) -> k (a -> f a) (s -> f s)
+ Data.Data.Lens: upon :: (Indexable [Int] p, Applicative f, Data s, Data a) => (s -> a) -> p a (f a) -> s -> f s
- Data.Data.Lens: upon' :: (Data s, Data a) => (s -> a) -> SimpleIndexedLens [Int] s a
+ Data.Data.Lens: upon' :: (Data s, Data a) => (s -> a) -> IndexedLens' [Int] s a
- Data.HashSet.Lens: setmapped :: (Eq i, Hashable i, Eq j, Hashable j) => Setter (HashSet i) (HashSet j) i j
+ Data.HashSet.Lens: setmapped :: (Eq i, Hashable i, Eq j, Hashable j) => IndexPreservingSetter (HashSet i) (HashSet j) i j
- Data.IntSet.Lens: setmapped :: Simple Setter IntSet Int
+ Data.IntSet.Lens: setmapped :: IndexPreservingSetter' IntSet Int
- Data.List.Lens: strippingPrefix :: Eq a => [a] -> Simple Prism [a] [a]
+ Data.List.Lens: strippingPrefix :: Eq a => [a] -> Prism' [a] [a]
- Data.List.Split.Lens: condensing :: Simple Lens (Splitter a) Bool
+ Data.List.Split.Lens: condensing :: Lens' (Splitter a) Bool
- Data.List.Split.Lens: delimiting :: Simple Lens (Splitter a) DelimPolicy
+ Data.List.Split.Lens: delimiting :: Lens' (Splitter a) DelimPolicy
- Data.List.Split.Lens: keepFinalBlanks :: Simple Lens (Splitter a) Bool
+ Data.List.Split.Lens: keepFinalBlanks :: Lens' (Splitter a) Bool
- Data.List.Split.Lens: keepInitialBlanks :: Simple Lens (Splitter a) Bool
+ Data.List.Split.Lens: keepInitialBlanks :: Lens' (Splitter a) Bool
- Data.Sequence.Lens: sliced :: Int -> Int -> SimpleIndexedTraversal Int (Seq a) a
+ Data.Sequence.Lens: sliced :: Int -> Int -> IndexedTraversal' Int (Seq a) a
- Data.Sequence.Lens: slicedFrom :: Int -> SimpleIndexedTraversal Int (Seq a) a
+ Data.Sequence.Lens: slicedFrom :: Int -> IndexedTraversal' Int (Seq a) a
- Data.Sequence.Lens: slicedTo :: Int -> SimpleIndexedTraversal Int (Seq a) a
+ Data.Sequence.Lens: slicedTo :: Int -> IndexedTraversal' Int (Seq a) a
- Data.Set.Lens: setmapped :: (Ord i, Ord j) => Setter (Set i) (Set j) i j
+ Data.Set.Lens: setmapped :: (Ord i, Ord j) => IndexPreservingSetter (Set i) (Set j) i j
- Data.Text.Lazy.Lens: packed :: Simple Iso String Text
+ Data.Text.Lazy.Lens: packed :: Iso' String Text
- Data.Text.Lazy.Lens: text :: SimpleIndexedTraversal Int Text Char
+ Data.Text.Lazy.Lens: text :: IndexedTraversal' Int Text Char
- Data.Text.Lens: class IsText t where text = from packed .> itraversed
+ Data.Text.Lens: class IsText t where text = from packed . itraversed
- Data.Text.Lens: packed :: IsText t => Simple Iso String t
+ Data.Text.Lens: packed :: IsText t => Iso' String t
- Data.Text.Lens: text :: IsText t => SimpleIndexedTraversal Int t Char
+ Data.Text.Lens: text :: IsText t => IndexedTraversal' Int t Char
- Data.Text.Strict.Lens: packed :: Simple Iso String Text
+ Data.Text.Strict.Lens: packed :: Iso' String Text
- Data.Text.Strict.Lens: text :: SimpleIndexedTraversal Int Text Char
+ Data.Text.Strict.Lens: text :: IndexedTraversal' Int Text Char
- Data.Tree.Lens: branches :: SimpleLens (Tree a) [Tree a]
+ Data.Tree.Lens: branches :: Lens' (Tree a) [Tree a]
- Data.Tree.Lens: root :: SimpleLens (Tree a) a
+ Data.Tree.Lens: root :: Lens' (Tree a) a
- Data.Typeable.Lens: _cast :: (Typeable s, Typeable a) => Simple Traversal s a
+ Data.Typeable.Lens: _cast :: (Typeable s, Typeable a) => Traversal' s a
- Data.Typeable.Lens: _gcast :: (Typeable s, Typeable a) => Simple Traversal (c s) (c a)
+ Data.Typeable.Lens: _gcast :: (Typeable s, Typeable a) => Traversal' (c s) (c a)
- Data.Vector.Generic.Lens: asStream :: Vector v a => Simple Iso (v a) (Stream a)
+ Data.Vector.Generic.Lens: asStream :: Vector v a => Iso' (v a) (Stream a)
- Data.Vector.Generic.Lens: asStreamR :: Vector v a => Simple Iso (v a) (Stream a)
+ Data.Vector.Generic.Lens: asStreamR :: Vector v a => Iso' (v a) (Stream a)
- Data.Vector.Generic.Lens: cloned :: Vector v a => Simple Iso (v a) (New v a)
+ Data.Vector.Generic.Lens: cloned :: Vector v a => Iso' (v a) (New v a)
- Data.Vector.Generic.Lens: forced :: Vector v a => Simple Iso (v a) (v a)
+ Data.Vector.Generic.Lens: forced :: Vector v a => Iso' (v a) (v a)
- Data.Vector.Generic.Lens: ordinals :: Vector v a => [Int] -> SimpleIndexedTraversal Int (v a) a
+ Data.Vector.Generic.Lens: ordinals :: Vector v a => [Int] -> IndexedTraversal' Int (v a) a
- Data.Vector.Generic.Lens: reversed :: Vector v a => Simple Iso (v a) (v a)
+ Data.Vector.Generic.Lens: reversed :: Vector v a => Iso' (v a) (v a)
- Data.Vector.Generic.Lens: sliced :: Vector v a => Int -> Int -> SimpleLens (v a) (v a)
+ Data.Vector.Generic.Lens: sliced :: Vector v a => Int -> Int -> Lens' (v a) (v a)
- Data.Vector.Generic.Lens: vector :: Vector v a => Simple Iso [a] (v a)
+ Data.Vector.Generic.Lens: vector :: Vector v a => Iso' [a] (v a)
- Data.Vector.Lens: ordinals :: [Int] -> SimpleIndexedTraversal Int (Vector a) a
+ Data.Vector.Lens: ordinals :: [Int] -> IndexedTraversal' Int (Vector a) a
- Data.Vector.Lens: sliced :: Int -> Int -> SimpleLens (Vector a) (Vector a)
+ Data.Vector.Lens: sliced :: Int -> Int -> Lens' (Vector a) (Vector a)
- GHC.Generics.Lens: generic :: Generic a => Simple Iso a (Rep a b)
+ GHC.Generics.Lens: generic :: Generic a => Iso' a (Rep a b)
- GHC.Generics.Lens: generic1 :: Generic1 f => Simple Iso (f a) (Rep1 f a)
+ GHC.Generics.Lens: generic1 :: Generic1 f => Iso' (f a) (Rep1 f a)
- GHC.Generics.Lens: tinplate :: (Generic a, GTraversal (Rep a), Typeable b) => Simple Traversal a b
+ GHC.Generics.Lens: tinplate :: (Generic a, GTraversal (Rep a), Typeable b) => Traversal' a b
- Language.Haskell.TH.Lens: conFields :: Simple Traversal Con StrictType
+ Language.Haskell.TH.Lens: conFields :: Traversal' Con StrictType
- Language.Haskell.TH.Lens: conNamedFields :: Simple Traversal Con VarStrictType
+ Language.Haskell.TH.Lens: conNamedFields :: Traversal' Con VarStrictType
- Language.Haskell.TH.Lens: name :: HasName t => Simple Lens t Name
+ Language.Haskell.TH.Lens: name :: HasName t => Lens' t Name
- Language.Haskell.TH.Lens: typeVars :: HasTypeVars t => Simple Traversal t Name
+ Language.Haskell.TH.Lens: typeVars :: HasTypeVars t => Traversal' t Name
- Language.Haskell.TH.Lens: typeVarsEx :: HasTypeVars t => Set Name -> Simple Traversal t Name
+ Language.Haskell.TH.Lens: typeVarsEx :: HasTypeVars t => Set Name -> Traversal' t Name
- System.FilePath.Lens: (<.>=) :: MonadState s m => SimpleSetting s FilePath -> String -> m ()
+ System.FilePath.Lens: (<.>=) :: MonadState s m => ASetter' s FilePath -> String -> m ()
- System.FilePath.Lens: (<.>~) :: Setting s a FilePath FilePath -> String -> s -> a
+ System.FilePath.Lens: (<.>~) :: ASetter s a FilePath FilePath -> String -> s -> a
- System.FilePath.Lens: (</>=) :: MonadState s m => SimpleSetting s FilePath -> FilePath -> m ()
+ System.FilePath.Lens: (</>=) :: MonadState s m => ASetter' s FilePath -> FilePath -> m ()
- System.FilePath.Lens: (</>~) :: Setting s t FilePath FilePath -> FilePath -> s -> t
+ System.FilePath.Lens: (</>~) :: ASetter s t FilePath FilePath -> FilePath -> s -> t
- System.FilePath.Lens: (<<.>=) :: MonadState s m => SimpleLensLike ((,) FilePath) s FilePath -> String -> m FilePath
+ System.FilePath.Lens: (<<.>=) :: MonadState s m => LensLike' ((,) FilePath) s FilePath -> String -> m FilePath
- System.FilePath.Lens: (<</>=) :: MonadState s m => SimpleLensLike ((,) FilePath) s FilePath -> FilePath -> m FilePath
+ System.FilePath.Lens: (<</>=) :: MonadState s m => LensLike' ((,) FilePath) s FilePath -> FilePath -> m FilePath
- System.FilePath.Lens: basename :: Simple Lens FilePath FilePath
+ System.FilePath.Lens: basename :: Lens' FilePath FilePath
- System.FilePath.Lens: directory :: Simple Lens FilePath FilePath
+ System.FilePath.Lens: directory :: Lens' FilePath FilePath
- System.FilePath.Lens: extension :: Simple Lens FilePath FilePath
+ System.FilePath.Lens: extension :: Lens' FilePath FilePath
- System.FilePath.Lens: filename :: Simple Lens FilePath FilePath
+ System.FilePath.Lens: filename :: Lens' FilePath FilePath

Files

.gitignore view
@@ -7,3 +7,7 @@ .DS_Store .*.swp .*.swo+*.o+*.hi+*~+*#
.travis.yml view
@@ -1,17 +1,19 @@ language: haskell before_install:   # Uncomment whenever hackage is down.-  # - mkdir -p ~/.cabal && cp config ~/.cabal/config && cabal update+  # - mkdir -p ~/.cabal && cp travis/config ~/.cabal/config && cabal update    # Try installing some of the build-deps with apt-get for speed.-  - ./travis-cabal-apt-install --only-dependencies --force-reinstall $mode+  - travis/cabal-apt-install --only-dependencies --force-reinstall $mode +  - sudo apt-get -q -y install hlint || cabal install hlint+ install:-  - cabal configure $mode+  - cabal configure -flib-Werror $mode   - cabal build  script:-  - $script+  - $script && hlint src --cpp-define HLINT  notifications:   irc:
+ AUTHORS.markdown view
@@ -0,0 +1,45 @@+Lens started as a one man project by++* [Edward Kmett](mailto:ekmett@gmail.com) [@ekmett](https://github.com/ekmett)++But it has been greatly enriched by opening it up to community development.++Many people have contributed patches, documentation, wiki pages, bug reports, test cases and massive quantities of code to `lens` including (among others):++* [Shachaf Ben-Kiki](mailto:shachaf@gmail.com) [@shachaf](https://github.com/shachaf)+* Elliott Hird [@ehird](https://github.com/ehird)+* [Johan Kiviniemi](mailto:lens@johan.kiviniemi.name) [@ion1](https://github.com/ion1)+* [Bas Dirks](mailto:ik@basdirks.eu) [@basdirks](https://github.com/basdirks)+* [Eric Mertens](mailto:emertens@gmail.com) [@glguy](https://github.com/glguy)+* [Michael Sloan](mailto:mgsloan@gmail.com) [@mgsloan](https://github.com/mgsloan)+* [Alexander Altman](mailto:alexanderaltman@me.com) [@phtariensflame](https://github.com/phtariensflame)+* [Austin Seipp](mailto:mad.one@gmail.com) [@thoughtpolice](https://github.com/thoughtpolice)+* [Dag Odenhall](mailto:dag.odenhall@gmail.com) [@dag](https://github.com/dag)+* [Aristid Breitkreuz](mailto:aristidb+lens@gmail.com) [@aristidb](https://github.com/aristidb)+* [Simon Hengel](mailto:sol@typeful.net) [@sol](https://github.com/sol)+* [@startling](https://github.com/startling)+* [Mike Ledger](mailto:eleventynine@gmail.com) [@mikeplus64](https://github.com/mikeplus64)+* `nand` [@nandykins](https://github.com/nandykins)+* [Adrian Keet](mailto:arkeet@gmail.com) [@arkeet](https://github.com/arkeet)+* [Matvey B. Aksenov](mailto:matvey.aksenov@gmail.com) [@supki](https://github.com/supki)+* [Eyal Lotem](mailto:eyal.lotem+github@gmail.com) [@Peaker](https://github.com/Peaker)+* [Oliver Charles](mailto:ollie@ocharles.org.uk) [@ocharles](https://github.com/ocharles)+* Liyang HU [@liyang](https://github.com/liyang)+* [Carter Schonwald](mailto:carter.schonwald@gmail.com) [@cartazio](https://github.com/cartazio)+* [Mark Wright](mailto:gienah@gentoo.org) [@markwright](https://github.com/markwright)+* [Nathan van Doorn](mailto:nvd1234@gmail.com) [@Taneb](https://github.com/Taneb)+* Ville Tirronen [@aleator](https://github.com/aleator)+* [Mikhail Vorozhtsov](mailto:mikhail.vorozhtsov@gmail.com) [@mvv](https://github.com/mvv)+* [Brent Yorgey](mailto:byorgey@gmail.com) [@byorgey](https://github.com/byorgey)+* [Dan Rosén](mailto:danr@fripost.org) [@danr](https://github.com/danr)+* Yair Chuchem [@yairchu](https://github.com/yairchu)+* [Michael Thompson](mailto:what_is_it_to_do_anything@yahoo.com) [@michaelt](https://github.com/michaelt)+* [John Wiegley](mailto:johnw@newartisans.com) [@jwiegley](https://github.com/jwiegley)++You can watch them carry on the quest for bragging rights in the [contributors graph](https://github.com/ekmett/lens/graphs/contributors).++Omission from this list is by no means an attempt to discount your contributions!++Thank you for all of your help!++-Edward Kmett
CHANGELOG.markdown view
@@ -1,14 +1,73 @@-3.7.6 [maintenance release]-------* Fixed an issue with the `Complex` `Each` instance.--3.7.5 [maintenance release]-------* Fixed an errant `LANGUAGE` pragma--3.7.4 [maintenance release]-------* Backported the API for `ALens` and `ALens'` to support `snap` builds on old platforms.+3.8+---+* Overall:+  * Replaced each of the different `SimpleFoo` type aliases with `Foo'` throughout. The various `Simple` aliases can still be found in `Control.Lens.Simple` but are now deprecated.+  * Made sweeping changes to `Iso` and `Prism` and `Indexed` lenses internally. They are now based on `profunctors`. This affects how you use `indexed` in the resulting code and dramatically changed the meaning of `Overloaded`.+  * Generalized combinators to pass through indices unmodified wherever possible and added indexed variants to existing combinators. There are hundreds of these changes and they would swamp this list.+* `Control.Exception.Lens`+  * This module was created to add combinators and prisms that make it possible to work with GHC's extensible exceptions and monad transformer stacks more easily. There are knock-on changes in `Data.Dynamic.Lens`, `System.Exit.Lens`, and `System.IO.Error.Lens`.+* `Control.Lens.At`+  * Moved `At(at)` and `Contains(contains)` and factored out `Ixed(ix)`.+  * Deprecated `_at` and `resultAt`.+  * Removed various `ordinal` and `ix` combinators, which are subsumed by `Ixed(ix)`.+* `Control.Lens.Cons`+  * Consoldiated the various `_head`, `_tail`, `_init` and `_last` traversals that were scattered around the place into a pair of `Cons` and `Snoc` classes that provide `_Cons` and `_Snoc` prisms respectively, and combinators that build on top.+* `Control.Lens.Each`+  * Generalized the signature of `Each` to permit it to provide an `IndexedSetter` for `((->) e)`.+  * `Each` now uses an `Index` type family that is shared with `At`, `Ixed` and `Contains` to indicate these operations are related.+* `Control.Lens.Equality`+  * Added as a stronger form of `Iso` that can be used to safely cast.+  * Added the adverb `simply`, which can be used to simplify the types of most combinators in the library so they only take a simple lens, simple traversal, etc as their first argument instead. e.g. `simply view` forces `a ~ b`, `s ~ t` in the argument to `view`.+* `Control.Lens.Fold`+  * Added `foldr1Of'` and `foldl1Of'`.+  * Added `has` and `hasn't`.+* `Control.Lens.Indexed`+  * The various indexed combinators for each type were distributed to their respective modules. This module grew to encompass the remaining index-specifics.+  * Added `index` and `indices`, and removed `iwhere` and `iwhereOf`. Use `itraversed.indices even` and `bar.indices (>3)` instead.+* `Control.Lens.Internal`+  * This module was exploded into more manageable component modules.+* `Control.Lens.Iso`+  * `Strict(strict)` is now a `Simple Iso`.+  * Added `magma` and `imagma` which can be used to provide a 'debugging view' of a `Traversal`.+* `Control.Lens.Lens`+  * Restructuring split this module out from `Control.Lens.Type` and merged the contents `Control.Lens.IndexedLens`.+* `Control.Lens.Level`+  * This module was created to provide the breadth-first-search Traversals `levels` and `ilevels` which can be used to do (optionally depth-limited) breadth-first searches through arbitrary traversals reaching all leaves at finite depth in finite time. To use these in full accordance with the laws you should restrict yourself to commutative operations and finite containers, but they are useful even in the absence of these properties.+* `Control.Lens.Loupe`+  * In the interest of consistency, the `Loupe` alias has been deprecated in favor of `ALens`.+  * `Loupe` (and `ALens`) are now defined in terms of `Pretext` rather than `Context`. This permits them to be cloned at a reduced cost reducing the call for `ReifiedLens`.+* `Control.Lens.Operators`+  * Added this module for users who insist on qualified use, but want access to the operators. They can `import qualified Control.Lens as Lens` and `import Control.Lens.Operators` unqualified.+* `Control.Lens.Prism`+  * Added `prism'` to construct `SimplePrism`s.+* `Control.Lens.Reified`+  * Consolidated the various `ReifiedFoo` definitions into one module.+* `Control.Lens.Representable`+  * This module was removed. Its functionality may be split out into a separate package, but currently the `linear` package exports is own `Linear.Core` module to provide this functionality. It was taking lots of useful names for little functionality and didn't feel like the rest of the API.+* `Control.Lens.Review`+  * This module now factors the `review` functionality out of `Prism` and exposes `unto`, which is to `review` what `to` is to `view`.+* `Control.Lens.Setter`+  * Added `contramapped` and `argument` for mapping over inputs.+* `Control.Lens.Simple`+  * Removed the infix lens aliases and repurposed the module to house the now deprecated `SimpleFoo` type aliases, which were replaced universally with `Foo'`.+* `Control.Lens.TH`+  * `makeLenses` now generates `Lens'` and `Traversal'` where appropriate+  * Added `makePrisms` as a generalized `makeIso` that automatically generates a `Prism` for each constructor. `makePrisms` generates names with an `_Foo` convention. This was consolidated upon throughout the library to reduce namespace conflicts between prisms and lenses.+  * Added `makeFields`, which generates classes for each individual field in a data type.+  * Added `makeWrapped`, which automatically generates a `Wrapped` instance for a newtype.+* `Control.Lens.Type`+  * This module was repurposed to provide a single home for all the standard lens-like type aliases used when producing lenses. You still need to go to their respective modules to find the types for consuming lens-likes if you want to generate your own lens combinators+* `Control.Lens.Wrapped`+  * Added `wrapped'` and `unwrapped'` for scenarios where you need the help with type inference.+* `Control.Lens.Zipper`+  * Converted `Zipper` to walk a magma based on the original structure and to use indices from indexed traversals when restoring from tape. This also means that when zipping around within a balanced structure with ascending keys `moveTo` can operate in logarithmic time, but required changing the `Zipper` type to add the index type.+* `Data.Bits.Lens`+  * Added `byteAt`.+* `Data.ByteString.Lens`+  * `Data.ByteString.Lazy.Lens` now uses `Int64`-based indexing.+  * The `Traversal` for strict `ByteStrings` now construct a balanced tree up to a given grain size. This permits zipper based seeking to operate in logarithmic time and speeds up many traversals.+* `Numeric.Lens`+  * Created. `base` shows and reads integers at base-2 through base-36. `integral` can be used as a safe `fromInteger`/`toInteger`.  3.7.3 [maintenance release] -----@@ -84,6 +143,7 @@ * Readded `leftmost` and `rightmost` due to the verbosity of `farthest leftward`/`farthest rightward`. * Added `preview`/`previews`/`firstOf` and deprecated `headOf`. * Added `iview`/`iviews`/`iuse`/`iuses` to `Control.Lens.IndexedGetter`.+* We've generalized the type of Bazaar and provided generalized variants of `partsOf`, etc. that used it.  3.6.0.4 [maintenance release] -------@@ -132,7 +192,7 @@ [3.5](https://github.com/ekmett/lens/issues?milestone=8&state=closed) --- * Fixed a potential SafeHaskell issue where a user could use `undefined` to derive `unsafeCoerce`. You now have to import an explicitly-  Unsafe module and create an instance of `Trustworthy` for your type to cause this behavior, so if you do, its on your head, not mine. :)+  Unsafe module and create an instance of `Trustworthy` for your type to cause this behavior, so if you do, it's on your head, not mine. :) * Renamed `EvilBazaar` to `BazaarT`. * Moved a lot of internals around. Most notably, `Gettable`, `Settable` and `Effective` have moved to `Control.Lens.Classes`. * Exposed `partsOf'` and `unsafePartsOf'` in `Control.Lens.Traversal` to reduce reliance on `BazaarT` in `Control.Lens.Zipper`@@ -172,6 +232,7 @@ * Fixed a bug that caused `resultAt` to give wrong answers most of the time. * Changed `resultAt` to an `IndexedLens` and moved it to `Control.Lens.IndexedLens` * Changed `ignored` to an `IndexedTraversal` and moved it to `Control.Lens.IndexedTraversal`+* We've relinquished the name `value`.  3.2 ---
LICENSE view
@@ -1,4 +1,4 @@-Copyright 2012 Edward Kmett+Copyright 2012-2013 Edward Kmett  All rights reserved. 
README.markdown view
@@ -1,10 +1,12 @@ Lens: Lenses, Folds, and Traversals ================================== -[![Build Status](https://secure.travis-ci.org/ekmett/lens.png?branch=master)](http://travis-ci.org/ekmett/lens)+[![Build Status](https://secure.travis-ci.org/ekmett/lens.png)](http://travis-ci.org/ekmett/lens)  This package provides families of [lenses](https://github.com/ekmett/lens/blob/master/src/Control/Lens/Type.hs), [isomorphisms](https://github.com/ekmett/lens/blob/master/src/Control/Lens/Iso.hs), [folds](https://github.com/ekmett/lens/blob/master/src/Control/Lens/Fold.hs), [traversals](https://github.com/ekmett/lens/blob/master/src/Control/Lens/Traversal.hs), [getters](https://github.com/ekmett/lens/blob/master/src/Control/Lens/Getter.hs) and [setters](https://github.com/ekmett/lens/blob/master/src/Control/Lens/Setter.hs). +If you are looking for where to get started, [a crash course video](http://youtu.be/cefnmjtAolY?hd=1) on how `lens` was constructed and how to use the basics is available on youtube. It is best watched in high definition to see the slides, but the [slides](http://comonad.com/haskell/Lenses-Folds-and-Traversals-NYC.pdf) are also available if you want to use them to follow along.+ The [FAQ](https://github.com/ekmett/lens/wiki/FAQ), which provides links to a large number of different resources for learning about lenses and an overview of the [derivation](https://github.com/ekmett/lens/wiki/Derivation) of these types can be found on the [Lens Wiki](https://github.com/ekmett/lens/wiki) along with a brief [overview](https://github.com/ekmett/lens/wiki/Overview) and some [examples](https://github.com/ekmett/lens/wiki/Examples).  Documentation is available through [github](http://ekmett.github.com/lens/frames.html) (for HEAD) or [hackage](http://hackage.haskell.org/package/lens) for the current and preceding releases.@@ -51,7 +53,7 @@ ("hello",(42,"!!!")) ``` -You can make a `Getter` out of a pure functions with `to`.+You can make a `Getter` out of a pure function with `to`.  ```haskell ghci> "hello"^.to length@@ -246,94 +248,94 @@   <td><a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:-60-.-126-"><code>&lt;.~</code></a></td>   <td><a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:.-61-"><code>.=</code></a></td>   <td><a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:assign"><code>assign</code></a>,<a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:-60-.-61-"><code>&lt;.=</code></a></td>-  <td>Replace target(s). <a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-60--60-.-126-"><code>&lt;&lt;.~</code> and-      <a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-60--60-.-61-"><code>&lt;&lt;.=</code></a>+  <td>Replace target(s). <a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-60--60-.-126-"><code>&lt;&lt;.~</code></a> and+      <a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-60--60-.-61-"><code>&lt;&lt;.=</code></a>       return the old value</td> </tr> <tr>   <td><a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:over"><code>over</code></a>,<a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:mapOf"><code>mapOf</code></a>,<a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:-37--126-"><code>%~</code></a></td>-  <td><a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-60--37--126-"><code>&lt;%~</code></td>+  <td><a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-60--37--126-"><code>&lt;%~</code></td>   <td><a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:-37--61-"><code>%=</code></a></td>-  <td><a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-60--37--61-"><code>&lt;%=</code></td>-  <td>Update target(s). <a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-60--60--37--126-"><code>&lt;&lt;%~</code> and-      <a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-60--60--37--61-"><code>&lt;&lt;%=</code></a>+  <td><a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-60--37--61-"><code>&lt;%=</code></td>+  <td>Update target(s). <a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-60--60--37--126-"><code>&lt;&lt;%~</code></a> and+      <a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-60--60--37--61-"><code>&lt;&lt;%=</code></a>       return the old value</td> </tr> <tr>-  <td><code>id</code>,<a href="http://ekmett.github.com/lens/Control-Lens-Traversal.html#v:traverseOf"><code>traverseOf</code></a>,<a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-37--37--126-"><code>%%~</code></a></td>+  <td><code>id</code>,<a href="http://ekmett.github.com/lens/Control-Lens-Traversal.html#v:traverseOf"><code>traverseOf</code></a>,<a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-37--37--126-"><code>%%~</code></a></td>   <td/>-  <td><a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-37--37--61-"><code>%%=</code></a></td>+  <td><a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-37--37--61-"><code>%%=</code></a></td>   <td/>   <td>Update target(s) with an <code>Applicative</code> or auxiliary result</td> </tr> <tr>   <td><a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:-43--126-"><code>+~</code></a></td>-  <td><a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-60--43--126-"><code>&lt;+~</code></td>+  <td><a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-60--43--126-"><code>&lt;+~</code></td>   <td><a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:-43--61-"><code>+=</code></a></td>-  <td><a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-60--43--61-"><code>&lt;+=</code></td>+  <td><a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-60--43--61-"><code>&lt;+=</code></td>   <td>Add to target(s)</td> </tr> <tr>   <td><a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:-45--126-"><code>-~</code></a></td>-  <td><a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-60--45--126-"><code>&lt;-~</code></td>+  <td><a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-60--45--126-"><code>&lt;-~</code></td>   <td><a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:-45--61-"><code>-=</code></a></td>-  <td><a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-60--45--61-"><code>&lt;-=</code></td>+  <td><a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-60--45--61-"><code>&lt;-=</code></td>   <td>Subtract from target(s)</td> </tr> <tr>   <td><a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:-42--126-"><code>*~</code></a></td>-  <td><a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-60--42--126-"><code>&lt;*~</code></td>+  <td><a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-60--42--126-"><code>&lt;*~</code></td>   <td><a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:-42--61-"><code>*=</code></a></td>-  <td><a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-60--42--61-"><code>&lt;*=</code></td>+  <td><a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-60--42--61-"><code>&lt;*=</code></td>   <td>Multiply target(s)</td> </tr> <tr>   <td><a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:-47--47--126-"><code>//~</code></a></td>-  <td><a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-60--47--47--126-"><code>&lt;//~</code></td>+  <td><a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-60--47--47--126-"><code>&lt;//~</code></td>   <td><a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:-47--47--61-"><code>//=</code></a></td>-  <td><a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-60--47--47--61-"><code>&lt;//=</code></td>+  <td><a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-60--47--47--61-"><code>&lt;//=</code></td>   <td>Divide target(s)</td> </tr> <tr>   <td><a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:-94--126-"><code>^~</code></a></td>-  <td><a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-60--94--126-"><code>&lt;^~</code></td>+  <td><a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-60--94--126-"><code>&lt;^~</code></td>   <td><a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:-94--61-"><code>^=</code></a></td>-  <td><a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-60--94--61-"><code>&lt;^=</code></td>+  <td><a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-60--94--61-"><code>&lt;^=</code></td>   <td>Raise target(s) to a non-negative <code>Integral</code> power</td> </tr> <tr>   <td><a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:-94--94--126-"><code>^^~</code></a></td>-  <td><a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-60--94--94--126-"><code>&lt;^^~</code></td>+  <td><a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-60--94--94--126-"><code>&lt;^^~</code></td>   <td><a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:-94--94--61-"><code>^^=</code></a></td>-  <td><a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-60--94--94--61-"><code>&lt;^^=</code></td>+  <td><a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-60--94--94--61-"><code>&lt;^^=</code></td>   <td>Raise target(s) to an <code>Integral</code> power</td> </tr> <tr>   <td><a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:-42--42--126-"><code>**~</code></a></td>-  <td><a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-60--42--42--126-"><code>&lt;**~</code></td>+  <td><a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-60--42--42--126-"><code>&lt;**~</code></td>   <td><a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:-42--42--61-"><code>**=</code></a></td>-  <td><a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-60--42--42--61-"><code>&lt;**=</code></td>+  <td><a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-60--42--42--61-"><code>&lt;**=</code></td>   <td>Raise target(s) to an arbitrary power</td> </tr> <tr>   <td><a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:-124--124--126-"><code>||~</code></a></td>-  <td><a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-60--124--124--126-"><code>&lt;||~</code></td>+  <td><a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-60--124--124--126-"><code>&lt;||~</code></td>   <td><a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:-124--124--61-"><code>||=</code></a></td>-  <td><a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-60--124--124--61-"><code>&lt;||=</code></td>+  <td><a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-60--124--124--61-"><code>&lt;||=</code></td>   <td>Logically or target(s)</td> </tr> <tr>   <td><a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:-38--38--126-"><code>&amp;&amp;~</code></a></td>-  <td><a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-60--38--38--126-"><code>&lt;&amp;&amp;~</code></td>+  <td><a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-60--38--38--126-"><code>&lt;&amp;&amp;~</code></td>   <td><a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:-38--38--61-"><code>&amp;&amp;=</code></a></td>-  <td><a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-60--38--38--61-"><code>&lt;&amp;&amp;=</code></td>+  <td><a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-60--38--38--61-"><code>&lt;&amp;&amp;=</code></td>   <td>Logically and target(s)</td> </tr> <tr>   <td><a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:-60--62--126-"><code>&lt;&gt;~</code></a></td>-  <td><a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-60--60--62--126-"><code>&lt;&lt;&gt;~</code></td>+  <td><a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-60--60--62--126-"><code>&lt;&lt;&gt;~</code></td>   <td><a href="http://ekmett.github.com/lens/Control-Lens-Setter.html#v:-60--62--61-"><code>&lt;&gt;=</code></a></td>-  <td><a href="http://ekmett.github.com/lens/Control-Lens-Type.html#v:-60--60--62--61-"><code>&lt;&lt;&gt;=</code></td>+  <td><a href="http://ekmett.github.com/lens/Control-Lens-Lens.html#v:-60--60--62--61-"><code>&lt;&lt;&gt;=</code></td>   <td><code>mappend</code> to the target monoidal value(s)</td> </tr> <tr>
benchmarks/plated.hs view
@@ -1,6 +1,5 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE Rank2Types #-}-{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE DeriveDataTypeable, DeriveGeneric #-} {-# OPTIONS_GHC -funbox-strict-fields #-} import           Control.Applicative
benchmarks/unsafe.hs view
@@ -10,19 +10,19 @@  import GHC.Exts -overS :: Setting s t a b -> (a -> b) -> s -> t+overS :: ASetter s t a b -> (a -> b) -> s -> t overS l f = runMutator . l (Mutator . f) {-# INLINE overS #-} -mappedS :: Setting [a] [b] a b+mappedS :: ASetter [a] [b] a b mappedS f = Mutator . map (runMutator . f) {-# INLINE mappedS #-} -overU :: Setting s t a b -> (a -> b) -> s -> t+overU :: ASetter s t a b -> (a -> b) -> s -> t overU = over {-# INLINE overU #-} -mappedU :: Setting [a] [b] a b+mappedU :: ASetter [a] [b] a b mappedU = mapped {-# INLINE mappedU #-} 
+ benchmarks/zipper.hs view
@@ -0,0 +1,45 @@+module Main+       ( main -- :: IO ()+       ) where++import Control.Lens+import Criterion.Main++main :: IO ()+main = defaultMain+  [ bgroup "rezip"+      [ bench "rezip"             $ nf tugAndRezip1 ['a'..'z']+      , bench "farthest leftward" $ nf tugAndRezip2 ['a'..'z']+      , bench "leftmost"          $ nf tugAndRezip3 ['a'..'z']+      , bench "tugTo"             $ nf tugAndRezip4 ['a'..'z']+      ]+  , bgroup "zipper creation"+      [ bench "over traverse id"  $ nf (over traverse id) ['a'..'z']+      , bench "zipper"            $ nf zipTraverseRezip   ['a'..'z']+      ]+  , bgroup "downward"+      [ bench "downward _1"       $ nf downwardAndRezip1 (['a'..'z'],['z'..'a'])+      , bench "fromWithin"        $ nf downwardAndRezip2 (['a'..'z'],['z'..'a'])+      ]+  ]++-- What's the fastest rezip of all?+tugAndRezip1, tugAndRezip2, tugAndRezip3 :: String -> String+tugAndRezip1 xs = zipntugs 25 xs & focus .~ 'a' & rezip+tugAndRezip2 xs = zipntugs 25 xs & focus .~ 'b' & farthest leftward & rezip+tugAndRezip3 xs = zipntugs 25 xs & focus .~ 'c' & leftmost & rezip+tugAndRezip4 xs = zipntugs 25 xs & focus .~ 'd' & tugTo 0 & rezip++zipntugs i x = zipper x & fromWithin traverse & tugs rightward i++-- How fast is creating and destroying a zipper compared to+-- a regular traversal?+zipTraverseRezip x = zipper x & fromWithin traverse & rezip++-- is 'downward' any faster than the composition of traverse?+downwardAndRezip1 :: (String, String) -> (String, String)+downwardAndRezip1 xs =+  zipper xs & downward _1 & fromWithin traverse & focus .~ 'h' & rezip+downwardAndRezip2 :: (String, String) -> (String, String)+downwardAndRezip2 xs =+  zipper xs & fromWithin (_1.traverse) & focus .~ 'g' & rezip
− config
@@ -1,16 +0,0 @@--- This provides a custom ~/.cabal/config file for use when hackage is down that should work on unix------ This is particularly useful for travis-ci to get it to stop complaining--- about a broken build when everything is still correct on our end.------ This uses Luite Stegeman's mirror of hackage provided by his 'hdiff' site instead------ To enable this, uncomment the before_script in .travis.yml--remote-repo: hdiff.luite.com:http://hdiff.luite.com/packages/archive-remote-repo-cache: ~/.cabal/packages-world-file: ~/.cabal/world-build-summary: ~/.cabal/logs/build.log-remote-build-reporting: anonymous-install-dirs user-install-dirs global
examples/Aeson.hs view
@@ -14,12 +14,12 @@ import Data.ByteString.Lazy  -- |--- >>> 5^.by aeson+-- >>> review aeson 5 -- "5"--- >>> [1,2,3]^.by aeson+-- >>> [1,2,3]^.re aeson -- "[1,2,3]"--- >>> aeson.both +~ 2 $ (2,3)^.by aeson+-- >>> aeson.both +~ 2 $ (2,3)^.re aeson -- "[4,5]"-aeson, aeson' :: (FromJSON c, ToJSON d) => Projection ByteString ByteString c d-aeson  = projection encode decode-aeson' = projection encode decode'+aeson, aeson' :: (FromJSON a, ToJSON a) => Prism' ByteString a+aeson  = prism' encode decode+aeson' = prism' encode decode'
examples/Brainfuck.hs view
@@ -1,4 +1,6 @@ {-# LANGUAGE TypeOperators #-}+{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE DeriveFunctor #-} ----------------------------------------------------------------------------- -- | -- Module      :  Brainfuck@@ -17,17 +19,19 @@  import Control.Lens import Control.Applicative-import Control.Monad.Free-import Control.Monad.RWS+import Control.Monad.State+import Control.Monad.Writer  import qualified Data.ByteString.Lazy as BS-import Data.Maybe (fromMaybe)-import qualified Data.Stream.Infinite as S+import Data.Maybe (fromMaybe, mapMaybe) import Data.Word (Word8)  import System.Environment (getArgs) import System.IO +-- | Brainfuck is defined to have a memory of 30000 cells.+memoryCellNum :: Int+memoryCellNum = 30000  -- Low level syntax form @@ -35,84 +39,86 @@ type Code = [Instr]  parse :: String -> Code-parse = concatMap (maybe [] return . (`lookup` symbols))+parse = mapMaybe (`lookup` symbols)   where symbols = [ ('+', Plus ), ('-', Minus), ('<', Left), ('>', Right)                   , (',', Comma), ('.', Dot  ), ('[', Open), (']', Close) ]  -- Higher level semantic graph -data Brainfuck n-  = Succ n | Pred n  -- Increment or decrement the current value-  | Next n | Prev n  -- Shift memory left or right-  | Read n | Write n -- Input or output the current value+data Program+  = Succ Program | Pred Program  -- Increment or decrement the current value+  | Next Program | Prev Program  -- Shift memory left or right+  | Read Program | Write Program -- Input or output the current value+  | Halt                         -- End execution    -- Branching semantic, used for both sides of loops-  | Branch { zero :: n, nonzero :: n }--type Program = Free Brainfuck ()+  | Branch { zero :: Program, nonzero :: Program }  compile :: Code -> Program compile = fst . bracket []  bracket :: [Program] -> Code -> (Program, [Program])-bracket [] []        = (Pure (), [])+bracket [] []        = (Halt, []) bracket _  []        = error "Mismatched opening bracket" bracket [] (Close:_) = error "Mismatched closing bracket"  -- Match a closing bracket: Pop a forward continuation, push backwards-bracket (c:cs) (Close : xs) = (Free (Branch n c), n:bs)+bracket (c:cs) (Close : xs) = (Branch n c, n:bs)   where (n, bs) = bracket cs xs  -- Match an opening bracket: Pop a backwards continuation, push forwards-bracket cs (Open : xs) = (Free (Branch b n), bs)+bracket cs (Open : xs) = (Branch b n, bs)   where (n, b:bs) = bracket (n:cs) xs  -- Match any other symbol in the trivial way-bracket cs (x:xs) = over _1 (Free . f x) (bracket cs xs)+bracket cs (x:xs) = over _1 (f x) (bracket cs xs)   where     f Plus  = Succ; f Minus = Pred     f Right = Next; f Left  = Prev     f Comma = Read; f Dot   = Write --- * RWS-based interpreter+-- * State/Writer-based interpreter  type Cell   = Word8-type Input  = S.Stream Cell+type Input  = [Cell] type Output = [Cell]-type Memory = Top :> [Cell] :> Cell -- list zipper+type Memory = Top :>> [Cell] :>> Cell -- list zipper -type Interpreter = RWS Input Output Memory ()+data MachineState = MachineState+  { _input  :: [Cell]+  , _memory :: Memory }+makeLenses ''MachineState +type Interpreter = StateT MachineState (Writer Output) ()+ -- | Initial memory configuration-initial :: Memory-initial = zipper (replicate 30000 0) & fromWithin traverse+initial :: Input -> MachineState+initial i = MachineState i (zipper (replicate memoryCellNum 0) & fromWithin traverse)  interpret :: Input -> Program -> Output-interpret i p = snd $ execRWS (run p) i initial+interpret i = execWriter . flip execStateT (initial i) . run  -- | Evaluation function run :: Program -> Interpreter-run (Pure _) = return ()-run (Free f) = case f of-  Succ n -> focus += 1       >> run n-  Pred n -> focus -= 1       >> run n-  Next n -> modify wrapRight >> run n-  Prev n -> modify wrapLeft  >> run n--  Read n -> do-    focus <~ asks S.head-    local S.tail $ run n--  Write n -> do-    tell . return =<< use focus-    run n--  Branch z n -> do-    c <- use focus-    run $ case c of 0 -> z; _ -> n+run Halt     = return ()+run (Succ n) = memory.focus += 1   >> run n+run (Pred n) = memory.focus -= 1   >> run n+run (Next n) = memory %= wrapRight >> run n+run (Prev n) = memory %= wrapLeft  >> run n+run (Read n) = do+  memory.focus <~ uses input head+  input %= tail+  run n+run (Write n) = do+  x <- use (memory.focus)+  tell [x]+  run n+run (Branch z n) = do+  c <- use (memory.focus)+  run $ if c == 0 then z else n  -- | Zipper helpers-wrapRight, wrapLeft :: (a :> b) -> (a :> b)+wrapRight, wrapLeft :: (a :>> b) -> (a :>> b) wrapRight = liftM2 fromMaybe leftmost rightward wrapLeft  = liftM2 fromMaybe rightmost leftward @@ -141,7 +147,7 @@ -- | EOF is represented as 0 getInput :: IO Input getInput = f <$> BS.getContents-  where f s = S.fromList (BS.unpack s ++ repeat 0)+  where f s = BS.unpack s ++ repeat 0  noInput :: Input-noInput = S.repeat 0+noInput = repeat 0
+ examples/BrainfuckFinal.hs view
@@ -0,0 +1,129 @@+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE DeriveFunctor #-}+-----------------------------------------------------------------------------+-- |+-- Module      :  BrainfuckFinal+-- Copyright   :  (C) 2012 Edward Kmett, nand`+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  provisional+-- Portability :  TH, Rank2, NoMonomorphismRestriction+--+-- A simple interpreter for the esoteric programming language "Brainfuck"+-- written using lenses and zippers.+--+-- This version of the interpreter is 'finally encoded' without going through+-- an AST.+-----------------------------------------------------------------------------+module Main where++import Prelude hiding (Either(..))++import Control.Lens+import Control.Applicative+import Control.Monad.State+import Control.Monad.Writer++import qualified Data.ByteString.Lazy as BS+import Data.Maybe (fromMaybe, mapMaybe)+import Data.Word (Word8)++import System.Environment (getArgs)+import System.IO++-- | Brainfuck is defined to have a memory of 30000 cells.+memoryCellNum :: Int+memoryCellNum = 30000++-- * State/Writer-based interpreter++type Cell   = Word8+type Input  = [Cell]+type Output = [Cell]+type Memory = Top :>> [Cell] :>> Cell -- list zipper++data MachineState = MachineState+  { _input  :: [Cell]+  , _memory :: Memory }++makeLenses ''MachineState++type Program = StateT MachineState (Writer Output) ()++compile :: String -> Program+compile = fst . bracket []++branch :: Program -> Program -> Program+branch z n = do+  c <- use (memory.focus)+  if c == 0 then z else n++bracket :: [Program] -> String -> (Program, [Program])+bracket [] ""      = (return () , [])+bracket _  ""      = error "Mismatched opening bracket"+bracket [] (']':_) = error "Mismatched closing bracket"++-- Match a closing bracket: Pop a forward continuation, push backwards+bracket (c:cs) (']': xs) = (branch n c, n:bs) where+  (n, bs) = bracket cs xs++-- Match an opening bracket: Pop a backwards continuation, push forwards+bracket cs ('[': xs) = (branch b n, bs) where+  (n, b:bs) = bracket (n:cs) xs++-- Match any other symbol in the trivial way+bracket cs (x:xs) = over _1 (f x >>) (bracket cs xs) where+  f '+' = memory.focus += 1+  f '-' = memory.focus -= 1+  f '>' = memory %= wrapRight+  f '<' = memory %= wrapLeft+  f ',' = do+    memory.focus <~ uses input head+    input %= tail+  f '.' = do+    x <- use (memory.focus)+    tell [x]+  f _   = return ()++-- | Initial memory configuration+initial :: Input -> MachineState+initial i = MachineState i (zipper (replicate memoryCellNum 0) & fromWithin traverse)++interpret :: Input -> Program -> Output+interpret i = execWriter . flip execStateT (initial i)++-- | Zipper helpers+wrapRight, wrapLeft :: (a :>> b) -> (a :>> b)+wrapRight = liftM2 fromMaybe leftmost rightward+wrapLeft  = liftM2 fromMaybe rightmost leftward++-- Main program action to actually run this stuff++main :: IO ()+main = do+  as <- getArgs+  case as of+    -- STDIN is program+    [ ] -> do+      hSetBuffering stdin  NoBuffering+      hSetBuffering stdout NoBuffering+      getContents >>= eval noInput++    -- STDIN is input+    [f] -> join $ eval <$> getInput <*> readFile f++    -- Malformed command line+    _ -> putStrLn "Usage: brainfuck [program]"++eval :: Input -> String -> IO ()+eval i = mapM_ putByte . interpret i . compile+  where putByte = BS.putStr . BS.pack . return++-- | EOF is represented as 0+getInput :: IO Input+getInput = f <$> BS.getContents+  where f s = BS.unpack s ++ repeat 0++noInput :: Input+noInput = repeat 0
examples/Plates.hs view
@@ -19,7 +19,7 @@   plate f (Sel xs) = pure (Sel xs)   plate f (Let x y) = pure (Let x y) -exprs :: Simple Traversal Stmt Expr+exprs :: Traversal' Stmt Expr exprs f (Seq xs)  = Seq <$> traverse (exprs f) xs exprs f (Sel xs)  = Sel <$> traverse f xs exprs f (Let x y) = Let x <$> f y
examples/Pong.hs view
@@ -111,7 +111,7 @@   p <- get    let paddleMovement = time * paddleSpeed-      keyPressed key = p^.keys.contains (SpecialKey key)+      keyPressed key = p^.keys.ix (SpecialKey key)    -- Update the player's paddle based on keys   when (keyPressed KeyUp)   $ paddle1 += paddleMovement@@ -205,7 +205,7 @@ -- Handle input by simply updating the keys set  handle :: Event -> Pong -> Pong-handle (EventKey k s _ _) = keys.contains k .~ (s == Down)+handle (EventKey k s _ _) = keys.ix k .~ (s == Down) handle _ = id  -- The main program action
examples/Turtle.hs view
@@ -2,7 +2,7 @@ {-# LANGUAGE DeriveDataTypeable #-} -- | A simple Turtle-graphics demonstration for modeling the location of a turtle. ----- This is based on the code presented by Seth Tisue at the Boston Area Scala +-- This is based on the code presented by Seth Tisue at the Boston Area Scala -- Enthusiasts meeting during his lens talk. -- -- Usage:@@ -10,11 +10,11 @@ -- > def & forward 10 & down & color .~ red % turn (pi/2) & forward 5 module Turtle where -import Control.Lens hiding (up, down)+import Control.Lens import Data.Default  data Point = Point-  { _x, _y :: Double+  { __x, __y :: Double   } deriving (Eq,Show)  makeClassy ''Point@@ -23,7 +23,7 @@   def = Point def def  data Color = Color-  { _r, _g, _b :: Int+  { __r, __g, __b :: Int   } deriving (Eq,Show)  makeClassy ''Color@@ -54,8 +54,8 @@  forward :: Double -> Turtle -> Turtle forward d t =-  t & y +~ d * cos (t^.heading)-    & x +~ d * sin (t^.heading)+  t & _y +~ d * cos (t^.heading)+    & _x +~ d * sin (t^.heading)  turn :: Double -> Turtle -> Turtle turn d = heading +~ d
examples/bf-examples/triangle.bf view
@@ -1,33 +1,33 @@-[ This program prints Sierpinski triangle on 80-column display. ]
-                                >    
-                               + +    
-                              +   +    
-                             [ < + +    
-                            +       +    
-                           + +     + +    
-                          >   -   ]   >    
-                         + + + + + + + +    
-                        [               >    
-                       + +             + +    
-                      <   -           ]   >    
-                     > + + >         > > + >    
-                    >       >       +       <    
-                   < <     < <     < <     < <    
-                  <   [   -   [   -   >   +   <    
-                 ] > [ - < + > > > . < < ] > > >    
-                [                               [    
-               - >                             + +    
-              +   +                           +   +    
-             + + [ >                         + + + +    
-            <       -                       ]       >    
-           . <     < [                     - >     + <    
-          ]   +   >   [                   -   >   +   +    
-         + + + + + + + +                 < < + > ] > . [    
-        -               ]               >               ]    
-       ] +             < <             < [             - [    
-      -   >           +   <           ]   +           >   [    
-     - < + >         > > - [         - > + <         ] + + >    
-    [       -       <       -       >       ]       <       <    
-   < ]     < <     < <     ] +     + +     + +     + +     + +    
-  +   .   +   +   +   .   [   -   ]   <   ]   +   +   +   +   +    
- * * * * * M a d e * B y : * N Y Y R I K K I * 2 0 0 2 * * * * *    
+[ This program prints Sierpinski triangle on 80-column display. ]+                                >+                               + ++                              +   ++                             [ < + ++                            +       ++                           + +     + ++                          >   -   ]   >+                         + + + + + + + ++                        [               >+                       + +             + ++                      <   -           ]   >+                     > + + >         > > + >+                    >       >       +       <+                   < <     < <     < <     < <+                  <   [   -   [   -   >   +   <+                 ] > [ - < + > > > . < < ] > > >+                [                               [+               - >                             + ++              +   +                           +   ++             + + [ >                         + + + ++            <       -                       ]       >+           . <     < [                     - >     + <+          ]   +   >   [                   -   >   +   ++         + + + + + + + +                 < < + > ] > . [+        -               ]               >               ]+       ] +             < <             < [             - [+      -   >           +   <           ]   +           >   [+     - < + >         > > - [         - > + <         ] + + >+    [       -       <       -       >       ]       <       <+   < ]     < <     < <     ] +     + +     + +     + +     + ++  +   .   +   +   +   .   [   -   ]   <   ]   +   +   +   +   ++ * * * * * M a d e * B y : * N Y Y R I K K I * 2 0 0 2 * * * * *
examples/lens-examples.cabal view
@@ -26,7 +26,7 @@ flag brainfuck   default: True -executable pong+executable lens-pong   if !flag(pong)     buildable: False @@ -39,15 +39,28 @@     random     == 1.0.*   main-is: Pong.hs -executable brainfuck+executable lens-brainfuck   if !flag(brainfuck)     buildable: False    build-depends:     base,     lens,-    free       >= 3.0 && < 3.3,+    free       >= 3.0,     bytestring,     mtl        >= 2.0.1 && < 2.2,-    streams    == 3.0.*+    streams    >= 3.0   main-is: Brainfuck.hs++executable lens-brainfuck-final+  if !flag(brainfuck)+    buildable: False++  build-depends:+    base,+    lens,+    free       >= 3.0,+    bytestring,+    mtl        >= 2.0.1 && < 2.2,+    streams    >= 3.0+  main-is: BrainfuckFinal.hs
lens.cabal view
@@ -1,6 +1,6 @@ name:          lens category:      Data, Lenses-version:       3.7.6+version:       3.8 license:       BSD3 cabal-version: >= 1.8 license-file:  LICENSE@@ -9,7 +9,9 @@ stability:     provisional homepage:      http://github.com/ekmett/lens/ bug-reports:   http://github.com/ekmett/lens/issues-copyright:     Copyright (C) 2012 Edward A. Kmett+copyright:     Copyright (C) 2012-2013 Edward A. Kmett+build-type:    Custom+tested-with:   GHC == 7.0.4, GHC == 7.4.1, GHC == 7.4.2, GHC == 7.6.1, GHC == 7.7.20121213, GHC == 7.7.20130117 synopsis:      Lenses, Folds and Traversals description:   This package comes \"Batteries Included\" with many useful lenses for the types@@ -20,26 +22,24 @@   families of getters, folds, isomorphisms, traversals, setters and lenses and their   indexed variants.   .-  An overview, with a large number of examples can be found in the README.-  .-  <https://github.com/ekmett/lens#lens-lenses-folds-and-traversals>+  An overview, with a large number of examples can be found in the @README@: <https://github.com/ekmett/lens#lens-lenses-folds-and-traversals>   .-  More information on the care and feeding of lenses, including a brief tutorial and motivation-  for their types can be found on the lens wiki.+  A video on how to use lenses and how they are constructed is available from youtube: <http://youtu.be/cefnmjtAolY?hd=1>   .-  <https://github.com/ekmett/lens/wiki>+  Slides can be obtained here: <http://comonad.com/haskell/Lenses-Folds-and-Traversals-NYC.pdf>   .-  A small game that manages its state using lenses can be found in the example folder.+  More information on the care and feeding of lenses, including a brief tutorial and motivation+  for their types can be found on the lens wiki: <https://github.com/ekmett/lens/wiki>   .-  <https://github.com/ekmett/lens/blob/master/examples/Pong.hs>+  A small game of @pong@ and other more complex examples that manage their state using lenses can be found in the example folder: <https://github.com/ekmett/lens/blob/master/examples/>   .   /Lenses, Folds and Traversals/   .-  The core of this hierarchy looks like:+  The core of the hierarchy of lens-like constructions looks like:   .-  <<http://i.imgur.com/FgfVW.png>>+  <<http://i.imgur.com/RFi75.png>>   .-  You can compose any two elements of the hierarchy above using (.) from the Prelude, and you can+  You can compose any two elements of the hierarchy above using @(.)@ from the @Prelude@, and you can   use any element of the hierarchy as any type it linked to above it.   .   The result is their lowest upper bound in the hierarchy (or an error if that bound doesn't exist).@@ -61,7 +61,7 @@   .   You can define lenses such as   .-  > -- bar :: Simple Lens (Foo a) Int+  > -- bar :: Lens' (Foo a) Int   > bar :: Functor f => (Int -> f Int) -> Foo a -> f (Foo a)   > bar f (Foo a b c) = fmap (\a' -> Foo a' b c) (f a)   .@@ -73,7 +73,7 @@   .   And you can define a traversal of multiple fields with 'Control.Applicative.Applicative':   .-  > -- traverseBarAndBaz :: Simple Traversal (Foo a) Int+  > -- traverseBarAndBaz :: Traversal' (Foo a) Int   > traverseBarAndBaz :: Applicative f => (Int -> f Int) -> Foo a -> f (Foo a)   > traverseBarAndBaz f (Foo a b c) = Foo <$> f a <*> f b <*> pure c   .@@ -81,19 +81,19 @@   common haskell types, a wide array of combinators for working them, and more   exotic functionality, (/e.g./ getters, setters, indexed folds, isomorphisms). -build-type:    Custom-tested-with:   GHC == 7.0.4, GHC == 7.4.1, GHC == 7.6.1 extra-source-files:   .travis.yml   .ghci   .gitignore   .vim.custom-  config   examples/LICENSE   examples/lens-examples.cabal   examples/*.hs   examples/*.lhs   examples/bf-examples/*.bf+  travis/cabal-apt-install+  travis/config+  AUTHORS.markdown   README.markdown   CHANGELOG.markdown @@ -109,15 +109,6 @@   default: False   manual: True --- Enable template haskell. Disable this at your own risk and for testing only.------ cabal configure -f-template-haskell is an /unsupported/ configuration.------ Clients of this library can and should expect this to be turned on.-flag template-haskell-  default: True-  manual: True- -- Generate inline pragmas when using template-haskell. This defaults to enabled, but you can -- -- > cabal install lens -f-inlining@@ -138,11 +129,17 @@   default: False   manual: True +-- You can disable the doctests test suite with -f-test-doctests+flag test-doctests+  default: True+  manual: True+ -- You can disable the hunit test suite with -f-test-hunit flag test-hunit   default: True   manual: True +-- Build the properties test if we're building tests flag test-properties   default: True   manual: True@@ -157,67 +154,94 @@   default: True   manual: True -flag old-semigroups+flag lib-Werror   default: False-  manual: False-+  manual: True  library   build-depends:-    base                 >= 4.3      && < 5,-    bytestring           >= 0.9.1.10 && < 0.11,-    comonad              >= 3,-    comonad-transformers >= 3,-    comonads-fd          >= 3,-    containers           >= 0.4.0    && < 0.6,-    hashable             >= 1.1.2.3  && < 1.3,-    mtl                  >= 2.0.1    && < 2.2,-    split                == 0.2.*,-    text                 >= 0.11     && < 0.12,-    transformers         >= 0.2      && < 0.4,-    transformers-compat  >= 0.1,-    unordered-containers >= 0.2      && < 0.3,-    vector               >= 0.9      && < 0.11--  if flag(old-semigroups)-    build-depends:-      semigroups >= 0.8.4 && < 0.9-  else-    build-depends:-      nats >= 0.1,-      semigroups >= 0.9+    array                     >= 0.3.0.2  && < 0.5,+    base                      >= 4.3      && < 5,+    bifunctors                >= 3        && < 4,+    bytestring                >= 0.9.1.10 && < 0.11,+    comonad                   >= 3        && < 4,+    comonad-transformers      >= 3        && < 4,+    comonads-fd               >= 3        && < 4,+    contravariant             >= 0.2.0.2,+    containers                >= 0.4.0    && < 0.6,+    distributive              >= 0.3,+    filepath                  >= 1.2.0.0  && < 1.4,+    generic-deriving          == 1.4.*,+    ghc-prim,+    hashable                  >= 1.1.2.3  && < 1.3,+    MonadCatchIO-transformers >= 0.3      && < 0.4,+    mtl                       >= 2.0.1    && < 2.2,+    parallel                  >= 3.1.0.1  && < 3.3,+    profunctors               >= 3.2      && < 4,+    profunctor-extras         >= 3.3      && < 4,+    semigroupoids             >= 3        && < 4,+    semigroups                >= 0.8.4    && < 1,+    split                     == 0.2.*,+    tagged                    >= 0.4.4    && < 1,+    template-haskell          >= 2.4      && < 2.10,+    text                      >= 0.11     && < 0.12,+    transformers              >= 0.2      && < 0.4,+    transformers-compat       >= 0.1      && < 1,+    unordered-containers      >= 0.2      && < 0.3,+    vector                    >= 0.9      && < 0.11    exposed-modules:     Control.Exception.Lens     Control.Lens     Control.Lens.Action-    Control.Lens.Classes+    Control.Lens.At     Control.Lens.Combinators+    Control.Lens.Cons     Control.Lens.Each+    Control.Lens.Equality     Control.Lens.Fold     Control.Lens.Getter     Control.Lens.Indexed-    Control.Lens.IndexedGetter-    Control.Lens.IndexedFold-    Control.Lens.IndexedLens-    Control.Lens.IndexedSetter-    Control.Lens.IndexedTraversal     Control.Lens.Internal+    Control.Lens.Internal.Action+    Control.Lens.Internal.Bazaar+    Control.Lens.Internal.ByteString+    Control.Lens.Internal.Context+    Control.Lens.Internal.Deque+    Control.Lens.Internal.Fold+    Control.Lens.Internal.Getter+    Control.Lens.Internal.Indexed+    Control.Lens.Internal.Instances+    Control.Lens.Internal.Iso+    Control.Lens.Internal.Level+    Control.Lens.Internal.Magma+    Control.Lens.Internal.Prism+    Control.Lens.Internal.Review+    Control.Lens.Internal.Setter     Control.Lens.Internal.Zipper+    Control.Lens.Internal.Zoom     Control.Lens.Iso+    Control.Lens.Lens+    Control.Lens.Level     Control.Lens.Loupe+    Control.Lens.Operators     Control.Lens.Plated     Control.Lens.Prism-    Control.Lens.Representable+    Control.Lens.Reified+    Control.Lens.Review     Control.Lens.Setter     Control.Lens.Simple+    Control.Lens.TH     Control.Lens.Traversal     Control.Lens.Tuple     Control.Lens.Type-    Control.Lens.WithIndex     Control.Lens.Wrapped     Control.Lens.Zipper     Control.Lens.Zoom+    Control.Monad.Error.Lens+    Control.Parallel.Strategies.Lens+    Control.Seq.Lens+    Data.Array.Lens     Data.Bits.Lens     Data.ByteString.Lens     Data.ByteString.Strict.Lens@@ -239,15 +263,11 @@     Data.Vector.Lens     Data.Vector.Generic.Lens     GHC.Generics.Lens--  other-modules:-    Control.Lens.Internal.Combinators--  if flag(template-haskell)-    build-depends: template-haskell >= 2.4 && < 2.9-    exposed-modules: Control.Lens.TH Language.Haskell.TH.Lens-  else-    cpp-options: -DDISABLE_TEMPLATE_HASKELL=1+    System.Exit.Lens+    System.FilePath.Lens+    System.IO.Error.Lens+    Language.Haskell.TH.Lens+    Numeric.Lens    if flag(safe)     cpp-options: -DSAFE=1@@ -258,30 +278,20 @@   if impl(ghc<7.4)     ghc-options: -fno-spec-constr-count -  -- platform-  build-depends:   array >= 0.3.0.2 && < 0.5-  exposed-modules: Data.Array.Lens--  build-depends:   filepath >= 1.2.0.0 && < 1.4-  exposed-modules: System.FilePath.Lens--  build-depends:   parallel >= 3.1.0.1 && < 3.3-  exposed-modules: Control.Parallel.Strategies.Lens Control.Seq.Lens-   if impl(ghc>=7.6.0.20120810)     if flag(old-inline-pragmas)       cpp-options: -DOLD_INLINE_PRAGMAS=1 -  if !flag(inlining)-    cpp-options: -DOMIT_INLINING=1+  if flag(inlining)+    cpp-options: -DINLINING    if impl(ghc>=7.2)     other-extensions: Trustworthy-    build-depends: ghc-prim     cpp-options: -DDEFAULT_SIGNATURES=1-  else-    build-depends: generic-deriving +  if flag(lib-Werror)+    ghc-options: -Werror+   ghc-options: -Wall -fwarn-tabs -O2 -fdicts-cheap -funbox-strict-fields   hs-source-dirs: src @@ -339,20 +349,25 @@ test-suite doctests   type:    exitcode-stdio-1.0   main-is: doctests.hs-  build-depends:-    base,-    bytestring,-    containers,-    directory >= 1.0,-    doctest >= 0.9.1,-    filepath,-    mtl,-    parallel,-    simple-reflect >= 0.3.1,-    split,-    text,-    unordered-containers,-    vector+  if !flag(test-doctests)+    buildable: False+  else+    build-depends:+      base,+      bytestring,+      containers,+      directory >= 1.0,+      deepseq,+      doctest >= 0.9.1,+      filepath,+      mtl,+      nats,+      parallel,+      simple-reflect >= 0.3.1,+      split,+      text,+      unordered-containers,+      vector   ghc-options: -Wall -threaded   if impl(ghc<7.6.1)     ghc-options: -Werror@@ -398,6 +413,22 @@ benchmark unsafe   type: exitcode-stdio-1.0   main-is: unsafe.hs+  build-depends:+    base,+    comonad,+    comonads-fd,+    criterion,+    deepseq,+    ghc-prim,+    lens,+    transformers+  ghc-options: -w -O2 -threaded -fdicts-cheap -funbox-strict-fields+  hs-source-dirs: benchmarks++-- Benchmarking zipper usage+benchmark zipper+  type: exitcode-stdio-1.0+  main-is: zipper.hs   build-depends:     base,     comonad,
src/Control/Exception/Lens.hs view
@@ -1,36 +1,856 @@ {-# LANGUAGE CPP #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE Rank2Types #-}+{-# LANGUAGE PatternGuards #-}+{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE NoMonomorphismRestriction #-} #ifdef TRUSTWORTHY {-# LANGUAGE Trustworthy #-} #endif +#ifndef MIN_VERSION_base+#define MIN_VERSION_base(x,y,z) 1+#endif+ ----------------------------------------------------------------------------- -- | -- Module      :  Control.Exception.Lens--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  provisional -- Portability :  Control.Exception --+-- @Control.Exception@ provides an example of a large open hierarchy+-- that we can model with prisms and isomorphisms.+--+-- Additional combinators for working with 'IOException' results can+-- be found in "System.IO.Error.Lens".+--+-- The combinators in this module have been generalized to work with+-- 'MonadCatchIO' instead of just 'IO'. This enables them to be used+-- more easily in 'Monad' transformer stacks. ---------------------------------------------------------------------------- module Control.Exception.Lens-  ( exception+  (+  -- * Handling+    catching, catching_+  , handling, handling_+  -- * Trying+  , trying+  -- * Throwing+  , throwing+  , throwingM+  , throwingTo+  -- * Exceptions+  , exception+  -- ** IOExceptions+  , AsIOException(..)+  -- ** Arithmetic Exceptions+  , AsArithException(..)+  , _Overflow+  , _Underflow+  , _LossOfPrecision+  , _DivideByZero+  , _Denormal+#if MIN_VERSION_base(4,6,0)+  , _RatioZeroDenominator+#endif+  -- ** Array Exceptions+  , AsArrayException(..)+  , _IndexOutOfBounds+  , _UndefinedElement+  -- ** Assertion Failed+  , AsAssertionFailed(..)+  -- ** Async Exceptions+  , AsAsyncException(..)+  , _StackOverflow+  , _HeapOverflow+  , _ThreadKilled+  , _UserInterrupt+  -- ** Non-Termination+  , AsNonTermination(..)+  -- ** Nested Atomically+  , AsNestedAtomically(..)+  -- ** Blocked Indefinitely+  -- *** on MVar+  , AsBlockedIndefinitelyOnMVar(..)+  -- *** on STM+  , AsBlockedIndefinitelyOnSTM(..)+  -- ** Deadlock+  , AsDeadlock(..)+  -- ** No Such Method+  , AsNoMethodError(..)+  -- ** Pattern Match Failure+  , AsPatternMatchFail(..)+  -- ** Record+  , AsRecConError(..)+  , AsRecSelError(..)+  , AsRecUpdError(..)+  -- ** Error Call+  , AsErrorCall(..)   ) where -import Control.Exception+import Control.Applicative+import Control.Monad+import Control.Monad.IO.Class+import Control.Monad.CatchIO as CatchIO hiding (try, tryJust)+import Control.Exception as Exception hiding (try, tryJust, catchJust) import Control.Lens+import Data.Monoid+import GHC.Conc (ThreadId)+import Prelude+  ( asTypeOf, const, either, flip, id, maybe, undefined+  , ($), (.)+  ,  Maybe(..), Either(..), Functor(..), String+  ) --- |--- Traverse the strongly typed 'Exception' contained in 'SomeException' where the type of your function matches+{-# ANN module "HLint: ignore Use Control.Exception.catch" #-}++-- $setup+-- >>> :m + Control.Exception Control.Monad Data.List Prelude++------------------------------------------------------------------------------+-- Exceptions as Prisms+------------------------------------------------------------------------------++-- | Traverse the strongly typed 'Exception' contained in 'SomeException' where the type of your function matches -- the desired 'Exception'. -- -- @ -- exception :: ('Applicative' f, 'Exception' a, 'Exception' b) --           => (a -> f b) -> 'SomeException' -> f 'SomeException' -- @-exception :: Exception a => Simple Prism SomeException a+exception :: Exception a => Prism' SomeException a exception = prism toException $ \ e -> maybe (Left e) Right $ fromException e {-# INLINE exception #-}++------------------------------------------------------------------------------+-- Catching+------------------------------------------------------------------------------++-- | Catch exceptions that match a given 'Prism' (or any 'Getter', really).+--+-- >>> catching _AssertionFailed (assert False (return "uncaught")) $ \ _ -> return "caught"+-- "caught"+--+-- @+-- 'catching' :: 'MonadCatchIO' m => 'Prism'' 'SomeException' a     -> m r -> (a -> m r) -> m r+-- 'catching' :: 'MonadCatchIO' m => 'Lens'' 'SomeException' a      -> m r -> (a -> m r) -> m r+-- 'catching' :: 'MonadCatchIO' m => 'Traversal'' 'SomeException' a -> m r -> (a -> m r) -> m r+-- 'catching' :: 'MonadCatchIO' m => 'Iso'' 'SomeException' a       -> m r -> (a -> m r) -> m r+-- 'catching' :: 'MonadCatchIO' m => 'Getter' 'SomeException' a     -> m r -> (a -> m r) -> m r+-- 'catching' :: 'MonadCatchIO' m => 'Fold' 'SomeException' a       -> m r -> (a -> m r) -> m r+-- @+catching :: MonadCatchIO m => Getting (First a) SomeException t a b -> m r -> (a -> m r) -> m r+catching l = catchJust (preview l)+{-# INLINE catching #-}++-- | Catch exceptions that match a given 'Prism' (or any 'Getter'), discarding+-- the information about the match. This is particuarly useful when you have+-- a @'Prism'' e ()@ where the result of the 'Prism' or 'Fold' isn't+-- particularly valuable, just the fact that it matches.+--+-- >>> catching_ _AssertionFailed (assert False (return "uncaught")) $ return "caught"+-- "caught"+--+-- @+-- 'catching_' :: 'MonadCatchIO' m => 'Prism'' 'SomeException' a     -> m r -> m r -> m r+-- 'catching_' :: 'MonadCatchIO' m => 'Lens'' 'SomeException' a      -> m r -> m r -> m r+-- 'catching_' :: 'MonadCatchIO' m => 'Traversal'' 'SomeException' a -> m r -> m r -> m r+-- 'catching_' :: 'MonadCatchIO' m => 'Iso'' 'SomeException' a       -> m r -> m r -> m r+-- 'catching_' :: 'MonadCatchIO' m => 'Getter' 'SomeException' a     -> m r -> m r -> m r+-- 'catching_' :: 'MonadCatchIO' m => 'Fold' 'SomeException' a       -> m r -> m r -> m r+-- @+catching_ :: MonadCatchIO m => Getting (First a) SomeException t a b -> m r -> m r -> m r+catching_ l a b = catchJust (preview l) a (const b)+{-# INLINE catching_ #-}++-- | A helper function to provide conditional catch behavior.+catchJust :: (MonadCatchIO m, Exception e) => (e -> Maybe t) -> m a -> (t -> m a) -> m a+catchJust f m k = CatchIO.catch m $ \ e -> case f e of+  Nothing -> liftIO (throwIO e)+  Just x  -> k x+{-# INLINE catchJust #-}++------------------------------------------------------------------------------+-- Handling+------------------------------------------------------------------------------++-- | A version of 'catching' with the arguments swapped around; useful in+-- situations where the code for the handler is shorter.+--+-- >>> handling _NonTermination (\_ -> return "caught") $ throwIO NonTermination+-- "caught"+--+-- @+-- 'handling' :: 'MonadCatchIO' m => 'Prism'' 'SomeException' a     -> (a -> m r) -> m r -> m r+-- 'handling' :: 'MonadCatchIO' m => 'Lens'' 'SomeException' a      -> (a -> m r) -> m r -> m r+-- 'handling' :: 'MonadCatchIO' m => 'Traversal'' 'SomeException' a -> (a -> m r) -> m r -> m r+-- 'handling' :: 'MonadCatchIO' m => 'Iso'' 'SomeException' a       -> (a -> m r) -> m r -> m r+-- 'handling' :: 'MonadCatchIO' m => 'Fold' 'SomeException' a       -> (a -> m r) -> m r -> m r+-- 'handling' :: 'MonadCatchIO' m => 'Getter' 'SomeException' a     -> (a -> m r) -> m r -> m r+-- @+handling :: MonadCatchIO m => Getting (First a) SomeException t a b -> (a -> m r) -> m r -> m r+handling l = flip (catching l)+{-# INLINE handling #-}++-- | A version of 'catching_' with the arguments swapped around; useful in+-- situations where the code for the handler is shorter.+--+-- >>> handling_ _NonTermination (return "caught") $ throwIO NonTermination+-- "caught"+--+-- @+-- 'handling_' :: 'MonadCatchIO' m => 'Prism'' 'SomeException' a     -> m r -> m r -> m r+-- 'handling_' :: 'MonadCatchIO' m => 'Lens'' 'SomeException' a      -> m r -> m r -> m r+-- 'handling_' :: 'MonadCatchIO' m => 'Traversal'' 'SomeException' a -> m r -> m r -> m r+-- 'handling_' :: 'MonadCatchIO' m => 'Iso'' 'SomeException' a       -> m r -> m r -> m r+-- 'handling_' :: 'MonadCatchIO' m => 'Getter' 'SomeException' a     -> m r -> m r -> m r+-- 'handling_' :: 'MonadCatchIO' m => 'Fold' 'SomeException' a       -> m r -> m r -> m r+-- @+handling_ :: MonadCatchIO m => Getting (First a) SomeException t a b -> m r -> m r -> m r+handling_ l = flip (catching_ l)+{-# INLINE handling_ #-}++------------------------------------------------------------------------------+-- Trying+------------------------------------------------------------------------------++-- | A variant of 'CatchIO.try' that takes an 'Prism' (or any 'Getter') to select which+-- exceptions are caught (c.f. 'tryJust', 'catchJust'). If the 'Exception' does+-- not match the predicate, it is re-thrown.+--+-- @+-- 'trying' :: 'MonadCatchIO' m => 'Prism''     'SomeException' a -> m r -> m ('Either' a r)+-- 'trying' :: 'MonadCatchIO' m => 'Lens''      'SomeException' a -> m r -> m ('Either' a r)+-- 'trying' :: 'MonadCatchIO' m => 'Traversal'' 'SomeException' a -> m r -> m ('Either' a r)+-- 'trying' :: 'MonadCatchIO' m => 'Iso''       'SomeException' a -> m r -> m ('Either' a r)+-- 'trying' :: 'MonadCatchIO' m => 'Getter'     'SomeException' a -> m r -> m ('Either' a r)+-- 'trying' :: 'MonadCatchIO' m => 'Fold'       'SomeException' a -> m r -> m ('Either' a r)+-- @+trying :: MonadCatchIO m => Getting (First a) SomeException t a b -> m r -> m (Either a r)+trying l = tryJust (preview l)++-- | A helper version of 'CatchIO.try' that doesn't needlessly require 'Functor'.+try :: (MonadCatchIO m, Exception e) => m a -> m (Either e a)+try a = CatchIO.catch (liftM Right a) (return . Left)++-- | A helper version of 'CatchIO.tryJust' that doesn't needlessly require 'Functor'.+tryJust :: (MonadCatchIO m, Exception e) => (e -> Maybe b) -> m a -> m (Either b a)+tryJust p a = do+  r <- try a+  case r of+    Right v -> return (Right v)+    Left  e -> case p e of+      Nothing -> CatchIO.throw e `asTypeOf` return (Left undefined)+      Just b  -> return (Left b)++------------------------------------------------------------------------------+-- Throwing+------------------------------------------------------------------------------++-- | Throw an 'Exception' described by a 'Prism'. Exceptions may be thrown from+-- purely functional code, but may only be caught within the 'IO' 'Monad'.+--+-- @'throwing' l ≡ 'reviews' l 'throw'@+--+-- @+-- 'throwing' :: 'Prism'' 'SomeException' t -> t -> a+-- 'throwing' :: 'Iso'' 'SomeException' t   -> t -> a+-- @+throwing :: AReview s SomeException a b -> b -> a+throwing l = reviews l Exception.throw+{-# INLINE throwing #-}++-- | A variant of 'throwing' that can only be used within the 'IO' 'Monad'+-- (or any other 'MonadCatchIO' instance) to throw an 'Exception' described +-- by a 'Prism'.+--+-- Although 'throwingM' has a type that is a specialization of the type of+-- 'throwing', the two functions are subtly different:+--+-- @+-- 'throwing' l e \`seq\` x   ≡ 'throwing' e+-- 'throwingM' l e \`seq\` x ≡ x+-- @+--+-- The first example will cause the 'Exception' @e@ to be raised, whereas the+-- second one won't. In fact, 'throwingM' will only cause an 'Exception' to+-- be raised when it is used within the 'MonadCatchIO' instance. The 'throwingM'+-- variant should be used in preference to 'throwing' to raise an 'Exception'+-- within the 'Monad' because it guarantees ordering with respect to other+-- monadic operations, whereas 'throwing' does not.+--+-- @'throwingM' l ≡ 'reviews' l 'CatchIO.throw'@+--+-- @+-- 'throwingM' :: 'MonadCatchIO' m => 'Prism'' 'SomeException' t -> t -> m a+-- 'throwingM' :: 'MonadCatchIO' m => 'Iso'' 'SomeException' t   -> t -> m a+-- @+throwingM :: MonadCatchIO m => AReview s SomeException a b -> b -> m a+throwingM l = reviews l (liftIO . throwIO)+{-# INLINE throwingM #-}++-- | 'throwingTo' raises an 'Exception' specified by a 'Prism' in the target thread.+--+-- @'throwingTo' thread l ≡ 'reviews' l ('throwTo' thread)@+--+--+-- @+-- 'throwingTo' :: 'ThreadId' -> 'Prism'' 'SomeException' t -> t -> m a+-- 'throwingTo' :: 'ThreadId' -> 'Iso'' 'SomeException' t   -> t -> m a+-- @+throwingTo :: MonadIO m => ThreadId -> AReview s SomeException a b -> b -> m ()+throwingTo tid l = reviews l (liftIO . throwTo tid)+{-# INLINE throwingTo #-}++----------------------------------------------------------------------------+-- IOException+----------------------------------------------------------------------------++-- | Exceptions that occur in the 'IO' 'Monad'. An 'IOException' records a+-- more specific error type, a descriptive string and maybe the handle that was+-- used when the error was flagged.+--+-- Due to their richer structure relative to other exceptions, these have+-- a more carefully overloaded signature.+class AsIOException p f t where+  -- | Unfortunately the name 'ioException' is taken by @base@ for+  -- throwing IOExceptions.+  --+  -- @+  -- '_IOException' :: 'Equality'' 'IOException' 'IOException'+  -- '_IOException' :: 'Prism'' 'SomeException' 'IOException'+  -- @+  --+  -- Many combinators for working with an 'IOException' are available+  -- in "System.IO.Error.Lens".+  _IOException :: Overloaded' p f t IOException++instance AsIOException p f IOException where+  _IOException = id+  {-# INLINE _IOException #-}++instance (Choice p, Applicative f) => AsIOException p f SomeException where+  _IOException = exception+  {-# INLINE _IOException #-}++----------------------------------------------------------------------------+-- ArithException+----------------------------------------------------------------------------++-- | Arithmetic exceptions.+class AsArithException p f t where+  -- '_ArithException' :: 'Equality'' 'ArithException' 'ArithException'+  -- '_ArithException' :: 'Prism''    'SomeException'  'ArithException'+  _ArithException :: Overloaded' p f t ArithException++instance AsArithException p f ArithException where+  _ArithException = id+  {-# INLINE _ArithException #-}++instance (Choice p, Applicative f) => AsArithException p f SomeException where+  _ArithException = exception+  {-# INLINE _ArithException #-}++-- | Handle arithmetic '_Overflow'.+--+-- @'_Overflow' ≡ '_ArithException' '.' '_Overflow'@+--+-- @+-- '_Overflow' :: 'Prism'' 'ArithException' 'ArithException'+-- '_Overflow' :: 'Prism'' 'SomeException'  'ArithException'+-- @+_Overflow :: (AsArithException p f t, Choice p, Applicative f) => Overloaded' p f t ()+_Overflow = _ArithException . dimap seta (either id id) . right' . rmap (Overflow <$) where+  seta Overflow = Right ()+  seta t        = Left  (pure t)+{-# INLINE _Overflow #-}++-- | Handle arithmetic '_Underflow'.+--+-- @'_Underflow' ≡ '_ArithException' '.' '_Underflow'@+--+-- @+-- '_Underflow' :: 'Prism'' 'ArithException' 'ArithException'+-- '_Underflow' :: 'Prism'' 'SomeException'  'ArithException'+-- @+_Underflow :: (AsArithException p f t, Choice p, Applicative f) => Overloaded' p f t ()+_Underflow = _ArithException . dimap seta (either id id) . right' . rmap (Underflow <$) where+  seta Underflow = Right ()+  seta t        = Left  (pure t)+{-# INLINE _Underflow #-}++-- | Handle arithmetic loss of precision.+--+-- @'_LossOfPrecision' ≡ '_ArithException' '.' '_LossOfPrecision'@+--+-- @+-- '_LossOfPrecision' :: 'Prism'' 'ArithException' 'ArithException'+-- '_LossOfPrecision' :: 'Prism'' 'SomeException'  'ArithException'+-- @+_LossOfPrecision :: (AsArithException p f t, Choice p, Applicative f) => Overloaded' p f t ()+_LossOfPrecision = _ArithException . dimap seta (either id id) . right' . rmap (LossOfPrecision <$) where+  seta LossOfPrecision = Right ()+  seta t        = Left  (pure t)+{-# INLINE _LossOfPrecision #-}++-- | Handle division by zero.+--+-- @'_DivideByZero' ≡ '_ArithException' '.' '_DivideByZero'@+--+-- @+-- '_DivideByZero' :: 'Prism'' 'ArithException' 'ArithException'+-- '_DivideByZero' :: 'Prism'' 'SomeException'  'ArithException'+-- @+_DivideByZero :: (AsArithException p f t, Choice p, Applicative f) => Overloaded' p f t ()+_DivideByZero = _ArithException . dimap seta (either id id) . right' . rmap (DivideByZero <$) where+  seta DivideByZero = Right ()+  seta t        = Left  (pure t)+{-# INLINE _DivideByZero #-}++-- | Handle exceptional _Denormalized floating point.+--+-- @'_Denormal' ≡ '_ArithException' '.' '_Denormal'@+--+-- @+-- '_Denormal' :: 'Prism'' 'ArithException' 'ArithException'+-- '_Denormal' :: 'Prism'' 'SomeException'  'ArithException'+-- @+_Denormal :: (AsArithException p f t, Choice p, Applicative f) => Overloaded' p f t ()+_Denormal = _ArithException . dimap seta (either id id) . right' . rmap (Denormal <$) where+  seta Denormal = Right ()+  seta t        = Left  (pure t)+{-# INLINE _Denormal #-}++#if MIN_VERSION_base(4,6,0)+-- | Added in @base@ 4.6 in response to this libraries discussion:+--+-- <http://haskell.1045720.n5.nabble.com/Data-Ratio-and-exceptions-td5711246.html>+--+-- @'_RatioZeroDenominator' ≡ '_ArithException' '.' '_RatioZeroDenominator'@+--+-- @+-- '_RatioZeroDenominator' :: 'Prism'' 'ArithException' 'ArithException'+-- '_RatioZeroDenominator' :: 'Prism'' 'SomeException'  'ArithException'+-- @+_RatioZeroDenominator :: (AsArithException p f t, Choice p, Applicative f) => Overloaded' p f t ()+_RatioZeroDenominator = _ArithException . dimap seta (either id id) . right' . rmap (RatioZeroDenominator <$) where+  seta RatioZeroDenominator = Right ()+  seta t        = Left  (pure t)+{-# INLINE _RatioZeroDenominator #-}++#endif++----------------------------------------------------------------------------+-- ArrayException+----------------------------------------------------------------------------++-- | Exceptions generated by array operations.+class AsArrayException p f t where+  -- | Extract information about an 'ArrayException'.+  --+  -- @+  -- '_ArrayException' :: 'Equality'' 'ArrayException' 'ArrayException'+  -- '_ArrayException' :: 'Prism''    'SomeException'  'ArrayException'+  -- @+  _ArrayException :: Overloaded' p f t ArrayException++instance AsArrayException p f ArrayException where+  _ArrayException = id+  {-# INLINE _ArrayException #-}++instance (Choice p, Applicative f) => AsArrayException p f SomeException where+  _ArrayException = exception+  {-# INLINE _ArrayException #-}++-- | An attempt was made to index an array outside its declared bounds.+--+-- @'_IndexOutOfBounds' ≡ '_ArrayException' '.' '_IndexOutOfBounds'@+--+-- @+-- '_IndexOutOfBounds' :: 'Prism'' 'ArrayException' 'String'+-- '_IndexOutOfBounds' :: 'Prism'' 'SomeException'  'String'+-- @+_IndexOutOfBounds :: (AsArrayException p f t, Choice p, Applicative f) => Overloaded' p f t String+_IndexOutOfBounds = _ArrayException . dimap seta (either id id) . right' . rmap (fmap IndexOutOfBounds) where+  seta (IndexOutOfBounds r) = Right r+  seta t                    = Left  (pure t)+{-# INLINE _IndexOutOfBounds #-}++-- | An attempt was made to evaluate an element of an array that had not been initialized.+--+-- @'_UndefinedElement' ≡ '_ArrayException' '.' '_UndefinedElement'@+--+-- @+-- '_UndefinedElement' :: 'Prism'' 'ArrayException' 'String'+-- '_UndefinedElement' :: 'Prism'' 'SomeException'  'String'+-- @+_UndefinedElement :: (AsArrayException p f t, Choice p, Applicative f) => Overloaded' p f t String+_UndefinedElement = _ArrayException . dimap seta (either id id) . right' . rmap (fmap UndefinedElement) where+  seta (UndefinedElement r) = Right r+  seta t                    = Left  (pure t)+{-# INLINE _UndefinedElement #-}++----------------------------------------------------------------------------+-- AssertionFailed+----------------------------------------------------------------------------++-- | 'assert' was applied to 'Prelude.False'.+class AsAssertionFailed p f t where+  -- | This exception contains provides information about what assertion failed in the string.+  --+  -- >>> handling _AssertionFailed (\ xs -> "caught" <$ guard ("<interactive>" `isInfixOf` xs) ) $ assert False (return "uncaught")+  -- "caught"+  --+  -- @+  -- '_AssertionFailed' :: 'Iso''   'AssertionFailed' 'String'+  -- '_AssertionFailed' :: 'Prism'' 'SomeException'   'String'+  -- @+  _AssertionFailed :: Overloaded' p f t String++instance (Profunctor p, Functor f) => AsAssertionFailed p f AssertionFailed where+  _AssertionFailed = unwrapping AssertionFailed+  {-# INLINE _AssertionFailed #-}++instance (Choice p, Applicative f) => AsAssertionFailed p f SomeException where+  _AssertionFailed = exception.unwrapping AssertionFailed+  {-# INLINE _AssertionFailed #-}++----------------------------------------------------------------------------+-- AsyncException+----------------------------------------------------------------------------++-- | Asynchronous exceptions.+class AsAsyncException p f t where+  -- | There are several types of 'AsyncException'.+  --+  -- @+  -- '_AsyncException' :: 'Equality'' 'AsyncException' 'AsyncException'+  -- '_AsyncException' :: 'Prism''    'SomeException'  'AsyncException'+  -- @+  _AsyncException :: Overloaded' p f t AsyncException++instance AsAsyncException p f AsyncException where+  _AsyncException = id+  {-# INLINE _AsyncException #-}++instance (Choice p, Applicative f) => AsAsyncException p f SomeException where+  _AsyncException = exception+  {-# INLINE _AsyncException #-}++-- | The current thread's stack exceeded its limit. Since an 'Exception' has+-- been raised, the thread's stack will certainly be below its limit again,+-- but the programmer should take remedial action immediately.+--+-- @+-- '_StackOverflow' :: 'Prism'' 'AsyncException' ()+-- '_StackOverflow' :: 'Prism'' 'SomeException'  ()+-- @+_StackOverflow :: (AsAsyncException p f t, Choice p, Applicative f) => Overloaded' p f t ()+_StackOverflow = _AsyncException . dimap seta (either id id) . right' . rmap (StackOverflow <$) where+  seta StackOverflow = Right ()+  seta t             = Left  (pure t)+{-# INLINE _StackOverflow #-}++-- | The program's heap is reaching its limit, and the program should take action+-- to reduce the amount of live data it has.+--+-- Notes:+--+-- * It is undefined which thread receives this 'Exception'.+--+-- * GHC currently does not throw 'HeapOverflow' exceptions.+--+-- @+-- '_HeapOverflow' :: 'Prism'' 'AsyncException' ()+-- '_HeapOverflow' :: 'Prism'' 'SomeException'  ()+-- @+_HeapOverflow :: (AsAsyncException p f t, Choice p, Applicative f) => Overloaded' p f t ()+_HeapOverflow = _AsyncException . dimap seta (either id id) . right' . rmap (HeapOverflow <$) where+  seta HeapOverflow = Right ()+  seta t             = Left  (pure t)+{-# INLINE _HeapOverflow #-}++-- | This 'Exception' is raised by another thread calling+-- 'Control.Concurrent.killThread', or by the system if it needs to terminate+-- the thread for some reason.+--+-- @+-- '_ThreadKilled' :: 'Prism'' 'AsyncException' ()+-- '_ThreadKilled' :: 'Prism'' 'SomeException'  ()+-- @+_ThreadKilled :: (AsAsyncException p f t, Choice p, Applicative f) => Overloaded' p f t ()+_ThreadKilled = _AsyncException . dimap seta (either id id) . right' . rmap (ThreadKilled <$) where+  seta ThreadKilled = Right ()+  seta t             = Left  (pure t)+{-# INLINE _ThreadKilled #-}++-- | This 'Exception' is raised by default in the main thread of the program when+-- the user requests to terminate the program via the usual mechanism(s)+-- (/e.g./ Control-C in the console).+--+-- @+-- '_UserInterrupt' :: 'Prism'' 'AsyncException' ()+-- '_UserInterrupt' :: 'Prism'' 'SomeException'  ()+-- @+_UserInterrupt :: (AsAsyncException p f t, Choice p, Applicative f) => Overloaded' p f t ()+_UserInterrupt = _AsyncException . dimap seta (either id id) . right' . rmap (UserInterrupt <$) where+  seta UserInterrupt = Right ()+  seta t             = Left  (pure t)+{-# INLINE _UserInterrupt #-}++----------------------------------------------------------------------------+-- AsyncException+----------------------------------------------------------------------------++-- | Thrown when the runtime system detects that the computation is guaranteed+-- not to terminate. Note that there is no guarantee that the runtime system+-- will notice whether any given computation is guaranteed to terminate or not.+class (Profunctor p, Functor f) => AsNonTermination p f t where+  -- | There is no additional information carried in a 'NonTermination' exception.+  --+  -- @+  -- '_NonTermination' :: 'Iso''   'NonTermination' ()+  -- '_NonTermination' :: 'Prism'' 'SomeException'  ()+  -- @+  _NonTermination :: Overloaded' p f t ()++instance (Profunctor p, Functor f) => AsNonTermination p f NonTermination where+  _NonTermination = trivial NonTermination+  {-# INLINE _NonTermination #-}++instance (Choice p, Applicative f) => AsNonTermination p f SomeException where+  _NonTermination = exception.trivial NonTermination+  {-# INLINE _NonTermination #-}++----------------------------------------------------------------------------+-- NestedAtomically+----------------------------------------------------------------------------++-- | Thrown when the program attempts to call atomically, from the+-- 'Control.Monad.STM' package, inside another call to atomically.+class (Profunctor p, Functor f) => AsNestedAtomically p f t where+  -- | There is no additional information carried in a 'NestedAtomically' exception.+  --+  -- @+  -- '_NestedAtomically' :: 'Iso''   'NestedAtomically' ()+  -- '_NestedAtomically' :: 'Prism'' 'SomeException'    ()+  -- @+  _NestedAtomically :: Overloaded' p f t ()++instance (Profunctor p, Functor f) => AsNestedAtomically p f NestedAtomically where+  _NestedAtomically = trivial NestedAtomically+  {-# INLINE _NestedAtomically #-}++instance (Choice p, Applicative f) => AsNestedAtomically p f SomeException where+  _NestedAtomically = exception.trivial NestedAtomically+  {-# INLINE _NestedAtomically #-}++----------------------------------------------------------------------------+-- BlockedIndefinitelyOnMVar+----------------------------------------------------------------------------++-- | The thread is blocked on an 'Control.Concurrent.MVar.MVar', but there+-- are no other references to the 'Control.Concurrent.MVar.MVar' so it can't+-- ever continue.+class (Profunctor p, Functor f) => AsBlockedIndefinitelyOnMVar p f t where+  -- | There is no additional information carried in a 'BlockedIndefinitelyOnMVar' exception.+  --+  -- @+  -- '_BlockedIndefinitelyOnMVar' :: 'Iso''   'BlockedIndefinitelyOnMVar' ()+  -- '_BlockedIndefinitelyOnMVar' :: 'Prism'' 'SomeException'             ()+  -- @+  _BlockedIndefinitelyOnMVar :: Overloaded' p f t ()++instance (Profunctor p, Functor f) => AsBlockedIndefinitelyOnMVar p f BlockedIndefinitelyOnMVar where+  _BlockedIndefinitelyOnMVar = trivial BlockedIndefinitelyOnMVar+  {-# INLINE _BlockedIndefinitelyOnMVar #-}++instance (Choice p, Applicative f) => AsBlockedIndefinitelyOnMVar p f SomeException where+  _BlockedIndefinitelyOnMVar = exception.trivial BlockedIndefinitelyOnMVar+  {-# INLINE _BlockedIndefinitelyOnMVar #-}++----------------------------------------------------------------------------+-- BlockedIndefinitelyOnSTM+----------------------------------------------------------------------------++-- | The thread is waiting to retry an 'Control.Monad.STM.STM' transaction,+-- but there are no other references to any TVars involved, so it can't ever+-- continue.+class (Profunctor p, Functor f) => AsBlockedIndefinitelyOnSTM p f t where+  -- | There is no additional information carried in a 'BlockedIndefinitelyOnSTM' exception.+  --+  -- @+  -- '_BlockedIndefinitelyOnSTM' :: 'Iso''   'BlockedIndefinitelyOnSTM' ()+  -- '_BlockedIndefinitelyOnSTM' :: 'Prism'' 'SomeException'            ()+  -- @+  _BlockedIndefinitelyOnSTM :: Overloaded' p f t ()++instance (Profunctor p, Functor f) => AsBlockedIndefinitelyOnSTM p f BlockedIndefinitelyOnSTM where+  _BlockedIndefinitelyOnSTM = trivial BlockedIndefinitelyOnSTM+  {-# INLINE _BlockedIndefinitelyOnSTM #-}++instance (Choice p, Applicative f) => AsBlockedIndefinitelyOnSTM p f SomeException where+  _BlockedIndefinitelyOnSTM = exception.trivial BlockedIndefinitelyOnSTM+  {-# INLINE _BlockedIndefinitelyOnSTM #-}++----------------------------------------------------------------------------+-- Deadlock+----------------------------------------------------------------------------++-- | There are no runnable threads, so the program is deadlocked. The+-- 'Deadlock' 'Exception' is raised in the main thread only.+class (Profunctor p, Functor f) => AsDeadlock p f t where+  -- | There is no information carried in a 'Deadlock' exception.+  --+  -- @+  -- '_Deadlock' :: 'Iso''   'Deadlock'      ()+  -- '_Deadlock' :: 'Prism'' 'SomeException' ()+  -- @+  _Deadlock :: Overloaded' p f t ()++instance (Profunctor p, Functor f) => AsDeadlock p f Deadlock where+  _Deadlock = trivial Deadlock+  {-# INLINE _Deadlock #-}++instance (Choice p, Applicative f) => AsDeadlock p f SomeException where+  _Deadlock = exception.trivial Deadlock+  {-# INLINE _Deadlock #-}++----------------------------------------------------------------------------+-- NoMethodError+----------------------------------------------------------------------------++-- | A class method without a definition (neither a default definition,+-- nor a definition in the appropriate instance) was called.+class (Profunctor p, Functor f) => AsNoMethodError p f t where+  -- | Extract a description of the missing method.+  --+  -- @+  -- '_NoMethodError' :: 'Iso''   'NoMethodError' 'String'+  -- '_NoMethodError' :: 'Prism'' 'SomeException' 'String'+  -- @+  _NoMethodError :: Overloaded' p f t String++instance (Profunctor p, Functor f) => AsNoMethodError p f NoMethodError where+  _NoMethodError = unwrapping NoMethodError+  {-# INLINE _NoMethodError #-}++instance (Choice p, Applicative f) => AsNoMethodError p f SomeException where+  _NoMethodError = exception.unwrapping NoMethodError+  {-# INLINE _NoMethodError #-}++----------------------------------------------------------------------------+-- PatternMatchFail+----------------------------------------------------------------------------++-- | A pattern match failed.+class (Profunctor p, Functor f) => AsPatternMatchFail p f t where+  -- | Information about the source location of the pattern.+  --+  -- @+  -- '_PatternMatchFail' :: 'Iso''   'PatternMatchFail' 'String'+  -- '_PatternMatchFail' :: 'Prism'' 'SomeException'    'String'+  -- @+  _PatternMatchFail :: Overloaded' p f t String++instance (Profunctor p, Functor f) => AsPatternMatchFail p f PatternMatchFail where+  _PatternMatchFail = unwrapping PatternMatchFail+  {-# INLINE _PatternMatchFail #-}++instance (Choice p, Applicative f) => AsPatternMatchFail p f SomeException where+  _PatternMatchFail = exception.unwrapping PatternMatchFail+  {-# INLINE _PatternMatchFail #-}++----------------------------------------------------------------------------+-- RecConError+----------------------------------------------------------------------------++-- | An uninitialised record field was used.+class (Profunctor p, Functor f) => AsRecConError p f t where+  -- | Information about the source location where the record was+  -- constructed.+  --+  -- @+  -- '_RecConError' :: 'Iso''   'RecConError'   'String'+  -- '_RecConError' :: 'Prism'' 'SomeException' 'String'+  -- @+  _RecConError :: Overloaded' p f t String++instance (Profunctor p, Functor f) => AsRecConError p f RecConError where+  _RecConError = unwrapping RecConError+  {-# INLINE _RecConError #-}++instance (Choice p, Applicative f) => AsRecConError p f SomeException where+  _RecConError = exception.unwrapping RecConError+  {-# INLINE _RecConError #-}++----------------------------------------------------------------------------+-- RecSelError+----------------------------------------------------------------------------++-- | A record selector was applied to a constructor without the appropriate+-- field. This can only happen with a datatype with multiple constructors,+-- where some fields are in one constructor but not another.+class (Profunctor p, Functor f) => AsRecSelError p f t where+  -- | Information about the source location where the record selection occurred.+  _RecSelError :: Overloaded' p f t String++instance (Profunctor p, Functor f) => AsRecSelError p f RecSelError where+  _RecSelError = unwrapping RecSelError+  {-# INLINE _RecSelError #-}++instance (Choice p, Applicative f) => AsRecSelError p f SomeException where+  _RecSelError = exception.unwrapping RecSelError+  {-# INLINE _RecSelError #-}++----------------------------------------------------------------------------+-- RecUpdError+----------------------------------------------------------------------------++-- | A record update was performed on a constructor without the+-- appropriate field. This can only happen with a datatype with multiple+-- constructors, where some fields are in one constructor but not another.+class (Profunctor p, Functor f) => AsRecUpdError p f t where+  -- | Information about the source location where the record was updated.+  _RecUpdError :: Overloaded' p f t String++instance (Profunctor p, Functor f) => AsRecUpdError p f RecUpdError where+  _RecUpdError = unwrapping RecUpdError+  {-# INLINE _RecUpdError #-}++instance (Choice p, Applicative f) => AsRecUpdError p f SomeException where+  _RecUpdError = exception.unwrapping RecUpdError+  {-# INLINE _RecUpdError #-}++----------------------------------------------------------------------------+-- ErrorCall+----------------------------------------------------------------------------++-- | This is thrown when the user calls 'Prelude.error'.+class (Profunctor p, Functor f) => AsErrorCall p f t where+  -- | Retrieve the argument given to 'Prelude.error'.+  --+  -- 'ErrorCall' is isomorphic to a 'String'.+  --+  -- >>> catching _ErrorCall (error "touch down!") return+  -- "touch down!"+  _ErrorCall :: Overloaded' p f t String++instance (Profunctor p, Functor f) => AsErrorCall p f ErrorCall where+  _ErrorCall = unwrapping ErrorCall+  {-# INLINE _ErrorCall #-}++instance (Choice p, Applicative f) => AsErrorCall p f SomeException where+  _ErrorCall = exception.unwrapping ErrorCall+  {-# INLINE _ErrorCall #-}++------------------------------------------------------------------------------+-- Helper Functions+------------------------------------------------------------------------------++trivial :: t -> Iso' t ()+trivial t = const () `iso` const t
src/Control/Lens.hs view
@@ -1,16 +1,12 @@ {-# LANGUAGE CPP #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE Rank2Types #-}-{-# LANGUAGE LiberalTypeSynonyms #-}-{-# LANGUAGE FlexibleContexts #-} ----------------------------------------------------------------------------- -- | -- Module      :  Control.Lens--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com>--- Stability   :  provisional--- Portability :  Rank2Types+-- Stability   :  experimental+-- Portability :  non-portable -- -- Usage: --@@ -25,7 +21,7 @@ -- This defines the following lenses: -- -- @--- fooArgs :: 'Simple' 'Lens' (Foo a) ['String']+-- fooArgs :: 'Lens'' (Foo a) ['String'] -- fooValue :: 'Lens' (Foo a) (Foo b) a b -- @ --@@ -41,62 +37,66 @@ -- -- <http://github.com/ekmett/lens/wiki> ----- <<http://github.com/ekmett/lens/wiki/images/Hierarchy-3.7.png>>+-- <<http://github.com/ekmett/lens/wiki/images/Hierarchy-3.8.png>> ---------------------------------------------------------------------------- module Control.Lens   ( module Control.Lens.Action+  , module Control.Lens.At   , module Control.Lens.Combinators+  , module Control.Lens.Cons   , module Control.Lens.Each+  , module Control.Lens.Equality   , module Control.Lens.Fold   , module Control.Lens.Getter   , module Control.Lens.Indexed-  , module Control.Lens.IndexedFold-  , module Control.Lens.IndexedGetter-  , module Control.Lens.IndexedLens-  , module Control.Lens.IndexedSetter-  , module Control.Lens.IndexedTraversal   , module Control.Lens.Iso+  , module Control.Lens.Lens+  , module Control.Lens.Level   , module Control.Lens.Loupe   , module Control.Lens.Plated   , module Control.Lens.Prism-  , module Control.Lens.Representable+  , module Control.Lens.Reified+  , module Control.Lens.Review   , module Control.Lens.Setter+  , module Control.Lens.Simple #ifndef DISABLE_TEMPLATE_HASKELL   , module Control.Lens.TH #endif   , module Control.Lens.Traversal   , module Control.Lens.Tuple   , module Control.Lens.Type-  , module Control.Lens.WithIndex   , module Control.Lens.Wrapped   , module Control.Lens.Zipper   , module Control.Lens.Zoom   ) where  import Control.Lens.Action+import Control.Lens.At import Control.Lens.Combinators+import Control.Lens.Cons import Control.Lens.Each+import Control.Lens.Equality import Control.Lens.Fold import Control.Lens.Getter import Control.Lens.Indexed-import Control.Lens.IndexedFold-import Control.Lens.IndexedGetter-import Control.Lens.IndexedLens-import Control.Lens.IndexedSetter-import Control.Lens.IndexedTraversal import Control.Lens.Iso+import Control.Lens.Lens+import Control.Lens.Level import Control.Lens.Loupe import Control.Lens.Plated import Control.Lens.Prism-import Control.Lens.Representable+import Control.Lens.Reified+import Control.Lens.Review import Control.Lens.Setter+import Control.Lens.Simple #ifndef DISABLE_TEMPLATE_HASKELL import Control.Lens.TH #endif import Control.Lens.Traversal import Control.Lens.Tuple import Control.Lens.Type-import Control.Lens.WithIndex import Control.Lens.Wrapped import Control.Lens.Zipper import Control.Lens.Zoom++{-# ANN module "HLint: ignore Use import/export shortcut" #-}
src/Control/Lens/Action.hs view
@@ -1,14 +1,14 @@-{-# LANGUAGE MagicHash #-} {-# LANGUAGE Rank2Types #-}+{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MultiParamTypeClasses #-} ----------------------------------------------------------------------------- -- | -- Module      :  Control.Lens.Action--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  experimental--- Portability :  MTPCs, FDs, Rank2+-- Portability :  non-portable -- ---------------------------------------------------------------------------- module Control.Lens.Action@@ -21,73 +21,106 @@   , performs   , liftAct   , (^!)+  , (^!!)+  , (^!?) +  -- * Indexed Actions+  , IndexedAction+  , iact+  , iperform+  , iperforms+  , (^@!)+  , (^@!!)+  , (^@!?)+   -- * Folds with Effects   , MonadicFold+  , IndexedMonadicFold    -- * Implementation Details   , Acting+  , IndexedActing+  , Effective   ) where -import Control.Applicative-import Control.Lens.Classes-import Control.Lens.Internal-import Control.Lens.Internal.Combinators+import Control.Comonad+import Control.Lens.Internal.Action+import Control.Lens.Internal.Fold+import Control.Lens.Internal.Indexed+import Control.Lens.Type+import Control.Monad (liftM) import Control.Monad.Trans.Class+import Data.Profunctor+import Data.Profunctor.Rep+import Data.Profunctor.Unsafe  -- $setup -- >>> :m + Control.Lens -infixr 8 ^!---- | An 'Action' is a 'Getter' enriched with access to a 'Monad' for side-effects.------ Every 'Getter' can be used as an 'Action'------ You can compose an 'Action' with another 'Action' using ('Prelude..') from the @Prelude@.-type Action m s a = forall f r. Effective m r f => (a -> f a) -> s -> f s---- | A 'MonadicFold' is a 'Fold' enriched with access to a 'Monad' for side-effects.------ Every 'Fold' can be used as a 'MonadicFold', that simply ignores the access to the 'Monad'.------ You can compose a 'MonadicFold' with another 'MonadicFold' using ('Prelude..') from the @Prelude@.-type MonadicFold m s a = forall f r. (Effective m r f, Applicative f) => (a -> f a) -> s -> f s+infixr 8 ^!, ^!!, ^@!, ^@!!, ^!?, ^@!?  -- | Used to evaluate an 'Action'.-type Acting m r s t a b = (a -> Effect m r b) -> s -> Effect m r t+type Acting m r s t a b = LensLike (Effect m r) s t a b  -- | Perform an 'Action'. ----- @'perform' ≡ 'flip' ('^!')@+-- @+-- 'perform' ≡ 'flip' ('^!')+-- @ perform :: Monad m => Acting m a s t a b -> s -> m a-perform l = getEffect# (l (effect# return))+perform l = getEffect #. l (Effect #. return) {-# INLINE perform #-}  -- | Perform an 'Action' and modify the result.-performs :: Monad m => Acting m e s t a b -> (a -> e) -> s -> m e-performs l f = getEffect# (l (effect# (return . f)))+--+-- @+-- 'performs' :: 'Monad' m => 'Acting' m e s t a b -> (a -> e) -> s -> m e+-- @+performs :: (Profunctor p, Monad m) => Over p (Effect m e) s t a b -> p a e -> s -> m e+performs l f = getEffect #. l (rmap (Effect #. return) f)+{-# INLINE performs #-} --- | Perform an 'Action'+-- | Perform an 'Action'. -- -- >>> ["hello","world"]^!folded.act putStrLn -- hello -- world (^!) :: Monad m => s -> Acting m a s t a b -> m a-a ^! l = getEffect (l (effect# return) a)+a ^! l = getEffect (l (Effect #. return) a) {-# INLINE (^!) #-} --- | Construct an 'Action' from a monadic side-effect+-- | Perform a 'MonadicFold' and collect all of the results in a list.+(^!!) :: Monad m => s -> Acting m [a] s t a b -> m [a]+a ^!! l = getEffect (l (Effect #. return . return) a)+{-# INLINE (^!!) #-}++-- | Perform a 'MonadicFold' and collect the leftmost result. --+-- /Note:/ this still causes all effects for all elements.+(^!?) :: Monad m => s -> Acting m (Leftmost a) s t a b -> m (Maybe a)+a ^!?  l = liftM getLeftmost .# getEffect $ l (Effect #. return . LLeaf) a+{-# INLINE (^!?) #-}++-- | Construct an 'Action' from a monadic side-effect.+-- -- >>> ["hello","world"]^!folded.act (\x -> [x,x ++ "!"]) -- ["helloworld","helloworld!","hello!world","hello!world!"]-act :: Monad m => (s -> m a) -> Action m s a-act sma afb a = effective (sma a >>= ineffective . afb)+--+-- @+-- 'act' :: 'Monad' m => (s -> m a) -> 'Action' m s a+-- 'act' sma afb a = 'effective' (sma a '>>=' 'ineffective' '.' afb)+-- @+act :: Monad m => (s -> m a) -> IndexPreservingAction m s a+act sma pafb = cotabulate $ \ws -> effective $ do+   a <- sma (extract ws)+   ineffective (corep pafb (a <$ ws)) {-# INLINE act #-}  -- | A self-running 'Action', analogous to 'Control.Monad.join'. ----- @'acts' ≡ 'act' 'id'@+-- @+-- 'acts' ≡ 'act' 'id'+-- @ -- -- >>> (1,"hello")^!_2.acts.to succ -- "ifmmp"@@ -99,3 +132,48 @@ liftAct :: (MonadTrans trans, Monad m) => Acting m a s t a b -> Action (trans m) s a liftAct l = act (lift . perform l) {-# INLINE liftAct #-}++-----------------------------------------------------------------------------+-- Indexed Actions+----------------------------------------------------------------------------++-- | Used to evaluate an 'IndexedAction'.+type IndexedActing i m r s t a b = Over (Indexed i) (Effect m r) s t a b++-- | Perform an 'IndexedAction'.+--+-- @+-- 'iperform' ≡ 'flip' ('^@!')+-- @+iperform :: Monad m => IndexedActing i m (i, a) s t a b -> s -> m (i, a)+iperform l = getEffect #. l (Indexed $ \i a -> Effect (return (i, a)))+{-# INLINE iperform #-}++-- | Perform an 'IndexedAction' and modify the result.+iperforms :: Monad m => IndexedActing i m e s t a b -> (i -> a -> e) -> s -> m e+iperforms l = performs l .# Indexed+{-# INLINE iperforms #-}++-- | Perform an 'IndexedAction'.+(^@!) :: Monad m => s -> IndexedActing i m (i, a) s t a b -> m (i, a)+s ^@! l = getEffect (l (Indexed $ \i a -> Effect (return (i, a))) s)+{-# INLINE (^@!) #-}++-- | Obtain a list of all of the results of an 'IndexedMonadicFold'.+(^@!!) :: Monad m => s -> IndexedActing i m [(i, a)] s t a b -> m [(i, a)]+s ^@!! l = getEffect (l (Indexed $ \i a -> Effect (return [(i, a)])) s)+{-# INLINE (^@!!) #-}++-- | Perform an 'IndexedMonadicFold' and collect the 'Leftmost' result.+--+-- /Note:/ this still causes all effects for all elements.+(^@!?) :: Monad m => s -> IndexedActing i m (Leftmost (i, a)) s t a b -> m (Maybe (i, a))+a ^@!?  l = liftM getLeftmost .# getEffect $ l (Indexed $ \i -> Effect #. return . LLeaf . (,) i) a+{-# INLINE (^@!?) #-}++-- | Construct an 'IndexedAction' from a monadic side-effect.+iact :: Monad m => (s -> m (i, a)) -> IndexedAction i m s a+iact smia iafb s = effective $ do+  (i, a) <- smia s+  ineffective (indexed iafb i a)+{-# INLINE iact #-}
+ src/Control/Lens/At.hs view
@@ -0,0 +1,552 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE GADTs #-}+{-# LANGUAGE Rank2Types #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE MultiParamTypeClasses #-}++#ifdef DEFAULT_SIGNATURES+{-# LANGUAGE DefaultSignatures #-}+#endif++#ifdef TRUSTWORTHY+{-# LANGUAGE Trustworthy #-}+#endif++#ifndef MIN_VERSION_base+#define MIN_VERSION_base(x,y,z) 1+#endif+-----------------------------------------------------------------------------+-- |+-- Module      :  Control.Lens.At+-- Copyright   :  (C) 2012-13 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  experimental+-- Portability :  non-portable+--+----------------------------------------------------------------------------+module Control.Lens.At+  (+  -- * At+    At(at)+  -- * Ixed+  , IxValue+  , Ixed(ix)+  , ixAt, ixEach+  -- * Contains+  , Contains(..)+  , containsIx, containsAt, containsLength, containsN, containsTest, containsLookup+  -- * Deprecated+  , _at+  , resultAt+  ) where++import Control.Applicative+import Control.Lens.Combinators+import Control.Lens.Each+import Control.Lens.Fold+import Control.Lens.Getter+import Control.Lens.Indexed as Lens+import Control.Lens.Type+import Control.Lens.Traversal+import Data.Array.IArray as Array+import Data.Array.Unboxed+import Data.ByteString as StrictB+import Data.ByteString.Lazy as LazyB+import Data.Complex+import Data.Functor.Identity+import Data.Hashable+import Data.HashMap.Lazy as HashMap+import Data.HashSet as HashSet+import Data.IntMap as IntMap+import Data.IntSet as IntSet+import Data.Map as Map+import Data.Maybe+import Data.Monoid+import Data.Set as Set+import Data.Sequence as Seq+import Data.Text as StrictT+import Data.Text.Lazy as LazyT+import Data.Tree+import Data.Vector as Vector hiding (indexed)+import Data.Vector.Primitive as Prim+import Data.Vector.Storable as Storable+import Data.Vector.Unboxed as Unboxed+import Data.Word++-- $setup+-- >>> import Control.Lens+-- >>> import Debug.SimpleReflect.Expr+-- >>> import Debug.SimpleReflect.Vars as Vars hiding (f,g)+-- >>> let f :: Expr -> Expr; f = Debug.SimpleReflect.Vars.f+-- >>> let g :: Expr -> Expr; g = Debug.SimpleReflect.Vars.g++-- | Deprecated aliases for 'ix'.+_at, resultAt :: Ixed f m => Index m -> IndexedLensLike' (Index m) f m (IxValue m)+_at      = ix+resultAt = ix+{-# DEPRECATED _at, resultAt "use 'ix'. This function will be removed in version 3.9" #-}++-- |+-- This class provides a simple 'IndexedFold' (or 'IndexedTraversal') that lets you view (and modify)+-- information about whether or not a container contains a given 'Index'.+class Functor f => Contains f m where+  -- |+  -- >>> IntSet.fromList [1,2,3,4] ^. contains 3+  -- True+  --+  -- >>> IntSet.fromList [1,2,3,4] ^. contains 5+  -- False+  --+  -- >>> IntSet.fromList [1,2,3,4] & contains 3 .~ False+  -- fromList [1,2,4]+  contains :: Index m -> IndexedLensLike' (Index m) f m Bool+#ifdef DEFAULT_SIGNATURES+  default contains :: (Gettable f, At m) => Index m -> IndexedLensLike' (Index m) f m Bool+  contains = containsAt+#endif++-- | A definition of 'contains' for types with an 'Ix' instance.+containsIx :: (Gettable f, Ixed (Accessor Any) m) => Index m -> IndexedLensLike' (Index m) f m Bool+containsIx i f = coerce . Lens.indexed f i . has (ix i)+{-# INLINE containsIx #-}++-- | A definition of 'ix' for types with an 'At' instance. This is the default+-- if you don't specify a definition for 'contains' and you are on GHC >= 7.0.2+containsAt :: (Gettable f, At m) => Index m -> IndexedLensLike' (Index m) f m Bool+containsAt i f = coerce . Lens.indexed f i . views (at i) isJust+{-# INLINE containsAt #-}++-- | Construct a 'contains' check based on some notion of 'Prelude.length' for the container.+containsLength :: forall i s. (Ord i, Num i) => (s -> i) -> i -> IndexedGetter i s Bool+containsLength sn = \ i pafb s -> coerce $ Lens.indexed pafb (i :: i) (0 <= i && i < sn s)+{-# INLINE containsLength #-}++-- | Construct a 'contains' check for a fixed number of elements.+containsN :: Int -> Int -> IndexedGetter Int s Bool+containsN n = \ i pafb _ -> coerce $ Lens.indexed pafb (i :: Int) (0 <= i && i < n)+{-# INLINE containsN #-}++-- | Construct a 'contains' check that uses an arbitrary test.+containsTest :: forall i s. (i -> s -> Bool) -> i -> IndexedGetter i s Bool+containsTest isb = \i pafb s -> coerce $ Lens.indexed pafb (i :: i) (isb i s)+{-# INLINE containsTest #-}++-- | Construct a 'contains' check that uses an arbitrary 'Map.lookup' function.+containsLookup :: forall i s a. (i -> s -> Maybe a) -> i -> IndexedGetter i s Bool+containsLookup isb = \i pafb s -> coerce $ Lens.indexed pafb (i :: i) (isJust (isb i s))+{-# INLINE containsLookup #-}++instance Gettable f => Contains f (e -> a) where+  contains i f _ = coerce (Lens.indexed f i True)+  {-# INLINE contains #-}++instance Functor f => Contains f IntSet where+  contains k f s = Lens.indexed f k (IntSet.member k s) <&> \b ->+    if b then IntSet.insert k s else IntSet.delete k s+  {-# INLINE contains #-}++instance (Functor f, Ord a) => Contains f (Set a) where+  contains k f s = Lens.indexed f k (Set.member k s) <&> \b ->+    if b then Set.insert k s else Set.delete k s+  {-# INLINE contains #-}++instance (Functor f, Eq a, Hashable a) => Contains f (HashSet a) where+  contains k f s = Lens.indexed f k (HashSet.member k s) <&> \b ->+    if b then HashSet.insert k s else HashSet.delete k s+  {-# INLINE contains #-}++instance Gettable f => Contains f [a] where+  contains = containsLength Prelude.length+  {-# INLINE contains #-}++instance Gettable f => Contains f (Seq a) where+  contains = containsLength Seq.length+  {-# INLINE contains #-}++#if MIN_VERSION_base(4,4,0)+instance Gettable f => Contains f (Complex a) where+  contains = containsN 2+  {-# INLINE contains #-}+#else+instance (Gettable f, RealFloat a) => Contains f (Complex a) where+  contains = containsN 2+  {-# INLINE contains #-}+#endif++instance Gettable f => Contains f (Tree a) where+  contains xs0 pafb = coerce . Lens.indexed pafb xs0 . go xs0 where+    go [] (Node _ _) = True+    go (i:is) (Node _ as) = goto i is as+    goto 0 is (a:_) = go is a+    goto _ _  []     = False+    goto n is (_:as) = (goto $! n - 1) is as+  {-# INLINE contains #-}++instance Gettable k => Contains k (Identity a) where+  contains () f _ = coerce (Lens.indexed f () True)+  {-# INLINE contains #-}++instance Gettable k => Contains k (a,b) where+  contains = containsN 2+  {-# INLINE contains #-}++instance Gettable k => Contains k (a,b,c) where+  contains = containsN 3+  {-# INLINE contains #-}++instance Gettable k => Contains k (a,b,c,d) where+  contains = containsN 4+  {-# INLINE contains #-}++instance Gettable k => Contains k (a,b,c,d,e) where+  contains = containsN 5+  {-# INLINE contains #-}++instance Gettable k => Contains k (a,b,c,d,e,f) where+  contains = containsN 6+  {-# INLINE contains #-}++instance Gettable k => Contains k (a,b,c,d,e,f,g) where+  contains = containsN 7+  {-# INLINE contains #-}++instance Gettable k => Contains k (a,b,c,d,e,f,g,h) where+  contains = containsN 8+  {-# INLINE contains #-}++instance Gettable k => Contains k (a,b,c,d,e,f,g,h,i) where+  contains = containsN 9+  {-# INLINE contains #-}++instance Gettable k => Contains k (IntMap a) where+  contains = containsLookup IntMap.lookup+  {-# INLINE contains #-}++instance (Gettable f, Ord k) => Contains f (Map k a) where+  contains = containsLookup Map.lookup+  {-# INLINE contains #-}++instance (Gettable f, Eq k, Hashable k) => Contains f (HashMap k a) where+  contains = containsLookup HashMap.lookup+  {-# INLINE contains #-}++instance (Gettable f, Ix i) => Contains f (Array i e) where+  contains = containsTest $ \i s -> inRange (bounds s) i+  {-# INLINE contains #-}++instance (Gettable f, IArray UArray e, Ix i) => Contains f (UArray i e) where+  contains = containsTest $ \i s -> inRange (bounds s) i+  {-# INLINE contains #-}++instance Gettable f => Contains f (Vector.Vector a) where+  contains = containsLength Vector.length+  {-# INLINE contains #-}++instance (Gettable f, Prim a) => Contains f (Prim.Vector a) where+  contains = containsLength Prim.length+  {-# INLINE contains #-}++instance (Gettable f, Storable a) => Contains f (Storable.Vector a) where+  contains = containsLength Storable.length+  {-# INLINE contains #-}++instance (Gettable f, Unbox a) => Contains f (Unboxed.Vector a) where+  contains = containsLength Unboxed.length+  {-# INLINE contains #-}++instance Gettable f => Contains f StrictT.Text where+  contains = containsTest $ \i s -> StrictT.compareLength s i == GT+  {-# INLINE contains #-}++instance Gettable f => Contains f LazyT.Text where+  contains = containsTest $ \i s -> LazyT.compareLength s i == GT+  {-# INLINE contains #-}++instance Gettable f => Contains f StrictB.ByteString where+  contains = containsLength StrictB.length+  {-# INLINE contains #-}++instance Gettable f => Contains f LazyB.ByteString where+  contains = containsTest $ \i s -> not (LazyB.null (LazyB.drop i s))+  {-# INLINE contains #-}++-- | This provides a common notion of a value at an index that is shared by both 'Ixed' and 'At'.+type family IxValue (m :: *) :: *++-- | This simple 'IndexedTraversal' lets you 'traverse' the value at a given+-- key in a 'Map' or element at an ordinal position in a list or 'Seq'.+class (Functor f, Contains (Accessor (IxValue m)) m) => Ixed f m where+  -- | This simple 'IndexedTraversal' lets you 'traverse' the value at a given+  -- key in a 'Map' or element at an ordinal position in a list or 'Seq'.+  --+  -- /NB:/ Setting the value of this 'Traversal' will only set the value in the+  -- 'Lens' if it is already present.+  --+  -- If you want to be able to insert /missing/ values, you want 'at'.+  --+  -- >>> Seq.fromList [a,b,c,d] & ix 2 %~ f+  -- fromList [a,b,f c,d]+  --+  -- >>> Seq.fromList [a,b,c,d] & ix 2 .~ e+  -- fromList [a,b,e,d]+  --+  -- >>> Seq.fromList [a,b,c,d] ^? ix 2+  -- Just c+  --+  -- >>> Seq.fromList [] ^? ix 2+  -- Nothing+  ix :: Index m -> IndexedLensLike' (Index m) f m (IxValue m)+#ifdef DEFAULT_SIGNATURES+  default ix :: (Applicative f, At m) => Index m -> IndexedLensLike' (Index m) f m (IxValue m)+  ix = ixAt+  {-# INLINE ix #-}+#endif++-- | A definition of 'ix' for types with an 'At' instance. This is the default+-- if you don't specify a definition for 'ix'.+ixAt :: (Applicative f, At m) => Index m -> IndexedLensLike' (Index m) f m (IxValue m)+ixAt i = at i <. traverse+{-# INLINE ixAt #-}++-- | A definition of 'ix' for types with an 'Each' instance.+ixEach :: (Applicative f, Eq (Index m), Each f m m (IxValue m) (IxValue m)) => Index m -> IndexedLensLike' (Index m) f m (IxValue m)+ixEach i = each . Lens.index i+{-# INLINE ixEach #-}++type instance IxValue [a] = a+instance Applicative f => Ixed f [a] where+  ix k f xs0 = go xs0 k where+    go [] _ = pure []+    go (a:as) 0 = Lens.indexed f k a <&> (:as)+    go (a:as) i = (a:) <$> (go as $! i - 1)+  {-# INLINE ix #-}++type instance IxValue (Identity a) = a+instance Functor f => Ixed f (Identity a) where+  ix () f (Identity a) = Identity <$> Lens.indexed f () a+  {-# INLINE ix #-}++type instance IxValue (Tree a) = a+instance Applicative f => Ixed f (Tree a) where+  ix xs0 f = go xs0 where+    go [] (Node a as) = Lens.indexed f xs0 a <&> \a' -> Node a' as+    go (i:is) (Node a as) = Node a <$> goto is as i+    goto is (a:as) 0 = go is a <&> (:as)+    goto is (_:as) n = goto is as $! n - 1+    goto _  []     _ = pure []+  {-# INLINE ix #-}++type instance IxValue (Seq a) = a+instance Applicative f => Ixed f (Seq a) where+  ix i f m+    | 0 <= i && i < Seq.length m = Lens.indexed f i (Seq.index m i) <&> \a -> Seq.update i a m+    | otherwise                  = pure m+  {-# INLINE ix #-}++type instance IxValue (IntMap a) = a+instance Applicative f => Ixed f (IntMap a) where+  ix k f m = case IntMap.lookup k m of+     Just v -> Lens.indexed f k v <&> \v' -> IntMap.insert k v' m+     Nothing -> pure m+  {-# INLINE ix #-}++type instance IxValue (Map k a) = a+instance (Applicative f, Ord k) => Ixed f (Map k a) where+  ix k f m = case Map.lookup k m of+     Just v  -> Lens.indexed f k v <&> \v' -> Map.insert k v' m+     Nothing -> pure m+  {-# INLINE ix #-}++type instance IxValue (HashMap k a) = a+instance (Applicative f, Eq k, Hashable k) => Ixed f (HashMap k a) where+  ix k f m = case HashMap.lookup k m of+     Just v  -> Lens.indexed f k v <&> \v' -> HashMap.insert k v' m+     Nothing -> pure m+  {-# INLINE ix #-}++type instance IxValue (Array i e) = e+-- |+-- @+-- arr '!' i ≡ arr 'Control.Lens.Getter.^.' 'ix' i+-- arr '//' [(i,e)] ≡ 'ix' i 'Control.Lens.Setter..~' e '$' arr+-- @+instance (Applicative f, Ix i) => Ixed f (Array i e) where+  ix i f arr+    | inRange (bounds arr) i = Lens.indexed f i (arr Array.! i) <&> \e -> arr Array.// [(i,e)]+    | otherwise              = pure arr+  {-# INLINE ix #-}++type instance IxValue (UArray i e) = e+-- |+-- @+-- arr '!' i ≡ arr 'Control.Lens.Getter.^.' 'ix' i+-- arr '//' [(i,e)] ≡ 'ix' i 'Control.Lens.Setter..~' e '$' arr+-- @+instance (Applicative f, IArray UArray e, Ix i) => Ixed f (UArray i e) where+  ix i f arr+    | inRange (bounds arr) i = Lens.indexed f i (arr Array.! i) <&> \e -> arr Array.// [(i,e)]+    | otherwise              = pure arr+  {-# INLINE ix #-}++type instance IxValue (Vector.Vector a) = a+instance Applicative f => Ixed f (Vector.Vector a) where+  ix i f v+    | 0 <= i && i < Vector.length v = Lens.indexed f i (v Vector.! i) <&> \a -> v Vector.// [(i, a)]+    | otherwise                     = pure v+  {-# INLINE ix #-}++type instance IxValue (Prim.Vector a) = a+instance (Applicative f, Prim a) => Ixed f (Prim.Vector a) where+  ix i f v+    | 0 <= i && i < Prim.length v = Lens.indexed f i (v Prim.! i) <&> \a -> v Prim.// [(i, a)]+    | otherwise                   = pure v+  {-# INLINE ix #-}++type instance IxValue (Storable.Vector a) = a+instance (Applicative f, Storable a) => Ixed f (Storable.Vector a) where+  ix i f v+    | 0 <= i && i < Storable.length v = Lens.indexed f i (v Storable.! i) <&> \a -> v Storable.// [(i, a)]+    | otherwise                       = pure v+  {-# INLINE ix #-}++type instance IxValue (Unboxed.Vector a) = a+instance (Applicative f, Unbox a) => Ixed f (Unboxed.Vector a) where+  ix i f v+    | 0 <= i && i < Unboxed.length v = Lens.indexed f i (v Unboxed.! i) <&> \a -> v Unboxed.// [(i, a)]+    | otherwise                      = pure v+  {-# INLINE ix #-}++type instance IxValue StrictT.Text = Char+instance Applicative f => Ixed f StrictT.Text where+  ix e f s = case StrictT.splitAt e s of+     (l, mr) -> case StrictT.uncons mr of+       Nothing      -> pure s+       Just (c, xs) -> Lens.indexed f e c <&> \d -> StrictT.concat [l, StrictT.singleton d, xs]+  {-# INLINE ix #-}++type instance IxValue LazyT.Text = Char+instance Applicative f => Ixed f LazyT.Text where+  ix e f s = case LazyT.splitAt e s of+     (l, mr) -> case LazyT.uncons mr of+       Nothing      -> pure s+       Just (c, xs) -> Lens.indexed f e c <&> \d -> LazyT.append l (LazyT.cons d xs)+  {-# INLINE ix #-}++type instance IxValue StrictB.ByteString = Word8+instance Applicative f => Ixed f StrictB.ByteString where+  ix e f s = case StrictB.splitAt e s of+     (l, mr) -> case StrictB.uncons mr of+       Nothing      -> pure s+       Just (c, xs) -> Lens.indexed f e c <&> \d -> StrictB.concat [l, StrictB.singleton d, xs]+  {-# INLINE ix #-}++type instance IxValue LazyB.ByteString = Word8+instance Applicative f => Ixed f LazyB.ByteString where+  -- TODO: we could be lazier, returning each chunk as it is passed+  ix e f s = case LazyB.splitAt e s of+     (l, mr) -> case LazyB.uncons mr of+       Nothing      -> pure s+       Just (c, xs) -> Lens.indexed f e c <&> \d -> LazyB.append l (LazyB.cons d xs)+  {-# INLINE ix #-}++type instance IxValue (k -> a) = a+instance (Functor f, Eq k) => Ixed f (k -> a) where+  ix e g f = Lens.indexed g e (f e) <&> \a' e' -> if e == e' then a' else f e'+  {-# INLINE ix #-}++#if MIN_VERSION_base(4,4,0)+type instance IxValue (Complex a) = a+instance Applicative f => Ixed f (Complex a) where+  ix = ixEach+  {-# INLINE ix #-}+#else+instance (Applicative f, RealFloat a) => Ixed f (Complex a) where+  ix = ixEach+  {-# INLINE ix #-}+#endif++type instance IxValue (a,a) = a+instance (Applicative f, a ~ b) => Ixed f (a,b) where+  ix = ixEach+  {-# INLINE ix #-}++type instance IxValue (a,a,a) = a+instance (Applicative f, a ~ b, b ~ c) => Ixed f (a,b,c) where+  ix = ixEach+  {-# INLINE ix #-}++type instance IxValue (a,a,a,a) = a+instance (Applicative f, a ~ b, b ~ c, c ~ d) => Ixed f (a,b,c,d) where+  ix = ixEach+  {-# INLINE ix #-}++type instance IxValue (a,a,a,a,a) = a+instance (Applicative f, a ~ b, b ~ c, c ~ d, d ~ e) => Ixed f (a,b,c,d,e) where+  ix = ixEach+  {-# INLINE ix #-}++type instance IxValue (a,a,a,a,a,a) = a+instance (Applicative f, a ~ b, b ~ c, c ~ d, d ~ e, e ~ f') => Ixed f (a,b,c,d,e,f') where+  ix = ixEach+  {-# INLINE ix #-}++type instance IxValue (a,a,a,a,a,a,a) = a+instance (Applicative f, a ~ b, b ~ c, c ~ d, d ~ e, e ~ f', f' ~ g) => Ixed f (a,b,c,d,e,f',g) where+  ix = ixEach+  {-# INLINE ix #-}++type instance IxValue (a,a,a,a,a,a,a,a) = a+instance (Applicative f, a ~ b, b ~ c, c ~ d, d ~ e, e ~ f', f' ~ g, g ~ h) => Ixed f (a,b,c,d,e,f',g,h) where+  ix = ixEach+  {-# INLINE ix #-}++type instance IxValue (a,a,a,a,a,a,a,a,a) = a+instance (Applicative f, a ~ b, b ~ c, c ~ d, d ~ e, e ~ f', f' ~ g, g ~ h, h ~ i) => Ixed f (a,b,c,d,e,f',g,h,i) where+  ix = ixEach+  {-# INLINE ix #-}++-- | 'At' provides a 'Lens' that can be used to read,+-- write or delete the value associated with a key in a 'Map'-like+-- container on an ad hoc basis.+--+-- An instance of 'At' should satisfy:+--+-- @+-- 'ix' k ≡ 'at' k '<.' 'traverse'+-- @+class At m where+  -- |+  -- >>> Map.fromList [(1,"world")] ^.at 1+  -- Just "world"+  --+  -- >>> at 1 ?~ "hello" $ Map.empty+  -- fromList [(1,"hello")]+  --+  -- /Note:/ 'Map'-like containers form a reasonable instance, but not 'Array'-like ones, where+  -- you cannot satisfy the 'Lens' laws.+  at :: Index m -> IndexedLens' (Index m) m (Maybe (IxValue m))++instance At (IntMap a) where+  at k f m = Lens.indexed f k mv <&> \r -> case r of+    Nothing -> maybe m (const (IntMap.delete k m)) mv+    Just v' -> IntMap.insert k v' m+    where mv = IntMap.lookup k m+  {-# INLINE at #-}++instance Ord k => At (Map k a) where+  at k f m = Lens.indexed f k mv <&> \r -> case r of+    Nothing -> maybe m (const (Map.delete k m)) mv+    Just v' -> Map.insert k v' m+    where mv = Map.lookup k m+  {-# INLINE at #-}++instance (Eq k, Hashable k) => At (HashMap k a) where+  at k f m = Lens.indexed f k mv <&> \r -> case r of+    Nothing -> maybe m (const (HashMap.delete k m)) mv+    Just v' -> HashMap.insert k v' m+    where mv = HashMap.lookup k m+  {-# INLINE at #-}
− src/Control/Lens/Classes.hs
@@ -1,192 +0,0 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE MagicHash #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE FunctionalDependencies #-}-{-# LANGUAGE UndecidableInstances #-}-#if defined(TRUSTWORTHY) && !defined(SAFE)-{-# LANGUAGE Trustworthy #-}-#endif--------------------------------------------------------------------------------- |--- Module      :  Control.Lens.Classes--- Copyright   :  (C) 2012 Edward Kmett--- License     :  BSD-style (see the file LICENSE)--- Maintainer  :  Edward Kmett <ekmett@gmail.com>--- Stability   :  provisional--- Portability :  Rank2Types---------------------------------------------------------------------------------module Control.Lens.Classes-  (-  -- * Getters-    Gettable(..)-  , noEffect-  -- * Actions-  , Effective(..)-  -- * Setters-  , Settable(..)-  -- * Isomorphisms-  , Isomorphic(..)-  -- * Prisms-  , Prismatic(..)-  -- * Indexable-  , Indexable(..)-  ) where--import Control.Applicative-import Control.Applicative.Backwards (Backwards(..))-import Control.Category-import Control.Monad (liftM)-import Data.Functor.Compose (Compose(..))-import Data.Functor.Identity (Identity(..))-import Data.Monoid (Dual(..))-import Prelude hiding ((.),id)-#ifndef SAFE-import Unsafe.Coerce (unsafeCoerce)-#endif--#ifndef SAFE-#define UNSAFELY(x) unsafeCoerce-#else-#define UNSAFELY(f) (\g -> g `seq` \x -> (f) (g x))-#endif------------------------------------------------------------------------------------- Gettables & Accessors------------------------------------------------------------------------------------ | Generalizing 'Const' so we can apply simple 'Applicative'--- transformations to it and so we can get nicer error messages------ A 'Gettable' 'Functor' ignores its argument, which it carries solely as a--- phantom type parameter.------ To ensure this, an instance of 'Gettable' is required to satisfy:------ @'id' = 'fmap' f = 'coerce'@------ Which is equivalent to making a @'Gettable' f@ an \"anyvariant\" functor.-----class Functor f => Gettable f where-  -- | Replace the phantom type argument.-  coerce :: f a -> f b--instance Gettable (Const r) where-  coerce (Const m) = Const m--instance Gettable f => Gettable (Backwards f) where-  coerce = Backwards . coerce . forwards--instance (Functor f, Gettable g) => Gettable (Compose f g) where-  coerce = Compose . fmap coerce . getCompose---- | The 'mempty' equivalent for a 'Gettable' 'Applicative' 'Functor'.-noEffect :: (Applicative f, Gettable f) => f a-noEffect = coerce $ pure ()-{-# INLINE noEffect #-}------------------------------------------------------------------------------------ Programming with Effects------------------------------------------------------------------------------------ | An 'Effective' 'Functor' ignores its argument and is isomorphic to a 'Monad' wrapped around a value.------ That said, the 'Monad' is possibly rather unrelated to any 'Applicative' structure.-class (Monad m, Gettable f) => Effective m r f | f -> m r where-  effective :: m r -> f a-  ineffective :: f a -> m r--instance Effective m r f => Effective m (Dual r) (Backwards f) where-  effective = Backwards . effective . liftM getDual-  ineffective = liftM Dual . ineffective . forwards---------------------------------------------------------------------------------- Settable---------------------------------------------------------------------------------- | Anything 'Settable' must be isomorphic to the 'Identity' 'Functor'.-class Applicative f => Settable f where-  untainted :: f a -> a--  untainted# :: (a -> f b) -> a -> b-  untainted# g = g `seq` \x -> untainted (g x)--  tainted# :: (a -> b) -> a -> f b-  tainted# g = g `seq` \x -> pure (g x)---- | so you can pass our a 'Control.Lens.Setter.Setter' into combinators from other lens libraries-instance Settable Identity where-  untainted = runIdentity-  untainted# = UNSAFELY(runIdentity)-  {-# INLINE untainted #-}-  tainted# = UNSAFELY(Identity)-  {-# INLINE tainted# #-}---- | 'Control.Lens.Fold.backwards'-instance Settable f => Settable (Backwards f) where-  untainted = untainted . forwards-  {-# INLINE untainted #-}--instance (Settable f, Settable g) => Settable (Compose f g) where-  untainted = untainted . untainted . getCompose-  {-# INLINE untainted #-}---------------------------------------------------------------------------------- Isomorphisms---------------------------------------------------------------------------------- | Used to provide overloading of isomorphism application------ An instance of 'Isomorphic' is a 'Category' with a canonical mapping to it from the--- category of isomorphisms over Haskell types.-class Category k => Isomorphic k where-  -- | Build a simple isomorphism from a pair of inverse functions-  ---  -- @-  -- 'Control.Lens.Getter.view' ('iso' f g) ≡ f-  -- 'Control.Lens.Getter.view' ('Control.Lens.Iso.from' ('iso' f g)) ≡ g-  -- 'Control.Lens.Setter.set' ('iso' f g) h ≡ g '.' h '.' f-  -- 'Control.Lens.Setter.set' ('Control.Lens.Iso.from' ('iso' f g)) h ≡ f '.' h '.' g-  -- @-  iso :: Functor f => (s -> a) -> (b -> t) -> k (a -> f b) (s -> f t)--instance Isomorphic (->) where-  iso sa bt afb s = bt <$> afb (sa s)-  {-# INLINE iso #-}---------------------------------------------------------------------------------- Prisms---------------------------------------------------------------------------------- | Used to provide overloading of prisms.------ An instance of 'Prismatic' is a 'Category' with a canonical mapping to it from the category--- of embedding-projection pairs over Haskell types.-class Isomorphic k => Prismatic k where-  -- | Build a 'Control.Lens.Prism.Prism'.-  ---  -- @'Either' t a@ is used instead of @'Maybe' a@ to permit the types of @s@ and @t@ to differ.-  prism :: Applicative f => (b -> t) -> (s -> Either t a) -> k (a -> f b) (s -> f t)--instance Prismatic (->) where-  prism bt seta afb = either pure (fmap bt . afb) . seta-  {-# INLINE prism #-}--------------------------------------------------------------------------------- Indexed Internals---------------------------------------------------------------------------------- | This class permits overloading of function application for things that--- also admit a notion of a key or index.-class Indexable i k where-  -- | Build a function from an 'Indexed' function-  indexed :: ((i -> a) -> b) -> k a b--instance Indexable i (->) where-  indexed f = f . const-  {-# INLINE indexed #-}
src/Control/Lens/Combinators.hs view
@@ -1,53 +1,66 @@--------------------------------------------------------------------------------+-------------------------------------------------------------------------------- -- | -- Module      :  Control.Lens.Combinators--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  provisional -- Portability :  portable --+-- These are general purpose combinators that provide utility for non-lens code ------------------------------------------------------------------------------- module Control.Lens.Combinators-  ( (<$!>), (<$!), (<&>), (??)+  ( (&)+  , (<&>)+  , (??)   ) where  import Data.Functor ((<$>))  -- $setup -- >>> import Control.Lens+-- >>> import Control.Monad.State+-- >>> import Debug.SimpleReflect.Expr+-- >>> import Debug.SimpleReflect.Vars as Vars hiding (f)+-- >>> let f :: Expr -> Expr; f = Debug.SimpleReflect.Vars.f -infixl 4 <$!>, <$!-infixl 1 <&>, ??+infixl 1 &, <&>, ?? --- | A strict version of ('Data.Functor.<$>') for monads.+-- | Passes the result of the left side to the function on the right side (forward pipe operator). ----- >>> (+1) <$!> [1,2,3,4]--- [2,3,4,5]-(<$!>) :: Monad m => (a -> b) -> m a -> m b-f <$!> m = do-  a <- m-  return $! f a-{-# INLINE (<$!>) #-}---- | A strict version of ('Data.Functor.<$') for monads.+-- This is the flipped version of ('$'), which is more common in languages like F# as (@|>@) where it is needed+-- for inference. Here it is supplied for notational convenience and given a precedence that allows it+-- to be nested inside uses of ('$'). ----- >>> () <$! [1,2,3,4]--- [(),(),(),()]-(<$!) :: Monad m => b -> m a -> m b-b <$! m = do-  _ <- m-  return $! b-{-# INLINE (<$!) #-}+-- >>> a & f+-- f a+--+-- >>> "hello" & length & succ+-- 6+--+-- This combinator is commonly used when applying multiple 'Control.Lens.Lens.Lens' operations in sequence.+--+-- >>> ("hello","world") & _1.element 0 .~ 'j' & _1.element 4 .~ 'y'+-- ("jelly","world")+--+-- This reads somewhat similar to:+--+-- >>> flip execState ("hello","world") $ do _1.element 0 .= 'j'; _1.element 4 .= 'y'+-- ("jelly","world")+(&) :: a -> (a -> b) -> b+a & f = f a+{-# INLINE (&) #-} --- | Infix flipped fmap.+-- | Infix flipped 'fmap'. ----- @('<&>') = 'flip' 'fmap'@+-- @+-- ('<&>') = 'flip' 'fmap'+-- @ (<&>) :: Functor f => f a -> (a -> b) -> f b as <&> f = f <$> as {-# INLINE (<&>) #-} --- | This is convenient to 'flip' argument order of composite functions+-- | This is convenient to 'flip' argument order of composite functions. -- -- >>> over _2 ?? ("hello","world") $ length -- ("hello",5)
+ src/Control/Lens/Cons.hs view
@@ -0,0 +1,444 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FunctionalDependencies #-}+#ifdef TRUSTWORTHY+{-# LANGUAGE Trustworthy #-}+#endif+-----------------------------------------------------------------------------+-- |+-- Module      :  Control.Lens.Cons+-- Copyright   :  (C) 2012-13 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  experimental+-- Portability :  non-portable+--+-----------------------------------------------------------------------------+module Control.Lens.Cons+  (+  -- * Cons+    Cons(..)+  , (<|)+  , cons+  , uncons+  , _head, _tail+  -- * Snoc+  , Snoc(..)+  , (|>)+  , snoc+  , unsnoc+  , _init, _last+  ) where++import Control.Applicative+import Control.Lens.Equality (simply)+import Control.Lens.Fold+import Control.Lens.Internal.Getter+import Control.Lens.Internal.Review+import Control.Lens.Prism+import Control.Lens.Review+import Control.Lens.Tuple+import Control.Lens.Type+import qualified Data.ByteString      as StrictB+import qualified Data.ByteString.Lazy as LazyB+import           Data.Functor.Identity+import           Data.Monoid+import           Data.Profunctor+import qualified Data.Sequence as Seq+import           Data.Sequence hiding ((<|), (|>))+import qualified Data.Text      as StrictT+import qualified Data.Text.Lazy as LazyT+import           Data.Vector (Vector)+import qualified Data.Vector as Vector+import           Data.Vector.Storable (Storable)+import qualified Data.Vector.Storable as Storable+import           Data.Vector.Primitive (Prim)+import qualified Data.Vector.Primitive as Prim+import           Data.Vector.Unboxed (Unbox)+import qualified Data.Vector.Unboxed as Unbox+import           Data.Word++-- $setup+-- >>> import Control.Lens+-- >>> import Debug.SimpleReflect.Expr+-- >>> import Debug.SimpleReflect.Vars as Vars hiding (f,g)+-- >>> let f :: Expr -> Expr; f = Debug.SimpleReflect.Vars.f+-- >>> let g :: Expr -> Expr; g = Debug.SimpleReflect.Vars.g++infixr 5 <|, `cons`+infixl 5 |>, `snoc`++------------------------------------------------------------------------------+-- Cons+------------------------------------------------------------------------------++-- | This class provides a way to attach or detach elements on the left+-- side of a structure in a flexible manner.+class (Profunctor p, Functor f) => Cons p f s t a b | s -> a, t -> b, s b -> t, t a -> s where+  -- | Most of the time this is a 'Prism'.+  --+  -- @+  -- '_Cons' :: 'Prism' [a] [b] (a, [a]) (b, [b])+  -- '_Cons' :: 'Prism' ('Seq' a) ('Seq' b) (a, 'Seq' a) (b, 'Seq' b)+  -- '_Cons' :: 'Prism' ('Vector' a) ('Vector' b) (a, 'Vector' a) (b, 'Vector' b)+  -- '_Cons' :: 'Prism'' 'String' ('Char', 'String')+  -- '_Cons' :: 'Prism'' 'StrictT.Text' ('Char', 'StrictT.Text')+  -- '_Cons' :: 'Prism'' 'StrictB.ByteString' ('Word8', 'StrictB.ByteString')+  -- @+  --+  -- However, by including @p@ and @f@ in the class you can write instances that only permit 'uncons'+  -- or which only permit 'cons', or where '_head' and '_tail' are lenses and not traversals.+  _Cons :: Overloaded p f s t (a,s) (b,t)++instance (Choice p, Applicative f) => Cons p f [a] [b] a b where+  _Cons = prism (uncurry (:)) $ \ aas -> case aas of+    (a:as) -> Right (a, as)+    []     -> Left  []+  {-# INLINE _Cons #-}++instance (Choice p, Applicative f) => Cons p f (Seq a) (Seq b) a b where+  _Cons = prism (uncurry (Seq.<|)) $ \aas -> case viewl aas of+    a :< as -> Right (a, as)+    EmptyL  -> Left mempty+  {-# INLINE _Cons #-}++instance (Choice p, Applicative f) => Cons p f StrictB.ByteString StrictB.ByteString Word8 Word8 where+  _Cons = prism' (uncurry StrictB.cons) StrictB.uncons++instance (Choice p, Applicative f) => Cons p f LazyB.ByteString LazyB.ByteString Word8 Word8 where+  _Cons = prism' (uncurry LazyB.cons) LazyB.uncons++instance (Choice p, Applicative f) => Cons p f StrictT.Text StrictT.Text Char Char where+  _Cons = prism' (uncurry StrictT.cons) StrictT.uncons++instance (Choice p, Applicative f) => Cons p f LazyT.Text LazyT.Text Char Char where+  _Cons = prism' (uncurry LazyT.cons) LazyT.uncons++instance (Choice p, Applicative f) => Cons p f (Vector a) (Vector b) a b where+  _Cons = prism (uncurry Vector.cons) $ \v ->+    if Vector.null v+    then Left Vector.empty+    else Right (Vector.unsafeHead v, Vector.unsafeTail v)+  {-# INLINE _Cons #-}++instance (Choice p, Applicative f, Prim a, Prim b) => Cons p f (Prim.Vector a) (Prim.Vector b) a b where+  _Cons = prism (uncurry Prim.cons) $ \v ->+    if Prim.null v+    then Left Prim.empty+    else Right (Prim.unsafeHead v, Prim.unsafeTail v)+  {-# INLINE _Cons #-}++instance (Choice p, Applicative f, Storable a, Storable b) => Cons p f (Storable.Vector a) (Storable.Vector b) a b where+  _Cons = prism (uncurry Storable.cons) $ \v ->+    if Storable.null v+    then Left Storable.empty+    else Right (Storable.unsafeHead v, Storable.unsafeTail v)+  {-# INLINE _Cons #-}++instance (Choice p, Applicative f, Unbox a, Unbox b) => Cons p f (Unbox.Vector a) (Unbox.Vector b) a b where+  _Cons = prism (uncurry Unbox.cons) $ \v ->+    if Unbox.null v+    then Left Unbox.empty+    else Right (Unbox.unsafeHead v, Unbox.unsafeTail v)+  {-# INLINE _Cons #-}++-- | 'cons' an element onto a container.+--+-- This is an infix alias for 'cons'.+(<|) :: Cons Reviewed Identity s s a a => a -> s -> s+(<|) = curry (simply review _Cons)+{-# INLINE (<|) #-}++-- | 'cons' an element onto a container.+cons :: Cons Reviewed Identity s s a a => a -> s -> s+cons = curry (simply review _Cons)++-- | Attempt to extract the left-most element from a container, and a version of the container without that element.+uncons :: Cons (->) (Accessor (First (a, s))) s s a a => s -> Maybe (a, s)+uncons = simply preview _Cons+{-# INLINE uncons #-}++-- | A 'Traversal' reading and writing to the 'head' of a /non-empty/ container.+--+-- >>> [a,b,c]^? _head+-- Just a+--+-- >>> [a,b,c] & _head .~ d+-- [d,b,c]+--+-- >>> [a,b,c] & _head %~ f+-- [f a,b,c]+--+-- >>> [] & _head %~ f+-- []+--+-- >>> [1,2,3]^?!_head+-- 1+--+-- >>> []^?_head+-- Nothing+--+-- >>> [1,2]^?_head+-- Just 1+--+-- >>> [] & _head .~ 1+-- []+--+-- >>> [0] & _head .~ 2+-- [2]+--+-- >>> [0,1] & _head .~ 2+-- [2,1]+--+-- This isn't limited to lists.+--+-- For instance you can also 'Data.Traversable.traverse' the head of a 'Seq':+--+-- >>> Seq.fromList [a,b,c,d] & _head %~ f+-- fromList [f a,b,c,d]+--+-- >>> Seq.fromList [] ^? _head+-- Nothing+--+-- >>> Seq.fromList [a,b,c,d] ^? _head+-- Just a+--+-- @+-- '_head' :: 'Traversal'' [a] a+-- '_head' :: 'Traversal'' ('Seq' a) a+-- '_head' :: 'Traversal'' ('Vector' a) a+-- @+_head :: Cons (->) f s s a a => LensLike' f s a+_head = _Cons._1+{-# INLINE _head #-}++-- | A 'Traversal' reading and writing to the 'tail' of a /non-empty/ container.+--+-- >>> [a,b] & _tail .~ [c,d,e]+-- [a,c,d,e]+--+-- >>> [] & _tail .~ [a,b]+-- []+--+-- >>> [a,b,c,d,e] & _tail.traverse %~ f+-- [a,f b,f c,f d,f e]+--+-- >>> [1,2] & _tail .~ [3,4,5]+-- [1,3,4,5]+--+-- >>> [] & _tail .~ [1,2]+-- []+--+-- >>> [a,b,c]^?_tail+-- Just [b,c]+--+-- >>> [1,2]^?!_tail+-- [2]+--+-- >>> "hello"^._tail+-- "ello"+--+-- >>> ""^._tail+-- ""+--+-- This isn't limited to lists. For instance you can also 'Control.Traversable.traverse' the tail of a 'Seq'.+--+-- >>> Seq.fromList [a,b] & _tail .~ Seq.fromList [c,d,e]+-- fromList [a,c,d,e]+--+-- >>> Seq.fromList [a,b,c] ^? _tail+-- Just (fromList [b,c])+--+-- >>> Seq.fromList [] ^? _tail+-- Nothing+--+-- @+-- '_tail' :: 'Traversal'' [a] [a]+-- '_tail' :: 'Traversal'' ('Seq' a) ('Seq' a)+-- '_tail' :: 'Traversal'' ('Vector' a) ('Vector' a)+-- @+_tail :: Cons (->) f s s a a => LensLike' f s s+_tail = _Cons._2+{-# INLINE _tail #-}++------------------------------------------------------------------------------+-- Snoc+------------------------------------------------------------------------------++-- | This class provides a way to attach or detach elements on the right+-- side of a structure in a flexible manner.+class (Profunctor p, Functor f) => Snoc p f s t a b | s -> a, t -> b, s b -> t, t a -> s where+  -- | Most of the time this is a 'Prism'.+  --+  -- @+  -- '_Snoc' :: 'Prism' [a] [b] (a, [a]) (b, [b])+  -- '_Snoc' :: 'Prism' ('Seq' a) ('Seq' b) ('Seq' a, a) ('Seq' b, b)+  -- '_Snoc' :: 'Prism' ('Vector' a) ('Vector' b) ('Vector' a, a) ('Vector' b, b)+  -- '_Snoc' :: 'Prism'' 'String' ('String', 'Char')+  -- '_Snoc' :: 'Prism'' 'StrictT.Text' ('StrictT.Text', 'Char')+  -- '_Snoc' :: 'Prism'' 'StrictB.ByteString' ('StrictB.ByteString', 'Word8')+  -- @+  --+  -- However, by including @p@ and @f@ in the class you can write instances that only permit 'unsnoc'+  -- or which only permit 'snoc' or where '_init' and '_last' are lenses and not traversals.+  _Snoc :: Overloaded p f s t (s,a) (t,b)++instance (Choice p, Applicative f) => Snoc p f [a] [b] a b where+  _Snoc = prism (\(as,a) -> as Prelude.++ [a]) $ \aas -> if Prelude.null aas+    then Left []+    else Right (Prelude.init aas, Prelude.last aas)+  {-# INLINE _Snoc #-}++instance (Choice p, Applicative f) => Snoc p f (Seq a) (Seq b) a b where+  _Snoc = prism (uncurry (Seq.|>)) $ \aas -> case viewr aas of+    as :> a -> Right (as, a)+    EmptyR  -> Left mempty+  {-# INLINE _Snoc #-}++instance (Choice p, Applicative f) => Snoc p f (Vector a) (Vector b) a b where+  _Snoc = prism (uncurry Vector.snoc) $ \v -> if Vector.null v+    then Left Vector.empty+    else Right (Vector.unsafeInit v, Vector.unsafeLast v)+  {-# INLINE _Snoc #-}++instance (Choice p, Applicative f, Prim a, Prim b) => Snoc p f (Prim.Vector a) (Prim.Vector b) a b where+  _Snoc = prism (uncurry Prim.snoc) $ \v -> if Prim.null v+    then Left Prim.empty+    else Right (Prim.unsafeInit v, Prim.unsafeLast v)+  {-# INLINE _Snoc #-}++instance (Choice p, Applicative f, Storable a, Storable b) => Snoc p f (Storable.Vector a) (Storable.Vector b) a b where+  _Snoc = prism (uncurry Storable.snoc) $ \v -> if Storable.null v+    then Left Storable.empty+    else Right (Storable.unsafeInit v, Storable.unsafeLast v)+  {-# INLINE _Snoc #-}++instance (Choice p, Applicative f, Unbox a, Unbox b) => Snoc p f (Unbox.Vector a) (Unbox.Vector b) a b where+  _Snoc = prism (uncurry Unbox.snoc) $ \v -> if Unbox.null v+    then Left Unbox.empty+    else Right (Unbox.unsafeInit v, Unbox.unsafeLast v)+  {-# INLINE _Snoc #-}++instance (Choice p, Applicative f) => Snoc p f StrictB.ByteString StrictB.ByteString Word8 Word8 where+  _Snoc = prism (uncurry StrictB.snoc) $ \v -> if StrictB.null v+    then Left StrictB.empty+    else Right (StrictB.init v, StrictB.last v)+  {-# INLINE _Snoc #-}++instance (Choice p, Applicative f) => Snoc p f LazyB.ByteString LazyB.ByteString Word8 Word8 where+  _Snoc = prism (uncurry LazyB.snoc) $ \v -> if LazyB.null v+    then Left LazyB.empty+    else Right (LazyB.init v, LazyB.last v)+  {-# INLINE _Snoc #-}++instance (Choice p, Applicative f) => Snoc p f StrictT.Text StrictT.Text Char Char where+  _Snoc = prism (uncurry StrictT.snoc) $ \v -> if StrictT.null v+    then Left StrictT.empty+    else Right (StrictT.init v, StrictT.last v)+  {-# INLINE _Snoc #-}++instance (Choice p, Applicative f) => Snoc p f LazyT.Text LazyT.Text Char Char where+  _Snoc = prism (uncurry LazyT.snoc) $ \v -> if LazyT.null v+    then Left LazyT.empty+    else Right (LazyT.init v, LazyT.last v)+  {-# INLINE _Snoc #-}++-- | A 'Traversal' reading and replacing all but the a last element of a /non-empty/ container.+--+-- >>> [a,b,c,d]^?_init+-- Just [a,b,c]+--+-- >>> []^?_init+-- Nothing+--+-- >>> [a,b] & _init .~ [c,d,e]+-- [c,d,e,b]+--+-- >>> [] & _init .~ [a,b]+-- []+--+-- >>> [a,b,c,d] & _init.traverse %~ f+-- [f a,f b,f c,d]+--+-- >>> [1,2,3]^?_init+-- Just [1,2]+--+-- >>> [1,2,3,4]^?!_init+-- [1,2,3]+--+-- >>> "hello"^._init+-- "hell"+--+-- >>> ""^._init+-- ""+--+-- @+-- '_init' :: 'Traversal'' [a] a+-- '_init' :: 'Traversal'' ('Seq' a) a+-- '_init' :: 'Traversal'' ('Vector' a) a+-- @+_init :: Snoc (->) f s s a a => LensLike' f s s+_init = _Snoc._1+{-# INLINE _init #-}++-- | A 'Traversal' reading and writing to the last element of a /non-empty/ container.+--+-- >>> [a,b,c]^?!_last+-- c+--+-- >>> []^?_last+-- Nothing+--+-- >>> [a,b,c] & _last %~ f+-- [a,b,f c]+--+-- >>> [1,2]^?_last+-- Just 2+--+-- >>> [] & _last .~ 1+-- []+--+-- >>> [0] & _last .~ 2+-- [2]+--+-- >>> [0,1] & _last .~ 2+-- [0,2]+--+-- This 'Traversal' is not limited to lists, however. We can also work with other containers, such as a 'Vector'.+--+-- >>> Vector.fromList "abcde" ^? _last+-- Just 'e'+--+-- >>> Vector.empty ^? _last+-- Nothing+--+-- >>> Vector.fromList "abcde" & _last .~ 'Q'+-- fromList "abcdQ"+--+-- @+-- '_last' :: 'Traversal'' [a] [a]+-- '_last' :: 'Traversal'' ('Seq' a) ('Seq' a)+-- '_last' :: 'Traversal'' ('Vector' a) ('Vector' a)+-- @+_last :: Snoc (->) f s s a a => LensLike' f s a+_last = _Snoc._2+{-# INLINE _last #-}++-- | 'snoc' an element onto the end of a container.+--+-- This is an infix alias for 'snoc'.+(|>) :: Snoc Reviewed Identity s s a a => s -> a -> s+(|>) = curry (simply review _Snoc)+{-# INLINE (|>) #-}++-- | 'snoc' an element onto the end of a container.+snoc  :: Snoc Reviewed Identity s s a a => s -> a -> s+snoc = curry (simply review _Snoc)+{-# INLINE snoc #-}++-- | Attempt to extract the right-most element from a container, and a version of the container without that element.+unsnoc :: Snoc (->) (Accessor (First (s, a))) s s a a => s -> Maybe (s, a)+unsnoc s = simply preview _Snoc s+{-# INLINE unsnoc #-}
src/Control/Lens/Each.hs view
@@ -1,6 +1,8 @@ {-# LANGUAGE CPP #-}+{-# LANGUAGE GADTs #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE DefaultSignatures #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE UndecidableInstances #-}@@ -16,7 +18,7 @@ ----------------------------------------------------------------------------- -- | -- Module      :  Control.Lens.Each--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  experimental@@ -24,35 +26,83 @@ -- ----------------------------------------------------------------------------- module Control.Lens.Each-  ( Each(..)+  (+  -- * Indices+    Index+  -- * Each+  , Each(..)   ) where  import Control.Applicative+import Control.Lens.Cons as Lens+import Control.Lens.Internal.Deque+import Control.Lens.Internal.Setter import Control.Lens.Indexed as Lens-import Control.Lens.IndexedTraversal-import Control.Lens.Traversal import Control.Lens.Iso+import Control.Lens.Type+import Control.Lens.Traversal+import Data.Array.Unboxed as Unboxed+import Data.Array.IArray as IArray import Data.ByteString as StrictB import Data.ByteString.Lazy as LazyB import Data.Complex+import Data.Foldable as Foldable import Data.Functor.Identity+import Data.HashMap.Lazy as HashMap+import Data.HashSet import Data.Int+import Data.IntMap as IntMap+import Data.IntSet+import Data.Map as Map+import Data.Set import Data.Sequence as Seq import Data.Text as StrictT import Data.Text.Lazy as LazyT import Data.Traversable import Data.Tree as Tree+import qualified Data.Vector as Vector+import qualified Data.Vector.Primitive as Prim+import Data.Vector.Primitive (Prim)+import qualified Data.Vector.Storable as Storable+import Data.Vector.Storable (Storable)+import qualified Data.Vector.Unboxed as Unboxed+import Data.Vector.Unboxed (Unbox) import Data.Word-import Data.Map as Map-import Data.IntMap as IntMap-import Data.HashMap.Lazy as HashMap-import Data.Vector as Vector-import Data.Vector.Primitive as Prim-import Data.Vector.Storable as Storable-import Data.Vector.Unboxed as Unboxed-import Data.Array.Unboxed as Unboxed-import Data.Array.IArray as IArray +-- | This is a common 'Index' type shared by 'Each', 'Control.Lens.At.At', 'Control.Lens.At.Contains' and 'Control.Lens.At.Ixed'.+type family Index (s :: *) :: *+type instance Index (e -> a) = e+type instance Index IntSet = Int+type instance Index (Set a) = a+type instance Index (HashSet a) = a+type instance Index [a] = Int+type instance Index (Seq a) = Int+type instance Index (a,b) = Int+type instance Index (a,b,c) = Int+type instance Index (a,b,c,d) = Int+type instance Index (a,b,c,d,e) = Int+type instance Index (a,b,c,d,e,f) = Int+type instance Index (a,b,c,d,e,f,g) = Int+type instance Index (a,b,c,d,e,f,g,h) = Int+type instance Index (a,b,c,d,e,f,g,h,i) = Int+type instance Index (IntMap a) = Int+type instance Index (Map k a) = k+type instance Index (HashMap k a) = k+type instance Index (Array i e) = i+type instance Index (UArray i e) = i+type instance Index (Vector.Vector a) = Int+type instance Index (Prim.Vector a) = Int+type instance Index (Storable.Vector a) = Int+type instance Index (Unboxed.Vector a) = Int+type instance Index (Complex a) = Int+type instance Index (Identity a) = ()+type instance Index (Maybe a) = ()+type instance Index (Tree a) = [Int]+type instance Index StrictT.Text = Int+type instance Index LazyT.Text = Int64+type instance Index StrictB.ByteString = Int+type instance Index LazyB.ByteString = Int64+ -- $setup -- >>> import Control.Lens -- >>> import Data.Text.Strict.Lens as Text@@ -65,134 +115,186 @@ -- >>> (1,2,3) & each *~ 10 -- (10,20,30) ----- It can also be used on monomorphic containers like 'StrictT.Text' or 'StrictB.ByteString'+-- It can also be used on monomorphic containers like 'StrictT.Text' or 'StrictB.ByteString'. -- -- >>> over each Char.toUpper ("hello"^.Text.packed) -- "HELLO" ----- 'each' is an indexed traversal, so it can be used to access keys in many containers:+-- 'each' is an 'IndexedTraversal', so it can be used to access keys in many containers: -- -- >>> itoListOf each $ Map.fromList [("hello",2),("world",4)] -- [("hello",2),("world",4)] -- -- >>> ("hello","world") & each.each %~ Char.toUpper -- ("HELLO","WORLD")-class Each i s t a b | s -> i a, t -> i b, s b -> t, t a -> s where-  each :: IndexedTraversal i s t a b-+class (Functor f, Index s ~ Index t) => Each f s t a b | s -> a, t -> b, s b -> t, t a -> s where+  each :: IndexedLensLike (Index s) f s t a b #ifdef DEFAULT_SIGNATURES-  default each :: (Traversable f, s ~ f a, t ~ f b) => IndexedTraversal Int s t a b+  default each :: (Applicative f, Traversable g, s ~ g a, t ~ g b, Index s ~ Int, Index t ~ Int) => IndexedLensLike Int f s t a b   each = traversed   {-# INLINE each #-} #endif -instance (a ~ a', b ~ b') => Each Int (a,a') (b,b') a b where-  each = Lens.indexed $ \ f ~(a,b) -> (,) <$> f (0 :: Int) a <*> f 1 b+-- | @'each' :: 'IndexedTraversal' 'Int' (a,a) (b,b) a b@+instance (Applicative f, a~a', b~b') => Each f (a,a') (b,b') a b where+  each f ~(a,b) = (,) <$> f' (0 :: Int) a <*> f' 1 b+    where f' = Lens.indexed f   {-# INLINE each #-} -instance (a ~ a2, a ~ a3, b ~ b2, b ~ b3) => Each Int (a,a2,a3) (b,b2,b3) a b where-  each = Lens.indexed $ \ f ~(a,b,c) -> (,,) <$> f (0 :: Int) a <*> f 1 b <*> f 2 c+-- | @'each' :: 'IndexedTraversal' 'Int' (a,a,a) (b,b,b) a b@+instance (Applicative f, a~a2, a~a3, b~b2, b~b3) => Each f (a,a2,a3) (b,b2,b3) a b where+  each f ~(a,b,c) = (,,) <$> f' (0 :: Int) a <*> f' 1 b <*> f' 2 c+    where f' = Lens.indexed f   {-# INLINE each #-} -instance (a ~ a2, a ~ a3, a ~ a4, b ~ b2, b ~ b3, b ~ b4) => Each Int (a,a2,a3,a4) (b,b2,b3,b4) a b where-  each = Lens.indexed $ \ f ~(a,b,c,d) -> (,,,) <$> f (0 :: Int) a <*> f 1 b <*> f 2 c <*> f 3 d+-- | @'each' :: 'IndexedTraversal' 'Int' (a,a,a,a) (b,b,b,b) a b@+instance (Applicative f, a~a2, a~a3, a~a4, b~b2, b~b3, b~b4) => Each f (a,a2,a3,a4) (b,b2,b3,b4) a b where+  each f ~(a,b,c,d) = (,,,) <$> f' (0 :: Int) a <*> f' 1 b <*> f' 2 c <*> f' 3 d+    where f' = Lens.indexed f   {-# INLINE each #-} -instance (a ~ a2, a ~ a3, a ~ a4, a ~ a5, b ~ b2, b ~ b3, b ~ b4, b ~ b5) => Each Int (a,a2,a3,a4,a5) (b,b2,b3,b4,b5) a b where-  each = Lens.indexed $ \ f ~(a,b,c,d,e) -> (,,,,) <$> f (0 :: Int) a <*> f 1 b <*> f 2 c <*> f 3 d <*> f 4 e+-- | @'each' :: 'IndexedTraversal' 'Int' (a,a,a,a,a) (b,b,b,b,b) a b@+instance (Applicative f, a~a2, a~a3, a~a4, a~a5, b~b2, b~b3, b~b4, b~b5) => Each f (a,a2,a3,a4,a5) (b,b2,b3,b4,b5) a b where+  each f ~(a,b,c,d,e) = (,,,,) <$> f' (0 :: Int) a <*> f' 1 b <*> f' 2 c <*> f' 3 d <*> f' 4 e+    where f' = Lens.indexed f   {-# INLINE each #-} -instance (a ~ a2, a ~ a3, a ~ a4, a ~ a5, a ~ a6, b ~ b2, b ~ b3, b ~ b4, b ~ b5, b ~ b6) => Each Int (a,a2,a3,a4,a5,a6) (b,b2,b3,b4,b5,b6) a b where-  each = Lens.indexed $ \ f ~(a,b,c,d,e,g) -> (,,,,,) <$> f (0 :: Int) a <*> f 1 b <*> f 2 c <*> f 3 d <*> f 4 e <*> f 5 g+-- | @'each' :: 'IndexedTraversal' 'Int' (a,a,a,a,a,a) (b,b,b,b,b,b) a b@+instance (Applicative f, a~a2, a~a3, a~a4, a~a5, a~a6, b~b2, b~b3, b~b4, b~b5, b~b6) => Each f (a,a2,a3,a4,a5,a6) (b,b2,b3,b4,b5,b6) a b where+  each f ~(a,b,c,d,e,g) = (,,,,,) <$> f' (0 :: Int) a <*> f' 1 b <*> f' 2 c <*> f' 3 d <*> f' 4 e <*> f' 5 g+    where f' = Lens.indexed f   {-# INLINE each #-} -instance (a ~ a2, a ~ a3, a ~ a4, a ~ a5, a ~ a6, a ~ a7, b ~ b2, b ~ b3, b ~ b4, b ~ b5, b ~ b6, b ~ b7) => Each Int (a,a2,a3,a4,a5,a6,a7) (b,b2,b3,b4,b5,b6,b7) a b where-  each = Lens.indexed $ \ f ~(a,b,c,d,e,g,h) -> (,,,,,,) <$> f (0 :: Int) a <*> f 1 b <*> f 2 c <*> f 3 d <*> f 4 e <*> f 5 g <*> f 6 h+-- | @'each' :: 'IndexedTraversal' 'Int' (a,a,a,a,a,a,a) (b,b,b,b,b,b,b) a b@+instance (Applicative f, a~a2, a~a3, a~a4, a~a5, a~a6, a~a7, b~b2, b~b3, b~b4, b~b5, b~b6, b~b7) => Each f (a,a2,a3,a4,a5,a6,a7) (b,b2,b3,b4,b5,b6,b7) a b where+  each f ~(a,b,c,d,e,g,h) = (,,,,,,) <$> f' (0 :: Int) a <*> f' 1 b <*> f' 2 c <*> f' 3 d <*> f' 4 e <*> f' 5 g <*> f' 6 h+    where f' = Lens.indexed f   {-# INLINE each #-} -instance (a ~ a2, a ~ a3, a ~ a4, a ~ a5, a ~ a6, a ~ a7, a ~ a8, b ~ b2, b ~ b3, b ~ b4, b ~ b5, b ~ b6, b ~ b7, b ~ b8) => Each Int (a,a2,a3,a4,a5,a6,a7,a8) (b,b2,b3,b4,b5,b6,b7,b8) a b where-  each = Lens.indexed $ \ f ~(a,b,c,d,e,g,h,i) -> (,,,,,,,) <$> f (0 :: Int) a <*> f 1 b <*> f 2 c <*> f 3 d <*> f 4 e <*> f 5 g <*> f 6 h <*> f 7 i+-- | @'each' :: 'IndexedTraversal' 'Int' (a,a,a,a,a,a,a,a) (b,b,b,b,b,b,b,b) a b@+instance (Applicative f, a~a2, a~a3, a~a4, a~a5, a~a6, a~a7, a~a8, b~b2, b~b3, b~b4, b~b5, b~b6, b~b7, b~b8) => Each f (a,a2,a3,a4,a5,a6,a7,a8) (b,b2,b3,b4,b5,b6,b7,b8) a b where+  each f ~(a,b,c,d,e,g,h,i) = (,,,,,,,) <$> f' (0 :: Int) a <*> f' 1 b <*> f' 2 c <*> f' 3 d <*> f' 4 e <*> f' 5 g <*> f' 6 h <*> f' 7 i+    where f' = Lens.indexed f   {-# INLINE each #-} -instance (a ~ a2, a ~ a3, a ~ a4, a ~ a5, a ~ a6, a ~ a7, a ~ a8, a ~ a9, b ~ b2, b ~ b3, b ~ b4, b ~ b5, b ~ b6, b ~ b7, b ~ b8, b ~ b9) => Each Int (a,a2,a3,a4,a5,a6,a7,a8,a9) (b,b2,b3,b4,b5,b6,b7,b8,b9) a b where-  each = Lens.indexed $ \ f ~(a,b,c,d,e,g,h,i,j) -> (,,,,,,,,) <$> f (0 :: Int) a <*> f 1 b <*> f 2 c <*> f 3 d <*> f 4 e <*> f 5 g <*> f 6 h <*> f 7 i <*> f 8 j+-- | @'each' :: 'IndexedTraversal' 'Int' (a,a,a,a,a,a,a,a,a) (b,b,b,b,b,b,b,b,b) a b@+instance (Applicative f, a~a2, a~a3, a~a4, a~a5, a~a6, a~a7, a~a8, a~a9, b~b2, b~b3, b~b4, b~b5, b~b6, b~b7, b~b8, b~b9) => Each f (a,a2,a3,a4,a5,a6,a7,a8,a9) (b,b2,b3,b4,b5,b6,b7,b8,b9) a b where+  each f ~(a,b,c,d,e,g,h,i,j) = (,,,,,,,,) <$> f' (0 :: Int) a <*> f' 1 b <*> f' 2 c <*> f' 3 d <*> f' 4 e <*> f' 5 g <*> f' 6 h <*> f' 7 i <*> f' 8 j+    where f' = Lens.indexed f   {-# INLINE each #-} -#if !(MIN_VERSION_base(4,4,0))-instance (RealFloat a, RealFloat b) => Each Int (Complex a) (Complex b) a b where-  each = Lens.indexed $ \ f (a :+ b) -> (:+) <$> f (0 :: Int) a <*> f 1 b+#if MIN_VERSION_base(4,4,0)+-- | @'each' :: ('RealFloat' a, 'RealFloat' b) => 'IndexedTraversal' 'Int' ('Complex' a) ('Complex' b) a b@+instance Applicative f => Each f (Complex a) (Complex b) a b where+  each f (a :+ b) = (:+) <$> f' (0 :: Int) a <*> f' (1 :: Int) b+    where f' = Lens.indexed f   {-# INLINE each #-} #else-instance Each Int (Complex a) (Complex b) a b where-  each = Lens.indexed $ \ f (a :+ b) -> (:+) <$> f (0 :: Int) a <*> f 1 b+-- | @'each' :: 'IndexedTraversal' 'Int' ('Complex' a) ('Complex' b) a b@+instance (Applicative f, RealFloat a, RealFloat b) => Each f (Complex a) (Complex b) a b where+  each f (a :+ b) = (:+) <$> f' (0 :: Int) a <*> f' 1 b+    where f' = Lens.indexed f   {-# INLINE each #-} #endif -instance Each k (Map k a) (Map k b) a b where-  each = Lens.indexed $ \f m -> sequenceA $ Map.mapWithKey f m+-- | @'each' :: 'IndexedTraversal' c ('Map' c a) ('Map' c b) a b@+instance Applicative f => Each f (Map c a) (Map c b) a b where+  each f m = sequenceA $ Map.mapWithKey f' m+    where f' = Lens.indexed f   {-# INLINE each #-} -instance Each Int (IntMap a) (IntMap b) a b where-  each = Lens.indexed $ \f m -> sequenceA $ IntMap.mapWithKey f m+-- | @'each' :: 'IndexedTraversal' 'Int' ('Map' c a) ('Map' c b) a b@+instance Applicative f => Each f (IntMap a) (IntMap b) a b where+  each f m = sequenceA $ IntMap.mapWithKey f' m+    where f' = Lens.indexed f   {-# INLINE each #-} -instance Each k (HashMap k a) (HashMap k b) a b where-  each = Lens.indexed HashMap.traverseWithKey+-- | @'each' :: 'IndexedTraversal' c ('HashMap' c a) ('HashMap' c b) a b@+instance Applicative f => Each f (HashMap c a) (HashMap c b) a b where+  each = HashMap.traverseWithKey . Lens.indexed   {-# INLINE each #-} -instance Each Int [a] [b] a b where+-- | @'each' :: 'IndexedTraversal' 'Int' [a] [b] a b@+instance Applicative f => Each f [a] [b] a b where   each = traversed   {-# INLINE each #-} -instance Each Int (Identity a) (Identity b) a b where-  each = traversed+-- | @'each' :: 'IndexedTraversal' 'Int' ('Identity' a) ('Identity' b) a b@+instance Functor f => Each f (Identity a) (Identity b) a b where+  each f (Identity a) = Identity <$> Lens.indexed f () a   {-# INLINE each #-} -instance Each Int (Maybe a) (Maybe b) a b where-  each = traversed+-- | @'each' :: 'IndexedTraversal' 'Int' ('Maybe' a) ('Maybe' b) a b@+instance Applicative f => Each f (Maybe a) (Maybe b) a b where+  each f (Just a) = Just <$> Lens.indexed f () a+  each _ Nothing  = pure Nothing   {-# INLINE each #-} -instance Each Int (Seq a) (Seq b) a b where+-- | @'each' :: 'IndexedTraversal' 'Int' ('Seq' a) ('Seq' b) a b@+instance Applicative f => Each f (Seq a) (Seq b) a b where   each = traversed   {-# INLINE each #-} -instance Each Int (Tree a) (Tree b) a b where-  each = traversed+-- | @'each' :: 'IndexedTraversal' ['Int'] ('Tree' a) ('Tree' b) a b@+instance Applicative f => Each f (Tree a) (Tree b) a b where+  each pafb = go (BD 0 [] 0 []) where+    go dq (Node a as) = Node <$> Lens.indexed pafb (Foldable.toList dq) a <*> itraverse (\i n -> go (Lens.snoc dq i) n) as   {-# INLINE each #-} -instance Each Int (Vector.Vector a) (Vector.Vector b) a b where+-- | @'each' :: 'IndexedTraversal' 'Int' ('Vector.Vector' a) ('Vector.Vector' b) a b@+instance Applicative f => Each f (Vector.Vector a) (Vector.Vector b) a b where   each = traversed   {-# INLINE each #-} -instance (Prim a, Prim b) => Each Int (Prim.Vector a) (Prim.Vector b) a b where-  each = Lens.indexed $ \f v -> Prim.fromListN (Prim.length v) <$> withIndex traversed f (Prim.toList v)+-- | @'each' :: ('Prim' a, 'Prim' b) => 'IndexedTraversal' 'Int' ('Prim.Vector' a) ('Prim.Vector' b) a b@+instance (Applicative f, Prim a, Prim b) => Each f (Prim.Vector a) (Prim.Vector b) a b where+  each f v = Prim.fromListN (Prim.length v) <$> traversed (Indexed f') (Prim.toList v)+    where f' = Lens.indexed f+  {-# INLINE each #-} -instance (Storable a, Storable b) => Each Int (Storable.Vector a) (Storable.Vector b) a b where-  each = Lens.indexed $ \f v -> Storable.fromListN (Storable.length v) <$> withIndex traversed f (Storable.toList v)+-- | @'each' :: ('Storable' a, 'Storable' b) => 'IndexedTraversal' 'Int' ('Storable.Vector' a) ('Storable.Vector' b) a b@+instance (Applicative f, Storable a, Storable b) => Each f (Storable.Vector a) (Storable.Vector b) a b where+  each f v = Storable.fromListN (Storable.length v) <$> traversed (Indexed f') (Storable.toList v)+    where f' = Lens.indexed f+  {-# INLINE each #-} -instance (Unbox a, Unbox b) => Each Int (Unboxed.Vector a) (Unboxed.Vector b) a b where-  each = Lens.indexed $ \f v -> Unboxed.fromListN (Unboxed.length v) <$> withIndex traversed f (Unboxed.toList v)+-- | @'each' :: ('Unbox' a, 'Unbox' b) => 'IndexedTraversal' 'Int' ('Unboxed.Vector' a) ('Unboxed.Vector' b) a b@+instance (Applicative f, Unbox a, Unbox b) => Each f (Unboxed.Vector a) (Unboxed.Vector b) a b where+  each f v = Unboxed.fromListN (Unboxed.length v) <$> traversed (Indexed f') (Unboxed.toList v)+    where f' = Lens.indexed f+  {-# INLINE each #-} -instance Each Int StrictT.Text StrictT.Text Char Char where-  each = iso StrictT.unpack StrictT.pack .> traversed+-- | @'each' :: 'IndexedTraversal' 'Int' 'StrictT.Text' 'StrictT.Text' 'Char' 'Char'@+instance Applicative f =>  Each f StrictT.Text StrictT.Text Char Char where+  each = iso StrictT.unpack StrictT.pack . traversed   {-# INLINE each #-} -instance Each Int64 LazyT.Text LazyT.Text Char Char where-  each = iso LazyT.unpack LazyT.pack .> traversed64+-- | @'each' :: 'IndexedTraversal' 'Int64' 'LazyT.Text' 'LazyT.Text' 'Char' 'Char'@+instance Applicative f => Each f LazyT.Text LazyT.Text Char Char where+  each = iso LazyT.unpack LazyT.pack . traversed64   {-# INLINE each #-} -instance Each Int StrictB.ByteString StrictB.ByteString Word8 Word8 where-  each = iso StrictB.unpack StrictB.pack .> traversed+-- | @'each' :: 'IndexedTraversal' 'Int' 'StrictB.ByteString' 'StrictB.ByteString' 'Char' 'Char'@+instance Applicative f => Each f StrictB.ByteString StrictB.ByteString Word8 Word8 where+  each = iso StrictB.unpack StrictB.pack . traversed   {-# INLINE each #-} -instance Each Int64 LazyB.ByteString LazyB.ByteString Word8 Word8 where-  each = iso LazyB.unpack LazyB.pack .> traversed64+-- | @'each' :: 'IndexedTraversal' 'Int64' 'LazyB.ByteString' 'LazyB.ByteString' 'Char' 'Char'@+instance Applicative f => Each f LazyB.ByteString LazyB.ByteString Word8 Word8 where+  each = iso LazyB.unpack LazyB.pack . traversed64   {-# INLINE each #-} -instance (Ix i, IArray UArray a, IArray UArray b) => Each i (Array i a) (Array i b) a b where-  each = Lens.indexed $ \f arr -> array (bounds arr) <$> traverse (\(i,a) -> (,) i <$> f i a) (IArray.assocs arr)+-- | @'each' :: 'Ix' i => 'IndexedTraversal' i ('Array' i a) ('Array' i b) a b@+instance (Applicative f, Ix i) => Each f (Array i a) (Array i b) a b where+  each f arr = array (bounds arr) <$> traverse (\(i,a) -> (,) i <$> Lens.indexed f i a) (IArray.assocs arr)   {-# INLINE each #-} -instance (Ix i, IArray UArray a, IArray UArray b) => Each i (UArray i a) (UArray i b) a b where-  each = Lens.indexed $ \f arr -> array (bounds arr) <$> traverse (\(i,a) -> (,) i <$> f i a) (IArray.assocs arr)+-- | @'each' :: ('Ix' i, 'IArray' 'UArray' a, 'IArray' 'UArray' b) => 'IndexedTraversal' i ('Array' i a) ('Array' i b) a b@+instance (Applicative f, Ix i, IArray UArray a, IArray UArray b) => Each f (UArray i a) (UArray i b) a b where+  each f arr = array (bounds arr) <$> traverse (\(i,a) -> (,) i <$> Lens.indexed f i a) (IArray.assocs arr)+  {-# INLINE each #-}++-- | @'each' :: 'Control.Lens.IndexedSetter.IndexedSetter' i (i -> a) (i -> b) a b@+instance Settable f => Each f (i -> a) (i -> b) a b where+  each f g = pure (\i -> untaintedDot (Lens.indexed f i) (g i))   {-# INLINE each #-}
+ src/Control/Lens/Equality.hs view
@@ -0,0 +1,76 @@+{-# LANGUAGE GADTs #-}+{-# LANGUAGE Rank2Types #-}+{-# LANGUAGE TypeFamilies #-}+-----------------------------------------------------------------------------+-- |+-- Module      :  Control.Lens.Equality+-- Copyright   :  (C) 2012-13 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  provisional+-- Portability :  Rank2Types+--+----------------------------------------------------------------------------+module Control.Lens.Equality+  (+  -- * Type Equality+    Equality, Equality'+  , AnEquality, AnEquality'+  , runEq+  , substEq+  , mapEq+  , fromEq+  , simply+  -- * Implementation Details+  , Identical(..)+  ) where++import Control.Lens.Internal.Setter+import Control.Lens.Type++{-# ANN module "HLint: ignore Use id" #-}+{-# ANN module "HLint: ignore Eta reduce" #-}++-- $setup+-- >>> import Control.Lens++-----------------------------------------------------------------------------+-- Equality+-----------------------------------------------------------------------------++-- | Provides witness that @(s ~ a, b ~ t)@ holds.+data Identical a b s t where+  Identical :: Identical a b a b++-- | When you see this as an argument to a function, it expects an 'Equality'.+type AnEquality s t a b = Identical a (Mutator b) a (Mutator b) -> Identical a (Mutator b) s (Mutator t)++-- | A 'Simple' 'AnEquality'.+type AnEquality' s a = AnEquality s s a a++-- | Extract a witness of type 'Equality'.+runEq :: AnEquality s t a b -> Identical s t a b+runEq l = case l Identical of Identical -> Identical+{-# INLINE runEq #-}++-- | Substituting types with 'Equality'.+substEq :: AnEquality s t a b -> ((s ~ a, t ~ b) => r) -> r+substEq l = case runEq l of+  Identical -> \r -> r+{-# INLINE substEq #-}++-- | We can use 'Equality' to do substitution into anything.+mapEq :: AnEquality s t a b -> f s -> f a+mapEq l r = substEq l r+{-# INLINE mapEq #-}++-- | 'Equality' is symmetric.+fromEq :: AnEquality s t a b -> Equality b a t s+fromEq l = substEq l id+{-# INLINE fromEq #-}++-- | This is an adverb that can be used to modify many other 'Lens' combinators to make them require+-- simple lenses, simple traversals, simple prisms or simple isos as input.+simply :: (Overloaded' p f s a -> r) -> Overloaded' p f s a -> r+simply = id+{-# INLINE simply #-}
src/Control/Lens/Fold.hs view
@@ -1,1188 +1,2113 @@ {-# LANGUAGE CPP #-}-{-# LANGUAGE MagicHash #-}-{-# LANGUAGE Rank2Types #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE LiberalTypeSynonyms #-}-{-# LANGUAGE UndecidableInstances #-}-{-# LANGUAGE MultiParamTypeClasses #-}-#ifdef TRUSTWORTHY-{-# LANGUAGE Trustworthy #-}-#endif-------------------------------------------------------------------------------- |--- Module      :  Control.Lens.Fold--- Copyright   :  (C) 2012 Edward Kmett--- License     :  BSD-style (see the file LICENSE)--- Maintainer  :  Edward Kmett <ekmett@gmail.com>--- Stability   :  provisional--- Portability :  Rank2Types------ A @'Fold' s a@ is a generalization of something 'Foldable'. It allows--- you to extract multiple results from a container. A 'Foldable' container--- can be characterized by the behavior of--- @foldMap :: ('Foldable' t, 'Monoid' m) => (a -> m) -> t a -> m@.--- Since we want to be able to work with monomorphic containers, we could--- generalize this signature to @forall m. 'Monoid' m => (a -> m) -> s -> m@,--- and then decorate it with 'Accessor' to obtain------ @type 'Fold' s a = forall m. 'Monoid' m => 'Getting' m s s a a@------ Every 'Getter' is a valid 'Fold' that simply doesn't use the 'Monoid'--- it is passed.------ In practice the type we use is slightly more complicated to allow for--- better error messages and for it to be transformed by certain--- 'Applicative' transformers.------ Everything you can do with a 'Foldable' container, you can with with a 'Fold' and there are--- combinators that generalize the usual 'Foldable' operations here.------------------------------------------------------------------------------module Control.Lens.Fold-  (-  -- * Folds-    Fold-  , (^..)-  , (^?)-  , (^?!)-  , preview-  , previews-  , preuse-  , preuses-  -- ** Building Folds-  --, folds-  , folding-  , folded-  , unfolded-  , iterated-  , filtered-  , backwards-  , repeated-  , replicated-  , cycled-  , takingWhile-  , droppingWhile-  -- ** Folding-  , foldMapOf, foldOf-  , foldrOf, foldlOf-  , toListOf-  , anyOf, allOf-  , andOf, orOf-  , productOf, sumOf-  , traverseOf_, forOf_, sequenceAOf_-  , mapMOf_, forMOf_, sequenceOf_-  , asumOf, msumOf-  , concatMapOf, concatOf-  , elemOf, notElemOf-  , lengthOf-  , nullOf, notNullOf-  , firstOf, lastOf-  , maximumOf, minimumOf-  , maximumByOf, minimumByOf-  , findOf-  , foldrOf', foldlOf'-  , foldr1Of, foldl1Of-  , foldrMOf, foldlMOf-  -- * Storing Folds-  , ReifiedFold(..)-  -- * Deprecated-  , headOf-  ) where--import Control.Applicative as Applicative-import Control.Applicative.Backwards-import Control.Lens.Classes-import Control.Lens.Getter-import Control.Lens.Internal-import Control.Lens.Internal.Combinators-import Control.Lens.Type-import Control.Monad-import Control.Monad.Reader-import Control.Monad.State-import Data.Foldable as Foldable-import Data.Maybe-import Data.Monoid---- $setup--- >>> import Control.Lens--infixl 8 ^.., ^?, ^?!------------------------------- Folds------------------------------- | A 'Fold' describes how to retrieve multiple values in a way that can be composed--- with other lens-like constructions.------ A @'Fold' s a@ provides a structure with operations very similar to those of the 'Foldable'--- typeclass, see 'foldMapOf' and the other 'Fold' combinators.------ By convention, if there exists a 'foo' method that expects a @'Foldable' (f a)@, then there should be a--- @fooOf@ method that takes a @'Fold' s a@ and a value of type @s@.------ A 'Getter' is a legal 'Fold' that just ignores the supplied 'Monoid'------ Unlike a 'Control.Lens.Traversal.Traversal' a 'Fold' is read-only. Since a 'Fold' cannot be used to write back--- there are no lens laws that apply.-type Fold s a = forall f. (Gettable f, Applicative f) => (a -> f a) -> s -> f s----- | Obtain a 'Fold' by lifting an operation that returns a foldable result.------ This can be useful to lift operations from @Data.List@ and elsewhere into a 'Fold'.------ >>> [1,2,3,4]^..folding tail--- [2,3,4]-folding :: (Foldable f, Applicative g, Gettable g) => (s -> f a) -> LensLike g s t a b-folding sfa agb = coerce . traverse_ agb . sfa-{-# INLINE folding #-}---- | Obtain a 'Fold' from any 'Foldable'.------ >>> Just 3^..folded--- [3]------ >>> Nothing^..folded--- []------ >>> [(1,2),(3,4)]^..folded.both--- [1,2,3,4]-folded :: Foldable f => Fold (f a) a-folded f = coerce . getFolding . foldMap (folding# f)-{-# INLINE folded #-}---- | Fold by repeating the input forever.------ @'repeat' ≡ 'toListOf' 'repeated'@------ >>> 5^..taking 20 repeated--- [5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5]-repeated :: Fold a a-repeated f a = as where as = f a *> as-{-# INLINE repeated #-}---- | A fold that replicates its input @n@ times.------ @'replicate' n ≡ 'toListOf' ('replicated' n)@------ >>> 5^..replicated 20--- [5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5]-replicated :: Int -> Fold a a-replicated n0 f a = go n0 where-  m = f a-  go 0 = noEffect-  go n = m *> go (n - 1)-{-# INLINE replicated #-}---- | Transform a fold into a fold that loops over its elements over and over.------ >>> [1,2,3]^..taking 7 (cycled traverse)--- [1,2,3,1,2,3,1]-cycled :: (Applicative f, Gettable f) => LensLike f s t a b -> LensLike f s t a b-cycled l f a = as where as = l f a *> as-{-# INLINE cycled #-}---- | Build a fold that unfolds its values from a seed.------ @'Prelude.unfoldr' ≡ 'toListOf' . 'unfolded'@------ >>> 10^..unfolded (\b -> if b == 0 then Nothing else Just (b, b-1))--- [10,9,8,7,6,5,4,3,2,1]-unfolded :: (b -> Maybe (a, b)) -> Fold b a-unfolded f g b0 = go b0 where-  go b = case f b of-    Just (a, b') -> g a *> go b'-    Nothing      -> noEffect-{-# INLINE unfolded #-}---- | @x ^. 'iterated' f@ Return an infinite fold of repeated applications of @f@ to @x@.------ @'toListOf' ('iterated' f) a ≡ 'iterate' f a@-iterated :: (a -> a) -> Fold a a-iterated f g a0 = go a0 where-  go a = g a *> go (f a)-{-# INLINE iterated #-}---- | Obtain a 'Fold' that can be composed with to filter another 'Lens', 'Control.Lens.Iso.Iso', 'Getter', 'Fold' (or 'Control.Lens.Traversal.Traversal')------ Note: This is /not/ a legal 'Control.Lens.Traversal.Traversal', unless you are very careful not to invalidate the predicate on the target.------ As a counter example, consider that given @evens = 'filtered' 'even'@ the second 'Control.Lens.Traversal.Traversal' law is violated:------ @'over' evens 'succ' '.' 'over' evens 'succ' /= 'over' evens ('succ' '.' 'succ')@------ So, in order for this to qualify as a legal 'Traversal' you can only use it for actions that preserve the result of the predicate!------ @'filtered' :: (a -> 'Bool') -> 'Fold' a a@-filtered :: Applicative f => (a -> Bool) -> SimpleLensLike f a a-filtered p f a-  | p a       = f a-  | otherwise = pure a-{-# INLINE filtered #-}---- | This allows you to traverse the elements of a 'Control.Lens.Traversal.Traversal' or 'Fold' in the opposite order.--- This will demote an 'Control.Lens.IndexedTraversal.IndexedTraversal' or 'Control.Lens.IndexedFold.IndexedFold' to a regular 'Control.Lens.Traversal.Traversal' or 'Fold',--- respectively; to preserve the indices, use 'Control.Lens.IndexedFold.ibackwards' instead.------ Note: 'backwards' should have no impact on a 'Getter', 'Control.Lens.Setter.Setter', 'Lens' or 'Control.Lens.Iso.Iso'.------ To change the direction of an 'Control.Lens.Iso.Iso', use 'Control.Lens.Isomorphic.from'.-backwards :: LensLike (Backwards f) s t a b -> LensLike f s t a b-backwards l f = forwards# $ l (backwards# f)-{-# INLINE backwards #-}---- | Obtain a 'Fold' by taking elements from another 'Fold', 'Lens', 'Control.Lens.Iso.Iso', 'Getter' or 'Control.Lens.Traversal.Traversal' while a predicate holds.------ @'takeWhile' p ≡ 'toListOf' ('takingWhile' p 'folded')@------ >>> toListOf (takingWhile (<=3) folded) [1..]--- [1,2,3]-takingWhile :: (Gettable f, Applicative f)-            => (a -> Bool)-            -> Getting (Endo (f s)) s s a a-            -> LensLike f s s a a-takingWhile p l f = foldrOf l (\a r -> if p a then f a *> r else noEffect) noEffect-{-# INLINE takingWhile #-}----- | Obtain a 'Fold' by dropping elements from another 'Fold', 'Lens', 'Control.Lens.Iso.Iso', 'Getter' or 'Control.Lens.Traversal.Traversal' while a predicate holds.------ @'dropWhile' p ≡ 'toListOf' ('droppingWhile' p 'folded')@------ >>> toListOf (droppingWhile (<=3) folded) [1..6]--- [4,5,6]------ >>> toListOf (droppingWhile (<=3) folded) [1,6,1]--- [6,1]-droppingWhile :: (Gettable f, Applicative f)-              => (a -> Bool)-              -> Getting (Endo (f s, f s)) s s a a-              -> LensLike f s s a a-droppingWhile p l f = fst . foldrOf l (\a r -> let s = f a *> snd r in (if p a then fst r else s, s)) (noEffect, noEffect)-{-# INLINE droppingWhile #-}------------------------------- Fold/Getter combinators------------------------------- |--- @'Data.Foldable.foldMap' = 'foldMapOf' 'folded'@------ @'foldMapOf' ≡ 'views'@------ @--- 'foldMapOf' ::             'Getter' s a           -> (a -> r) -> s -> r--- 'foldMapOf' :: 'Monoid' r => 'Fold' s a             -> (a -> r) -> s -> r--- 'foldMapOf' ::             'Simple' 'Lens' s a      -> (a -> r) -> s -> r--- 'foldMapOf' ::             'Simple' 'Control.Lens.Iso.Iso' s a       -> (a -> r) -> s -> r--- 'foldMapOf' :: 'Monoid' r => 'Simple' 'Control.Lens.Traversal.Traversal' s a -> (a -> r) -> s -> r--- 'foldMapOf' :: 'Monoid' r => 'Simple' 'Control.Lens.Prism.Prism' s a     -> (a -> r) -> s -> r--- @-foldMapOf :: Getting r s t a b -> (a -> r) -> s -> r-foldMapOf l f = runAccessor# (l (accessor# f))-{-# INLINE foldMapOf #-}---- |--- @'Data.Foldable.fold' = 'foldOf' 'folded'@------ @'foldOf' ≡ 'view'@------ @--- 'foldOf' ::             'Getter' s m           -> s -> m--- 'foldOf' :: 'Monoid' m => 'Fold' s m             -> s -> m--- 'foldOf' ::             'Simple' 'Lens' s m      -> s -> m--- 'foldOf' ::             'Simple' 'Control.Lens.Iso.Iso' s m       -> s -> m--- 'foldOf' :: 'Monoid' m => 'Simple' 'Control.Lens.Traversal.Traversal' s m -> s -> m--- 'foldOf' :: 'Monoid' m => 'Simple' 'Control.Lens.Prism.Prism' s m     -> s -> m--- @-foldOf :: Getting a s t a b -> s -> a-foldOf l = runAccessor# (l Accessor)-{-# INLINE foldOf #-}---- |--- Right-associative fold of parts of a structure that are viewed through a 'Lens', 'Getter', 'Fold' or 'Control.Lens.Traversal.Traversal'.------ @'Data.Foldable.foldr' ≡ 'foldrOf' 'folded'@------ @--- 'foldrOf' :: 'Getter' s a           -> (a -> r -> r) -> r -> s -> r--- 'foldrOf' :: 'Fold' s a             -> (a -> r -> r) -> r -> s -> r--- 'foldrOf' :: 'Simple' 'Lens' s a      -> (a -> r -> r) -> r -> s -> r--- 'foldrOf' :: 'Simple' 'Control.Lens.Iso.Iso' s a       -> (a -> r -> r) -> r -> s -> r--- 'foldrOf' :: 'Simple' 'Control.Lens.Traversal.Traversal' s a -> (a -> r -> r) -> r -> s -> r--- 'foldrOf' :: 'Simple' 'Control.Lens.Prism.Prism' s a     -> (a -> r -> r) -> r -> s -> r--- @-foldrOf :: Getting (Endo r) s t a b -> (a -> r -> r) -> r -> s -> r-foldrOf l f z t = appEndo (foldMapOf l (endo# f) t) z-{-# INLINE foldrOf #-}---- |--- Left-associative fold of the parts of a structure that are viewed through a 'Lens', 'Getter', 'Fold' or 'Control.Lens.Traversal.Traversal'.------ @'Data.Foldable.foldl' ≡ 'foldlOf' 'folded'@------ @--- 'foldlOf' :: 'Getter' s a           -> (r -> a -> r) -> r -> s -> r--- 'foldlOf' :: 'Fold' s a             -> (r -> a -> r) -> r -> s -> r--- 'foldlOf' :: 'Simple' 'Lens' s a      -> (r -> a -> r) -> r -> s -> r--- 'foldlOf' :: 'Simple' 'Control.Lens.Iso.Iso' s a       -> (r -> a -> r) -> r -> s -> r--- 'foldlOf' :: 'Simple' 'Control.Lens.Traversal.Traversal' s a -> (r -> a -> r) -> r -> s -> r--- 'foldlOf' :: 'Simple' 'Control.Lens.Prism.Prism' s a     -> (r -> a -> r) -> r -> s -> r--- @-foldlOf :: Getting (Dual (Endo r)) s t a b -> (r -> a -> r) -> r -> s -> r-foldlOf l f z t = appEndo (getDual (foldMapOf l (dual# (endo# (flip f))) t)) z-{-# INLINE foldlOf #-}---- | Extract a list of the targets of a 'Fold'. See also ('^..').------ @--- 'Data.Foldable.toList' ≡ 'toListOf' 'folded'--- ('^..') ≡ 'flip' 'toListOf'--- @---- >>> toListOf both ("hello","world")--- ["hello","world"]------ @--- 'toListOf' :: 'Getter' s a           -> s -> [a]--- 'toListOf' :: 'Fold' s a             -> s -> [a]--- 'toListOf' :: 'Simple' 'Lens' s a      -> s -> [a]--- 'toListOf' :: 'Simple' 'Control.Lens.Iso.Iso' s a       -> s -> [a]--- 'toListOf' :: 'Simple' 'Control.Lens.Traversal.Traversal' s a -> s -> [a]--- 'toListOf' :: 'Simple' 'Control.Lens.Prism.Prism' s a     -> s -> [a]--- @-toListOf :: Getting (Endo [a]) s t a b -> s -> [a]-toListOf l = foldrOf l (:) []--- toListOf l = foldMapOf l return-{-# INLINE toListOf #-}---- |------ A convenient infix (flipped) version of 'toListOf'.------ >>> [[1,2],[3]]^..traverse.traverse--- [1,2,3]------ >>> (1,2)^..both--- [1,2]------ @--- 'Data.Foldable.toList' xs ≡ xs '^..' 'folded'--- ('^..') ≡ 'flip' 'toListOf'--- @------ @--- ('^..') :: s -> 'Getter' s a           -> [a]--- ('^..') :: s -> 'Fold' s a             -> [a]--- ('^..') :: s -> 'Simple' 'Lens' s a      -> [a]--- ('^..') :: s -> 'Simple' 'Control.Lens.Iso.Iso' s a       -> [a]--- ('^..') :: s -> 'Simple' 'Control.Lens.Traversal.Traversal' s a -> [a]--- ('^..') :: s -> 'Simple' 'Control.Lens.Prism.Prism' s a     -> [a]--- @-(^..) :: s -> Getting (Endo [a]) s t a b -> [a]-s ^.. l = toListOf l s-{-# INLINE (^..) #-}---- | Returns 'True' if every target of a 'Fold' is 'True'.------ >>> andOf both (True,False)--- False--- >>> andOf both (True,True)--- True------ @'Data.Foldable.and' ≡ 'andOf' 'folded'@------ @--- 'andOf' :: 'Getter' s 'Bool'           -> s -> 'Bool'--- 'andOf' :: 'Fold' s 'Bool'             -> s -> 'Bool'--- 'andOf' :: 'Simple' 'Lens' s 'Bool'      -> s -> 'Bool'--- 'andOf' :: 'Simple' 'Control.Lens.Iso.Iso' s 'Bool'       -> s -> 'Bool'--- 'andOf' :: 'Simple' 'Control.Lens.Traversal.Traversal' s 'Bool' -> s -> 'Bool'--- 'andOf' :: 'Simple' 'Control.Lens.Prism.Prism' s 'Bool'     -> s -> 'Bool'--- @-andOf :: Getting All s t Bool b -> s -> Bool-andOf l = getAll# (foldMapOf l All)-{-# INLINE andOf #-}---- | Returns 'True' if any target of a 'Fold' is 'True'.------ >>> orOf both (True,False)--- True--- >>> orOf both (False,False)--- False------ @'Data.Foldable.or' ≡ 'orOf' 'folded'@------ @--- 'orOf' :: 'Getter' s 'Bool'           -> s -> 'Bool'--- 'orOf' :: 'Fold' s 'Bool'             -> s -> 'Bool'--- 'orOf' :: 'Simple' 'Lens' s 'Bool'      -> s -> 'Bool'--- 'orOf' :: 'Simple' 'Control.Lens.Iso.Iso' s 'Bool'       -> s -> 'Bool'--- 'orOf' :: 'Simple' 'Control.Lens.Traversal.Traversal' s 'Bool' -> s -> 'Bool'--- 'orOf' :: 'Simple' 'Control.Lens.Prism.Prism' s 'Bool'     -> s -> 'Bool'--- @-orOf :: Getting Any s t Bool b -> s -> Bool-orOf l = getAny# (foldMapOf l Any)-{-# INLINE orOf #-}---- | Returns 'True' if any target of a 'Fold' satisfies a predicate.------ >>> anyOf both (=='x') ('x','y')--- True--- >>> import Data.Data.Lens--- >>> anyOf biplate (== "world") (((),2::Int),"hello",("world",11))--- True------ @'Data.Foldable.any' ≡ 'anyOf' 'folded'@------ @--- 'anyOf' :: 'Getter' s a               -> (a -> 'Bool') -> s -> 'Bool'--- 'anyOf' :: 'Fold' s a                 -> (a -> 'Bool') -> s -> 'Bool'--- 'anyOf' :: 'Simple' 'Lens' s a      -> (a -> 'Bool') -> s -> 'Bool'--- 'anyOf' :: 'Simple' 'Control.Lens.Iso.Iso' s a       -> (a -> 'Bool') -> s -> 'Bool'--- 'anyOf' :: 'Simple' 'Control.Lens.Traversal.Traversal' s a -> (a -> 'Bool') -> s -> 'Bool'--- 'anyOf' :: 'Simple' 'Control.Lens.Prism.Prism' s a     -> (a -> 'Bool') -> s -> 'Bool'--- @-anyOf :: Getting Any s t a b -> (a -> Bool) -> s -> Bool-anyOf l f = getAny# $ foldMapOf l (any# f)-{-# INLINE anyOf #-}---- | Returns 'True' if every target of a 'Fold' satisfies a predicate.------ >>> allOf both (>=3) (4,5)--- True--- >>> allOf folded (>=2) [1..10]--- False------ @'Data.Foldable.all' ≡ 'allOf' 'folded'@------ @--- 'allOf' :: 'Getter' s a           -> (a -> 'Bool') -> s -> 'Bool'--- 'allOf' :: 'Fold' s a             -> (a -> 'Bool') -> s -> 'Bool'--- 'allOf' :: 'Simple' 'Lens' s a      -> (a -> 'Bool') -> s -> 'Bool'--- 'allOf' :: 'Simple' 'Control.Lens.Iso.Iso' s a       -> (a -> 'Bool') -> s -> 'Bool'--- 'allOf' :: 'Simple' 'Control.Lens.Traversal.Traversal' s a -> (a -> 'Bool') -> s -> 'Bool'--- 'allOf' :: 'Simple' 'Control.Lens.Prism.Prism' s a     -> (a -> 'Bool') -> s -> 'Bool'--- @-allOf :: Getting All s t a b -> (a -> Bool) -> s -> Bool-allOf l f = getAll# $ foldMapOf l (all# f)-{-# INLINE allOf #-}---- | Calculate the product of every number targeted by a 'Fold'------ >>> productOf both (4,5)--- 20--- >>> productOf folded [1,2,3,4,5]--- 120------ @'Data.Foldable.product' ≡ 'productOf' 'folded'@------ @--- 'productOf' ::          'Getter' s a           -> s -> a--- 'productOf' :: 'Num' a => 'Fold' s a             -> s -> a--- 'productOf' ::          'Simple' 'Lens' s a      -> s -> a--- 'productOf' ::          'Simple' 'Control.Lens.Iso.Iso' s a       -> s -> a--- 'productOf' :: 'Num' a => 'Simple' 'Control.Lens.Traversal.Traversal' s a -> s -> a--- 'productOf' :: 'Num' a => 'Simple' 'Control.Lens.Prism.Prism' s a     -> s -> a--- @-productOf :: Getting (Product a) s t a b -> s -> a-productOf l = getProduct# $ foldMapOf l Product-{-# INLINE productOf #-}---- | Calculate the sum of every number targeted by a 'Fold'.------ >>> sumOf both (5,6)--- 11--- >>> sumOf folded [1,2,3,4]--- 10--- >>> sumOf (folded.both) [(1,2),(3,4)]--- 10--- >>> import Data.Data.Lens--- >>> sumOf biplate [(1::Int,[]),(2,[(3::Int,4::Int)])] :: Int--- 10------ @'Data.Foldable.sum' ≡ 'sumOf' 'folded'@------ @--- 'sumOf' '_1' :: (a, b) -> a--- 'sumOf' ('folded' . '_1') :: ('Foldable' f, 'Num' a) => f (a, b) -> a--- @------ @--- 'sumOf' ::          'Getter' s a           -> s -> a--- 'sumOf' :: 'Num' a => 'Fold' s a             -> s -> a--- 'sumOf' ::          'Simple' 'Lens' s a      -> s -> a--- 'sumOf' ::          'Simple' 'Control.Lens.Iso.Iso' s a       -> s -> a--- 'sumOf' :: 'Num' a => 'Simple' 'Control.Lens.Traversal.Traversal' s a -> s -> a--- 'sumOf' :: 'Num' a => 'Simple' 'Control.Lens.Prism.Prism' s a     -> s -> a--- @-sumOf :: Getting (Sum a) s t a b -> s -> a-sumOf l = getSum# $ foldMapOf l Sum-{-# INLINE sumOf #-}---- | Traverse over all of the targets of a 'Fold' (or 'Getter'), computing an 'Applicative' (or 'Functor') -based answer,--- but unlike 'Control.Lens.Traversal.traverseOf' do not construct a new structure. 'traverseOf_' generalizes--- 'Data.Foldable.traverse_' to work over any 'Fold'.------ When passed a 'Getter', 'traverseOf_' can work over any 'Functor', but when passed a 'Fold', 'traverseOf_' requires--- an 'Applicative'.------ >>> traverseOf_ both putStrLn ("hello","world")--- hello--- world------ @'Data.Foldable.traverse_' ≡ 'traverseOf_' 'folded'@------ @--- 'traverseOf_' '_2' :: 'Functor' f => (c -> f r) -> (d, c) -> f ()--- 'traverseOf_' 'Data.Either.Lens.traverseLeft' :: 'Applicative' f => (a -> f b) -> 'Either' a c -> f ()--- @------ The rather specific signature of 'traverseOf_' allows it to be used as if the signature was any of:------ @--- 'traverseOf_' :: 'Functor' f     => 'Getter' s a           -> (a -> f r) -> s -> f ()--- 'traverseOf_' :: 'Applicative' f => 'Fold' s a             -> (a -> f r) -> s -> f ()--- 'traverseOf_' :: 'Functor' f     => 'Simple' 'Lens' s a      -> (a -> f r) -> s -> f ()--- 'traverseOf_' :: 'Functor' f     => 'Simple' 'Control.Lens.Iso.Iso' s a       -> (a -> f r) -> s -> f ()--- 'traverseOf_' :: 'Applicative' f => 'Simple' 'Control.Lens.Traversal.Traversal' s a -> (a -> f r) -> s -> f ()--- 'traverseOf_' :: 'Applicative' f => 'Simple' 'Control.Lens.Prism.Prism' s a     -> (a -> f r) -> s -> f ()--- @-traverseOf_ :: Functor f => Getting (Traversed f) s t a b -> (a -> f r) -> s -> f ()-traverseOf_ l f = getTraversed# (foldMapOf l (traversed# (void . f)))-{-# INLINE traverseOf_ #-}---- | Traverse over all of the targets of a 'Fold' (or 'Getter'), computing an 'Applicative' (or 'Functor') -based answer,--- but unlike 'Control.Lens.Traversal.forOf' do not construct a new structure. 'forOf_' generalizes--- 'Data.Foldable.for_' to work over any 'Fold'.------ When passed a 'Getter', 'forOf_' can work over any 'Functor', but when passed a 'Fold', 'forOf_' requires--- an 'Applicative'.------ @'for_' ≡ 'forOf_' 'folded'@------ The rather specific signature of 'forOf_' allows it to be used as if the signature was any of:------ @--- 'forOf_' :: 'Functor' f     => 'Getter' s a           -> s -> (a -> f r) -> f ()--- 'forOf_' :: 'Applicative' f => 'Fold' s a             -> s -> (a -> f r) -> f ()--- 'forOf_' :: 'Functor' f     => 'Simple' 'Lens' s a      -> s -> (a -> f r) -> f ()--- 'forOf_' :: 'Functor' f     => 'Simple' 'Control.Lens.Iso.Iso' s a       -> s -> (a -> f r) -> f ()--- 'forOf_' :: 'Applicative' f => 'Simple' 'Control.Lens.Traversal.Traversal' s a -> s -> (a -> f r) -> f ()--- 'forOf_' :: 'Applicative' f => 'Simple' 'Control.Lens.Prism.Prism' s a     -> s -> (a -> f r) -> f ()--- @-forOf_ :: Functor f => Getting (Traversed f) s t a b -> s -> (a -> f r) -> f ()-forOf_ = flip . traverseOf_-{-# INLINE forOf_ #-}---- | Evaluate each action in observed by a 'Fold' on a structure from left to right, ignoring the results.------ @'sequenceA_' ≡ 'sequenceAOf_' 'folded'@------ @--- 'sequenceAOf_' :: 'Functor' f     => 'Getter' s (f a)           -> s -> f ()--- 'sequenceAOf_' :: 'Applicative' f => 'Fold' s (f a)             -> s -> f ()--- 'sequenceAOf_' :: 'Functor' f     => 'Simple' 'Lens' s (f a)      -> s -> f ()--- 'sequenceAOf_' :: 'Functor' f     => 'Simple' 'Iso' s (f a)       -> s -> f ()--- 'sequenceAOf_' :: 'Applicative' f => 'Simple' 'Control.Lens.Traversal.Traversal' s (f a) -> s -> f ()--- 'sequenceAOf_' :: 'Applicative' f => 'Simple' 'Control.Lens.Prism.Prism' s (f a)     -> s -> f ()--- @-sequenceAOf_ :: Functor f => Getting (Traversed f) s t (f a) b -> s -> f ()-sequenceAOf_ l = getTraversed# (foldMapOf l (traversed# void))-{-# INLINE sequenceAOf_ #-}---- | Map each target of a 'Fold' on a structure to a monadic action, evaluate these actions from left to right, and ignore the results.------ @'Data.Foldable.mapM_' ≡ 'mapMOf_' 'folded'@------ @--- 'mapMOf_' :: 'Monad' m => 'Getter' s a           -> (a -> m r) -> s -> m ()--- 'mapMOf_' :: 'Monad' m => 'Fold' s a             -> (a -> m r) -> s -> m ()--- 'mapMOf_' :: 'Monad' m => 'Simple' 'Lens' s a      -> (a -> m r) -> s -> m ()--- 'mapMOf_' :: 'Monad' m => 'Simple' 'Control.Lens.Iso.Iso' s a       -> (a -> m r) -> s -> m ()--- 'mapMOf_' :: 'Monad' m => 'Simple' 'Control.Lens.Traversal.Traversal' s a -> (a -> m r) -> s -> m ()--- 'mapMOf_' :: 'Monad' m => 'Simple' 'Control.Lens.Prism.Prism' s a     -> (a -> m r) -> s -> m ()--- @-mapMOf_ :: Monad m => Getting (Sequenced m) s t a b -> (a -> m r) -> s -> m ()-mapMOf_ l f = getSequenced# (foldMapOf l (sequenced# (liftM skip . f)))-{-# INLINE mapMOf_ #-}--skip :: a -> ()-skip _ = ()-{-# INLINE skip #-}---- | 'forMOf_' is 'mapMOf_' with two of its arguments flipped.------ @'Data.Foldable.forM_' ≡ 'forMOf_' 'folded'@------ @--- 'forMOf_' :: 'Monad' m => 'Getter' s a           -> s -> (a -> m r) -> m ()--- 'forMOf_' :: 'Monad' m => 'Fold' s a             -> s -> (a -> m r) -> m ()--- 'forMOf_' :: 'Monad' m => 'Simple' 'Lens' s a      -> s -> (a -> m r) -> m ()--- 'forMOf_' :: 'Monad' m => 'Simple' 'Control.Lens.Iso.Iso' s a       -> s -> (a -> m r) -> m ()--- 'forMOf_' :: 'Monad' m => 'Simple' 'Control.Lens.Traversal.Traversal' s a -> s -> (a -> m r) -> m ()--- 'forMOf_' :: 'Monad' m => 'Simple' 'Control.Lens.Prism.Prism' s a     -> s -> (a -> m r) -> m ()--- @-forMOf_ :: Monad m => Getting (Sequenced m) s t a b -> s -> (a -> m r) -> m ()-forMOf_ = flip . mapMOf_-{-# INLINE forMOf_ #-}---- | Evaluate each monadic action referenced by a 'Fold' on the structure from left to right, and ignore the results.------ @'Data.Foldable.sequence_' ≡ 'sequenceOf_' 'folded'@------ @--- 'sequenceOf_' :: 'Monad' m => 'Getter' s (m a)           -> s -> m ()--- 'sequenceOf_' :: 'Monad' m => 'Fold' s (m a)             -> s -> m ()--- 'sequenceOf_' :: 'Monad' m => 'Simple' 'Lens' s (m a)      -> s -> m ()--- 'sequenceOf_' :: 'Monad' m => 'Simple' 'Control.Lens.Iso.Iso' s (m a)       -> s -> m ()--- 'sequenceOf_' :: 'Monad' m => 'Simple' 'Control.Lens.Traversal.Traversal' s (m a) -> s -> m ()--- 'sequenceOf_' :: 'Monad' m => 'Simple' 'Control.Lens.Prism.Prism' s (m a)     -> s -> m ()--- @-sequenceOf_ :: Monad m => Getting (Sequenced m) s t (m a) b -> s -> m ()-sequenceOf_ l = getSequenced# (foldMapOf l (sequenced# (liftM skip)))-{-# INLINE sequenceOf_ #-}---- | The sum of a collection of actions, generalizing 'concatOf'.------ @'asum' ≡ 'asumOf' 'folded'@------ @--- 'asumOf' :: 'Alternative' f => 'Getter' s a           -> s -> f a--- 'asumOf' :: 'Alternative' f => 'Fold' s a             -> s -> f a--- 'asumOf' :: 'Alternative' f => 'Simple' 'Lens' s a      -> s -> f a--- 'asumOf' :: 'Alternative' f => 'Simple' 'Control.Lens.Iso.Iso' s a       -> s -> f a--- 'asumOf' :: 'Alternative' f => 'Simple' 'Control.Lens.Traversal.Traversal' s a -> s -> f a--- 'asumOf' :: 'Alternative' f => 'Simple' 'Control.Lens.Prism.Prism' s a     -> s -> f a--- @-asumOf :: Alternative f => Getting (Endo (f a)) s t (f a) b -> s -> f a-asumOf l = foldrOf l (<|>) Applicative.empty-{-# INLINE asumOf #-}---- | The sum of a collection of actions, generalizing 'concatOf'.------ @'msum' ≡ 'msumOf' 'folded'@------ @--- 'msumOf' :: 'MonadPlus' m => 'Getter' s a           -> s -> m a--- 'msumOf' :: 'MonadPlus' m => 'Fold' s a             -> s -> m a--- 'msumOf' :: 'MonadPlus' m => 'Simple' 'Lens' s a      -> s -> m a--- 'msumOf' :: 'MonadPlus' m => 'Simple' 'Control.Lens.Iso.Iso' s a       -> s -> m a--- 'msumOf' :: 'MonadPlus' m => 'Simple' 'Control.Lens.Traversal.Traversal' s a -> s -> m a--- 'msumOf' :: 'MonadPlus' m => 'Simple' 'Control.Lens.Prism.Prism' s a     -> s -> m a--- @-msumOf :: MonadPlus m => Getting (Endo (m a)) s t (m a) b -> s -> m a-msumOf l = foldrOf l mplus mzero-{-# INLINE msumOf #-}---- | Does the element occur anywhere within a given 'Fold' of the structure?------ >>> elemOf both "hello" ("hello","world")--- True------ @'elem' ≡ 'elemOf' 'folded'@------ @--- 'elemOf' :: 'Eq' a => 'Getter' s a           -> a -> s -> 'Bool'--- 'elemOf' :: 'Eq' a => 'Fold' s a             -> a -> s -> 'Bool'--- 'elemOf' :: 'Eq' a => 'Simple' 'Lens' s a      -> a -> s -> 'Bool'--- 'elemOf' :: 'Eq' a => 'Simple' 'Control.Lens.Iso.Iso' s a       -> a -> s -> 'Bool'--- 'elemOf' :: 'Eq' a => 'Simple' 'Control.Lens.Traversal.Traversal' s a -> a -> s -> 'Bool'--- 'elemOf' :: 'Eq' a => 'Simple' 'Control.Lens.Prism.Prism' s a     -> a -> s -> 'Bool'--- @-elemOf :: Eq a => Getting Any s t a b -> a -> s -> Bool-elemOf l = anyOf l . (==)-{-# INLINE elemOf #-}---- | Does the element not occur anywhere within a given 'Fold' of the structure?------ @'notElem' ≡ 'notElemOf' 'folded'@------ @--- 'notElemOf' :: 'Eq' a => 'Getter' s a           -> a -> s -> 'Bool'--- 'notElemOf' :: 'Eq' a => 'Fold' s a             -> a -> s -> 'Bool'--- 'notElemOf' :: 'Eq' a => 'Simple' 'Control.Lens.Iso.Iso' s a       -> a -> s -> 'Bool'--- 'notElemOf' :: 'Eq' a => 'Simple' 'Lens' s a      -> a -> s -> 'Bool'--- 'notElemOf' :: 'Eq' a => 'Simple' 'Control.Lens.Traversal.Traversal' s a -> a -> s -> 'Bool'--- 'notElemOf' :: 'Eq' a => 'Simple' 'Control.Lens.Prism.Prism' s a     -> a -> s -> 'Bool'--- @-notElemOf :: Eq a => Getting All s t a b -> a -> s -> Bool-notElemOf l = allOf l . (/=)-{-# INLINE notElemOf #-}---- | Map a function over all the targets of a 'Fold' of a container and concatenate the resulting lists.------ @'concatMap' ≡ 'concatMapOf' 'folded'@------ @--- 'concatMapOf' :: 'Getter' s a           -> (a -> [r]) -> s -> [r]--- 'concatMapOf' :: 'Fold' s a             -> (a -> [r]) -> s -> [r]--- 'concatMapOf' :: 'Simple' 'Lens' s a      -> (a -> [r]) -> s -> [r]--- 'concatMapOf' :: 'Simple' 'Control.Lens.Iso.Iso' s a       -> (a -> [r]) -> s -> [r]--- 'concatMapOf' :: 'Simple' 'Control.Lens.Traversal.Traversal' s a -> (a -> [r]) -> s -> [r]--- @-concatMapOf :: Getting [r] s t a b -> (a -> [r]) -> s -> [r]-concatMapOf l ces = runAccessor# (l (accessor# ces))-{-# INLINE concatMapOf #-}---- | Concatenate all of the lists targeted by a 'Fold' into a longer list.------ >>> concatOf both ("pan","ama")--- "panama"------ @--- 'concat' ≡ 'concatOf' 'folded'--- 'concatOf' ≡ 'view'--- @------ @--- 'concatOf' :: 'Getter' s [r]           -> s -> [r]--- 'concatOf' :: 'Fold' s [r]             -> s -> [r]--- 'concatOf' :: 'Simple' 'Control.Lens.Iso.Iso' s [r]       -> s -> [r]--- 'concatOf' :: 'Simple' 'Lens' s [r]      -> s -> [r]--- 'concatOf' :: 'Simple' 'Control.Lens.Traversal.Traversal' s [r] -> s -> [r]--- @-concatOf :: Getting [r] s t [r] b -> s -> [r]-concatOf = view-{-# INLINE concatOf #-}---- |--- Note: this can be rather inefficient for large containers.------ @'length' ≡ 'lengthOf' 'folded'@------ >>> lengthOf _1 ("hello",())--- 1------ @'lengthOf' ('folded' . 'folded') :: 'Foldable' f => f (g a) -> 'Int'@------ @--- 'lengthOf' :: 'Getter' s a           -> s -> 'Int'--- 'lengthOf' :: 'Fold' s a             -> s -> 'Int'--- 'lengthOf' :: 'Simple' 'Lens' s a      -> s -> 'Int'--- 'lengthOf' :: 'Simple' 'Control.Lens.Iso.Iso' s a       -> s -> 'Int'--- 'lengthOf' :: 'Simple' 'Control.Lens.Traversal.Traversal' s a -> s -> 'Int'--- @-lengthOf :: Getting (Sum Int) s t a b -> s -> Int-lengthOf l = getSum# (foldMapOf l (\_ -> Sum 1))-{-# INLINE lengthOf #-}---- | A deprecated alias for 'firstOf'-headOf :: Getting (First a) s t a b -> s -> Maybe a-headOf l = getFirst# (foldMapOf l (first# Just))-{-# INLINE headOf #-}-{-# DEPRECATED headOf "`headOf' will be removed in 3.8. (Use `preview' or `firstOf')" #-}---- | Perform a safe 'head' of a 'Fold' or 'Control.Lens.Traversal.Traversal' or retrieve 'Just' the result--- from a 'Getter' or 'Lens'.------ When using a 'Control.Lens.Traversal.Traversal' as a partial 'Control.Lens.Type.Lens', or a 'Fold' as a partial 'Getter' this can be a convenient--- way to extract the optional value.------ @('^?') ≡ 'flip' 'preview'@------ @--- ('^?') :: s -> 'Getter' s a           -> 'Maybe' a--- ('^?') :: s -> 'Fold' s a             -> 'Maybe' a--- ('^?') :: s -> 'Simple' 'Lens' s a      -> 'Maybe' a--- ('^?') :: s -> 'Simple' 'Control.Lens.Iso.Iso' s a       -> 'Maybe' a--- ('^?') :: s -> 'Simple' 'Control.Lens.Traversal.Traversal' s a -> 'Maybe' a--- @-(^?) :: s -> Getting (First a) s t a b -> Maybe a-a ^? l = getFirst (foldMapOf l (first# Just) a)-{-# INLINE (^?) #-}---- | Perform an *UNSAFE* 'head' of a 'Fold' or 'Control.Lens.Traversal.Traversal' assuming that it is there.------ @--- ('^?!') :: s -> 'Getter' s a           -> a--- ('^?!') :: s -> 'Fold' s a             -> a--- ('^?!') :: s -> 'Simple' 'Lens' s a      -> a--- ('^?!') :: s -> 'Simple' 'Control.Lens.Iso.Iso' s a       -> a--- ('^?!') :: s -> 'Simple' 'Control.Lens.Traversal.Traversal' s a -> a--- @-(^?!) :: s -> Getting (First a) s t a b -> a-a ^?! l = fromMaybe (error "(^?!): empty Fold") $ getFirst (foldMapOf l (first# Just) a)-{-# INLINE (^?!) #-}---- | Retrieve the 'First' entry of a 'Fold' or 'Control.Lens.Traversal.Traversal' or retrieve 'Just' the result--- from a 'Getter' or 'Lens'.------ @--- 'firstOf' :: 'Getter' s a           -> s -> 'Maybe' a--- 'firstOf' :: 'Fold' s a             -> s -> 'Maybe' a--- 'firstOf' :: 'Simple' 'Lens' s a      -> s -> 'Maybe' a--- 'firstOf' :: 'Simple' 'Control.Lens.Iso.Iso' s a       -> s -> 'Maybe' a--- 'firstOf' :: 'Simple' 'Control.Lens.Traversal.Traversal' s a -> s -> 'Maybe' a--- @-firstOf :: Getting (First a) s t a b -> s -> Maybe a-firstOf l = getFirst# (foldMapOf l (first# Just))-{-# INLINE firstOf #-}---- | Retrieve the 'Last' entry of a 'Fold' or 'Control.Lens.Traversal.Traversal' or retrieve 'Just' the result--- from a 'Getter' or 'Lens'.------ @--- 'lastOf' :: 'Getter' s a           -> s -> 'Maybe' a--- 'lastOf' :: 'Fold' s a             -> s -> 'Maybe' a--- 'lastOf' :: 'Simple' 'Lens' s a      -> s -> 'Maybe' a--- 'lastOf' :: 'Simple' 'Control.Lens.Iso.Iso' s a       -> s -> 'Maybe' a--- 'lastOf' :: 'Simple' 'Control.Lens.Traversal.Traversal' s a -> s -> 'Maybe' a--- @-lastOf :: Getting (Last a) s t a b -> s -> Maybe a-lastOf l = getLast# (foldMapOf l (last# Just))-{-# INLINE lastOf #-}---- |--- Returns 'True' if this 'Fold' or 'Control.Lens.Traversal.Traversal' has no targets in the given container.------ Note: 'nullOf' on a valid 'Control.Lens.Iso.Iso', 'Lens' or 'Getter' should always return 'False'------ @'null' ≡ 'nullOf' 'folded'@------ This may be rather inefficient compared to the 'null' check of many containers.------ >>> nullOf _1 (1,2)--- False------ @'nullOf' ('folded' '.' '_1' '.' 'folded') :: 'Foldable' f => f (g a, b) -> 'Bool'@------ @--- 'nullOf' :: 'Getter' s a           -> s -> 'Bool'--- 'nullOf' :: 'Fold' s a             -> s -> 'Bool'--- 'nullOf' :: 'Simple' 'Control.Lens.Iso.Iso' s a       -> s -> 'Bool'--- 'nullOf' :: 'Simple' 'Lens' s a      -> s -> 'Bool'--- 'nullOf' :: 'Simple' 'Control.Lens.Traversal.Traversal' s a -> s -> 'Bool'--- @-nullOf :: Getting All s t a b -> s -> Bool-nullOf l = getAll# (foldMapOf l (\_ -> All False))-{-# INLINE nullOf #-}----- |--- Returns 'True' if this 'Fold' or 'Control.Lens.Traversal.Traversal' has any targets in the given container.------ Note: 'notNullOf' on a valid 'Control.Lens.Iso.Iso', 'Lens' or 'Getter' should always return 'True'------ @'null' ≡ 'notNullOf' 'folded'@------ This may be rather inefficient compared to the @'not' . 'null'@ check of many containers.------ >>> notNullOf _1 (1,2)--- True------ @'notNullOf' ('folded' '.' '_1' '.' 'folded') :: 'Foldable' f => f (g a, b) -> 'Bool'@------ @--- 'notNullOf' :: 'Getter' s a           -> s -> 'Bool'--- 'notNullOf' :: 'Fold' s a             -> s -> 'Bool'--- 'notNullOf' :: 'Simple' 'Control.Lens.Iso.Iso' s a       -> s -> 'Bool'--- 'notNullOf' :: 'Simple' 'Lens' s a      -> s -> 'Bool'--- 'notNullOf' :: 'Simple' 'Control.Lens.Traversal.Traversal' s a -> s -> 'Bool'--- @-notNullOf :: Getting Any s t a b -> s -> Bool-notNullOf l = getAny# (foldMapOf l (\_ -> Any True))-{-# INLINE notNullOf #-}---- |--- Obtain the maximum element (if any) targeted by a 'Fold' or 'Control.Lens.Traversal.Traversal'------ Note: maximumOf on a valid 'Control.Lens.Iso.Iso', 'Lens' or 'Getter' will always return 'Just' a value.------ @'maximum' ≡ 'fromMaybe' ('error' \"empty\") '.' 'maximumOf' 'folded'@------ @--- 'maximumOf' ::          'Getter' s a           -> s -> 'Maybe' a--- 'maximumOf' :: 'Ord' a => 'Fold' s a             -> s -> 'Maybe' a--- 'maximumOf' ::          'Simple' 'Control.Lens.Iso.Iso' s a       -> s -> 'Maybe' a--- 'maximumOf' ::          'Simple' 'Lens' s a      -> s -> 'Maybe' a--- 'maximumOf' :: 'Ord' a => 'Simple' 'Control.Lens.Traversal.Traversal' s a -> s -> 'Maybe' a--- @-maximumOf :: Getting (Max a) s t a b -> s -> Maybe a-maximumOf l = getMax . foldMapOf l Max-{-# INLINE maximumOf #-}---- |--- Obtain the minimum element (if any) targeted by a 'Fold' or 'Control.Lens.Traversal.Traversal'------ Note: minimumOf on a valid 'Control.Lens.Iso.Iso', 'Lens' or 'Getter' will always return 'Just' a value.------ @'minimum' ≡ 'Data.Maybe.fromMaybe' ('error' \"empty\") '.' 'minimumOf' 'folded'@------ @--- 'minimumOf' ::          'Getter' s a           -> s -> 'Maybe' a--- 'minimumOf' :: 'Ord' a => 'Fold' s a             -> s -> 'Maybe' a--- 'minimumOf' ::          'Simple' 'Control.Lens.Iso.Iso' s a       -> s -> 'Maybe' a--- 'minimumOf' ::          'Simple' 'Lens' s a      -> s -> 'Maybe' a--- 'minimumOf' :: 'Ord' a => 'Simple' 'Control.Lens.Traversal.Traversal' s a -> s -> 'Maybe' a--- @-minimumOf :: Getting (Min a) s t a b -> s -> Maybe a-minimumOf l = getMin . foldMapOf l Min-{-# INLINE minimumOf #-}---- |--- Obtain the maximum element (if any) targeted by a 'Fold', 'Control.Lens.Traversal.Traversal', 'Lens', 'Control.Lens.Iso.Iso',--- or 'Getter' according to a user supplied ordering.------ @'Data.Foldable.maximumBy' cmp ≡ 'Data.Maybe.fromMaybe' ('error' \"empty\") '.' 'maximumByOf' 'folded' cmp@------ @--- 'maximumByOf' :: 'Getter' s a           -> (a -> a -> 'Ordering') -> s -> 'Maybe' a--- 'maximumByOf' :: 'Fold' s a             -> (a -> a -> 'Ordering') -> s -> 'Maybe' a--- 'maximumByOf' :: 'Simple' 'Control.Lens.Iso.Iso' s a       -> (a -> a -> 'Ordering') -> s -> 'Maybe' a--- 'maximumByOf' :: 'Simple' 'Lens' s a      -> (a -> a -> 'Ordering') -> s -> 'Maybe' a--- 'maximumByOf' :: 'Simple' 'Control.Lens.Traversal.Traversal' s a -> (a -> a -> 'Ordering') -> s -> 'Maybe' a--- @-maximumByOf :: Getting (Endo (Maybe a)) s t a b -> (a -> a -> Ordering) -> s -> Maybe a-maximumByOf l cmp = foldrOf l step Nothing where-  step a Nothing  = Just a-  step a (Just b) = Just (if cmp a b == GT then a else b)-{-# INLINE maximumByOf #-}---- |--- Obtain the minimum element (if any) targeted by a 'Fold', 'Control.Lens.Traversal.Traversal', 'Lens', 'Control.Lens.Iso.Iso'--- or 'Getter' according to a user supplied ordering.------ @'minimumBy' cmp ≡ 'Data.Maybe.fromMaybe' ('error' \"empty\") '.' 'minimumByOf' 'folded' cmp@------ @--- 'minimumByOf' :: 'Getter' s a           -> (a -> a -> 'Ordering') -> s -> 'Maybe' a--- 'minimumByOf' :: 'Fold' s a             -> (a -> a -> 'Ordering') -> s -> 'Maybe' a--- 'minimumByOf' :: 'Simple' 'Control.Lens.Iso.Iso' s a       -> (a -> a -> 'Ordering') -> s -> 'Maybe' a--- 'minimumByOf' :: 'Simple' 'Lens' s a      -> (a -> a -> 'Ordering') -> s -> 'Maybe' a--- 'minimumByOf' :: 'Simple' 'Control.Lens.Traversal.Traversal' s a -> (a -> a -> 'Ordering') -> s -> 'Maybe' a--- @-minimumByOf :: Getting (Endo (Maybe a)) s t a b -> (a -> a -> Ordering) -> s -> Maybe a-minimumByOf l cmp = foldrOf l step Nothing where-  step a Nothing  = Just a-  step a (Just b) = Just (if cmp a b == GT then b else a)-{-# INLINE minimumByOf #-}---- | The 'findOf' function takes a 'Lens' (or 'Control.Lens.Getter.Getter', 'Control.Lens.Iso.Iso', 'Control.Lens.Fold.Fold', or 'Control.Lens.Traversal.Traversal'),--- a predicate and a structure and returns the leftmost element of the structure--- matching the predicate, or 'Nothing' if there is no such element.------ @--- 'findOf' :: 'Getter' s a           -> (a -> 'Bool') -> s -> 'Maybe' a--- 'findOf' :: 'Fold' s a             -> (a -> 'Bool') -> s -> 'Maybe' a--- 'findOf' :: 'Simple' 'Control.Lens.Iso.Iso' s a       -> (a -> 'Bool') -> s -> 'Maybe' a--- 'findOf' :: 'Simple' 'Lens' s a      -> (a -> 'Bool') -> s -> 'Maybe' a--- 'findOf' :: 'Simple' 'Control.Lens.Traversal.Traversal' s a -> (a -> 'Bool') -> s -> 'Maybe' a--- @-findOf :: Getting (First a) s t a b -> (a -> Bool) -> s -> Maybe a-findOf l p = getFirst# (foldMapOf l step) where-  step a-    | p a       = First (Just a)-    | otherwise = First Nothing-{-# INLINE findOf #-}---- |--- A variant of 'foldrOf' that has no base case and thus may only be applied--- to lenses and structures such that the lens views at least one element of--- the structure.------ @--- 'foldr1Of' l f ≡ 'Prelude.foldr1' f '.' 'toListOf' l--- 'Data.Foldable.foldr1' ≡ 'foldr1Of' 'folded'--- @------ @--- 'foldr1Of' :: 'Getter' s a           -> (a -> a -> a) -> s -> a--- 'foldr1Of' :: 'Fold' s a             -> (a -> a -> a) -> s -> a--- 'foldr1Of' :: 'Simple' 'Control.Lens.Iso.Iso' s a       -> (a -> a -> a) -> s -> a--- 'foldr1Of' :: 'Simple' 'Lens' s a      -> (a -> a -> a) -> s -> a--- 'foldr1Of' :: 'Simple' 'Control.Lens.Traversal.Traversal' s a -> (a -> a -> a) -> s -> a--- @-foldr1Of :: Getting (Endo (Maybe a)) s t a b -> (a -> a -> a) -> s -> a-foldr1Of l f xs = fromMaybe (error "foldr1Of: empty structure")-                            (foldrOf l mf Nothing xs) where-  mf x Nothing = Just x-  mf x (Just y) = Just (f x y)-{-# INLINE foldr1Of #-}---- | A variant of 'foldlOf' that has no base case and thus may only be applied to lenses and structures such--- that the lens views at least one element of the structure.------ @--- 'foldl1Of' l f ≡ 'Prelude.foldl1Of' l f . 'toList'--- 'Data.Foldable.foldl1' ≡ 'foldl1Of' 'folded'--- @------ @--- 'foldl1Of' :: 'Getter' s a           -> (a -> a -> a) -> s -> a--- 'foldl1Of' :: 'Fold' s a             -> (a -> a -> a) -> s -> a--- 'foldl1Of' :: 'Simple' 'Control.Lens.Iso.Iso' s a       -> (a -> a -> a) -> s -> a--- 'foldl1Of' :: 'Simple' 'Lens' s a      -> (a -> a -> a) -> s -> a--- 'foldl1Of' :: 'Simple' 'Control.Lens.Traversal.Traversal' s a -> (a -> a -> a) -> s -> a--- @-foldl1Of :: Getting (Dual (Endo (Maybe a))) s t a b -> (a -> a -> a) -> s -> a-foldl1Of l f xs = fromMaybe (error "foldl1Of: empty structure") (foldlOf l mf Nothing xs) where-  mf Nothing y = Just y-  mf (Just x) y = Just (f x y)-{-# INLINE foldl1Of #-}---- | Strictly fold right over the elements of a structure.------ @'Data.Foldable.foldr'' ≡ 'foldrOf'' 'folded'@------ @--- 'foldrOf'' :: 'Getter' s a           -> (a -> r -> r) -> r -> s -> r--- 'foldrOf'' :: 'Fold' s a             -> (a -> r -> r) -> r -> s -> r--- 'foldrOf'' :: 'Simple' 'Control.Lens.Iso.Iso' s a       -> (a -> r -> r) -> r -> s -> r--- 'foldrOf'' :: 'Simple' 'Lens' s a      -> (a -> r -> r) -> r -> s -> r--- 'foldrOf'' :: 'Simple' 'Control.Lens.Traversal.Traversal' s a -> (a -> r -> r) -> r -> s -> r--- @-foldrOf' :: Getting (Dual (Endo (r -> r))) s t a b -> (a -> r -> r) -> r -> s -> r-foldrOf' l f z0 xs = foldlOf l f' id xs z0-  where f' k x z = k $! f x z-{-# INLINE foldrOf' #-}---- | Fold over the elements of a structure, associating to the left, but strictly.------ @'Data.Foldable.foldl'' ≡ 'foldlOf'' 'folded'@------ @--- 'foldlOf'' :: 'Getter' s a           -> (r -> a -> r) -> r -> s -> r--- 'foldlOf'' :: 'Fold' s a             -> (r -> a -> r) -> r -> s -> r--- 'foldlOf'' :: 'Simple' 'Control.Lens.Iso.Iso' s a       -> (r -> a -> r) -> r -> s -> r--- 'foldlOf'' :: 'Simple' 'Lens' s a      -> (r -> a -> r) -> r -> s -> r--- 'foldlOf'' :: 'Simple' 'Control.Lens.Traversal.Traversal' s a -> (r -> a -> r) -> r -> s -> r--- @-foldlOf' :: Getting (Endo (r -> r)) s t a b -> (r -> a -> r) -> r -> s -> r-foldlOf' l f z0 xs = foldrOf l f' id xs z0-  where f' x k z = k $! f z x-{-# INLINE foldlOf' #-}---- | Monadic fold over the elements of a structure, associating to the right,--- i.e. from right to left.------ @'Data.Foldable.foldrM' ≡ 'foldrMOf' 'folded'@------ @--- 'foldrMOf' :: 'Monad' m => 'Getter' s a           -> (a -> r -> m r) -> r -> s -> m r--- 'foldrMOf' :: 'Monad' m => 'Fold' s a             -> (a -> r -> m r) -> r -> s -> m r--- 'foldrMOf' :: 'Monad' m => 'Simple' 'Control.Lens.Iso.Iso' s a       -> (a -> r -> m r) -> r -> s -> m r--- 'foldrMOf' :: 'Monad' m => 'Simple' 'Lens' s a      -> (a -> r -> m r) -> r -> s -> m r--- 'foldrMOf' :: 'Monad' m => 'Simple' 'Control.Lens.Traversal.Traversal' s a -> (a -> r -> m r) -> r -> s -> m r--- @-foldrMOf :: Monad m-         => Getting (Dual (Endo (r -> m r))) s t a b-         -> (a -> r -> m r) -> r -> s -> m r-foldrMOf l f z0 xs = foldlOf l f' return xs z0-  where f' k x z = f x z >>= k-{-# INLINE foldrMOf #-}---- | Monadic fold over the elements of a structure, associating to the left,--- i.e. from left to right.------ @'Data.Foldable.foldlM' ≡ 'foldlMOf' 'folded'@------ @--- 'foldlMOf' :: 'Monad' m => 'Getter' s a           -> (r -> a -> m r) -> r -> s -> m r--- 'foldlMOf' :: 'Monad' m => 'Fold' s a             -> (r -> a -> m r) -> r -> s -> m r--- 'foldlMOf' :: 'Monad' m => 'Simple' 'Control.Lens.Iso.Iso' s a       -> (r -> a -> m r) -> r -> s -> m r--- 'foldlMOf' :: 'Monad' m => 'Simple' 'Lens' s a      -> (r -> a -> m r) -> r -> s -> m r--- 'foldlMOf' :: 'Monad' m => 'Simple' 'Control.Lens.Traversal.Traversal' s a -> (r -> a -> m r) -> r -> s -> m r--- @-foldlMOf :: Monad m-         => Getting (Endo (r -> m r)) s t a b-         -> (r -> a -> m r) -> r -> s -> m r-foldlMOf l f z0 xs = foldrOf l f' return xs z0-  where f' x k z = f z x >>= k-{-# INLINE foldlMOf #-}---- | Useful for storing folds in containers.-newtype ReifiedFold s a = ReifyFold { reflectFold :: Fold s a }----------------------------------------------------------------------------------- Preview----------------------------------------------------------------------------------- | Retrieve the first value targeted by a 'Fold' or 'Control.Lens.Traversal.Traversal' (or 'Just' the result--- from a 'Getter' or 'Lens'). See also ('^?').------ @'Data.Maybe.listToMaybe' '.' 'toList' ≡ 'preview' 'folded'@------ This is usually applied in the reader monad @(->) s@.------ @--- 'preview' :: 'Getter' s a           -> s -> 'Maybe' a--- 'preview' :: 'Fold' s a             -> s -> 'Maybe' a--- 'preview' :: 'Simple' 'Lens' s a      -> s -> 'Maybe' a--- 'preview' :: 'Simple' 'Control.Lens.Iso.Iso' s a       -> s -> 'Maybe' a--- 'preview' :: 'Simple' 'Control.Lens.Traversal.Traversal' s a -> s -> 'Maybe' a--- @------ However, it may be useful to think of its full generality when working with--- a monad transformer stack:------ @--- 'preview' :: MonadReader s m => 'Getter' s a           -> m ('Maybe' a)--- 'preview' :: MonadReader s m => 'Fold' s a             -> m ('Maybe' a)--- 'preview' :: MonadReader s m => 'Simple' 'Lens' s a      -> m ('Maybe' a)--- 'preview' :: MonadReader s m => 'Simple' 'Control.Lens.Iso.Iso' s a       -> m ('Maybe' a)--- 'preview' :: MonadReader s m => 'Simple' 'Control.Lens.Traversal.Traversal' s a -> m ('Maybe' a)--- @-preview :: MonadReader s m => Getting (First a) s t a b -> m (Maybe a)-preview l = asks (getFirst# (foldMapOf l (first# Just)))-{-# INLINE preview #-}---- | Retrieve a function of the first value targeted by a 'Fold' or--- 'Control.Lens.Traversal.Traversal' (or 'Just' the result from a 'Getter' or 'Lens').------ This is usually applied in the reader monad @(->) s@.------ @--- 'previews' :: 'Getter' s a           -> (a -> r) -> s -> 'Maybe' a--- 'previews' :: 'Fold' s a             -> (a -> r) -> s -> 'Maybe' a--- 'previews' :: 'Simple' 'Lens' s a      -> (a -> r) -> s -> 'Maybe' a--- 'previews' :: 'Simple' 'Control.Lens.Iso.Iso' s a       -> (a -> r) -> s -> 'Maybe' a--- 'previews' :: 'Simple' 'Control.Lens.Traversal.Traversal' s a -> (a -> r) -> s -> 'Maybe' a--- @------ However, it may be useful to think of its full generality when working with--- a monad transformer stack:------ @--- 'previews' :: MonadReader s m => 'Getter' s a           -> (a -> r) -> m ('Maybe' r)--- 'previews' :: MonadReader s m => 'Fold' s a             -> (a -> r) -> m ('Maybe' r)--- 'previews' :: MonadReader s m => 'Simple' 'Lens' s a      -> (a -> r) -> m ('Maybe' r)--- 'previews' :: MonadReader s m => 'Simple' 'Control.Lens.Iso.Iso' s a       -> (a -> r) -> m ('Maybe' r)--- 'previews' :: MonadReader s m => 'Simple' 'Control.Lens.Traversal.Traversal' s a -> (a -> r) -> m ('Maybe' r)--- @-previews :: MonadReader s m => Getting (First r) s t a b -> (a -> r) -> m (Maybe r)-previews l f = asks (getFirst# (foldMapOf l (first# (Just . f))))-{-# INLINE previews #-}------------------------------------------------------------------------------------ Preuse----------------------------------------------------------------------------------- | Retrieve the first value targeted by a 'Fold' or 'Control.Lens.Traversal.Traversal' (or 'Just' the result--- from a 'Getter' or 'Lens') into the current state.------ @--- 'preuse' :: MonadState s m => 'Getter' s a           -> m ('Maybe' a)--- 'preuse' :: MonadState s m => 'Fold' s a             -> m ('Maybe' a)--- 'preuse' :: MonadState s m => 'Simple' 'Lens' s a      -> m ('Maybe' a)--- 'preuse' :: MonadState s m => 'Simple' 'Control.Lens.Iso.Iso' s a       -> m ('Maybe' a)--- 'preuse' :: MonadState s m => 'Simple' 'Control.Lens.Traversal.Traversal' s a -> m ('Maybe' a)--- @-preuse :: MonadState s m => Getting (First a) s t a b -> m (Maybe a)-preuse l = gets (getFirst# (foldMapOf l (first# Just)))-{-# INLINE preuse #-}---- | Retrieve a function of the first value targeted by a 'Fold' or--- 'Control.Lens.Traversal.Traversal' (or 'Just' the result from a 'Getter' or 'Lens') into the current state.------ @--- 'preuses' :: MonadState s m => 'Getter' s a           -> (a -> r) -> m ('Maybe' r)--- 'preuses' :: MonadState s m => 'Fold' s a             -> (a -> r) -> m ('Maybe' r)--- 'preuses' :: MonadState s m => 'Simple' 'Lens' s a      -> (a -> r) -> m ('Maybe' r)--- 'preuses' :: MonadState s m => 'Simple' 'Control.Lens.Iso.Iso' s a       -> (a -> r) -> m ('Maybe' r)--- 'preuses' :: MonadState s m => 'Simple' 'Control.Lens.Traversal.Traversal' s a -> (a -> r) -> m ('Maybe' r)--- @-preuses :: MonadState s m => Getting (First r) s t a b -> (a -> r) -> m (Maybe r)-preuses l f = gets (getFirst# (foldMapOf l (first# (Just . f))))-{-# INLINE preuses #-}+{-# LANGUAGE Rank2Types #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+#ifdef TRUSTWORTHY+{-# LANGUAGE Trustworthy #-}+#endif+----------------------------------------------------------------------------+-- |+-- Module      :  Control.Lens.Fold+-- Copyright   :  (C) 2012-13 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  provisional+-- Portability :  Rank2Types+--+-- A @'Fold' s a@ is a generalization of something 'Foldable'. It allows+-- you to extract multiple results from a container. A 'Foldable' container+-- can be characterized by the behavior of+-- @'Data.Foldable.foldMap' :: ('Foldable' t, 'Monoid' m) => (a -> m) -> t a -> m@.+-- Since we want to be able to work with monomorphic containers, we could+-- generalize this signature to @forall m. 'Monoid' m => (a -> m) -> s -> m@,+-- and then decorate it with 'Accessor' to obtain+--+-- @type 'Fold' s a = forall m. 'Monoid' m => 'Getting' m s s a a@+--+-- Every 'Getter' is a valid 'Fold' that simply doesn't use the 'Monoid'+-- it is passed.+--+-- In practice the type we use is slightly more complicated to allow for+-- better error messages and for it to be transformed by certain+-- 'Applicative' transformers.+--+-- Everything you can do with a 'Foldable' container, you can with with a 'Fold' and there are+-- combinators that generalize the usual 'Foldable' operations here.+----------------------------------------------------------------------------+module Control.Lens.Fold+  (+  -- * Folds+    Fold+  , IndexedFold++  -- * Getting Started+  , (^..)+  , (^?)+  , (^?!)+  , pre, ipre+  , preview, previews, ipreview, ipreviews+  , preuse, preuses, ipreuse, ipreuses++  , has, hasn't++  -- ** Building Folds+  , folding+  , folded+  , unfolded+  , iterated+  , filtered+  , backwards+  , repeated+  , replicated+  , cycled+  , takingWhile+  , droppingWhile++  -- ** Folding+  , foldMapOf, foldOf+  , foldrOf, foldlOf+  , toListOf+  , anyOf, allOf+  , andOf, orOf+  , productOf, sumOf+  , traverseOf_, forOf_, sequenceAOf_+  , mapMOf_, forMOf_, sequenceOf_+  , asumOf, msumOf+  , concatMapOf, concatOf+  , elemOf, notElemOf+  , lengthOf+  , nullOf, notNullOf+  , firstOf, lastOf+  , maximumOf, minimumOf+  , maximumByOf, minimumByOf+  , findOf+  , foldrOf', foldlOf'+  , foldr1Of, foldl1Of+  , foldr1Of', foldl1Of'+  , foldrMOf, foldlMOf++  -- * Indexed Folds+  , (^@..)+  , (^@?)+  , (^@?!)++  -- ** Indexed Folding+  , ifoldMapOf+  , ifoldrOf+  , ifoldlOf+  , ianyOf+  , iallOf+  , itraverseOf_+  , iforOf_+  , imapMOf_+  , iforMOf_+  , iconcatMapOf+  , ifindOf+  , ifoldrOf'+  , ifoldlOf'+  , ifoldrMOf+  , ifoldlMOf+  , itoListOf++  -- ** Building Indexed Folds+  , ifiltered+  , itakingWhile+  , idroppingWhile++  -- * Deprecated+  , headOf++  -- * Internal types+  , Leftmost+  , Rightmost+  , Traversed+  , Sequenced+  ) where++import Control.Applicative as Applicative+import Control.Applicative.Backwards+import Control.Comonad+import Control.Lens.Getter+import Control.Lens.Internal.Fold+import Control.Lens.Internal.Getter+import Control.Lens.Internal.Indexed+import Control.Lens.Internal.Magma+import Control.Lens.Type+import Control.Monad+import Control.Monad.Reader+import Control.Monad.State+import Data.Foldable as Foldable+import Data.Functor.Compose+import Data.Maybe+import Data.Monoid+import Data.Profunctor+import Data.Profunctor.Rep+import Data.Profunctor.Unsafe+import Data.Traversable++-- $setup+-- >>> import Control.Lens+-- >>> import Data.List.Lens+-- >>> import Debug.SimpleReflect.Expr+-- >>> import Debug.SimpleReflect.Vars as Vars hiding (f,g)+-- >>> let f :: Expr -> Expr; f = Debug.SimpleReflect.Vars.f+-- >>> let g :: Expr -> Expr; g = Debug.SimpleReflect.Vars.g+-- >>> import Control.DeepSeq (NFData (..), force)+-- >>> import Control.Exception (evaluate)+-- >>> import Data.Maybe (fromMaybe)+-- >>> import System.Timeout (timeout)+-- >>> let timingOut :: NFData a => a -> IO a; timingOut = fmap (fromMaybe (error "timeout")) . timeout (5*10^6) . evaluate . force++{-# ANN module "HLint: ignore Eta reduce" #-}+{-# ANN module "HLint: ignore Use camelCase" #-}+{-# ANN module "HLint: ignore Use curry" #-}++infixl 8 ^.., ^?, ^?!, ^@.., ^@?, ^@?!++--------------------------+-- Folds+--------------------------++-- | Obtain a 'Fold' by lifting an operation that returns a 'Foldable' result.+--+-- This can be useful to lift operations from @Data.List@ and elsewhere into a 'Fold'.+--+-- >>> [1,2,3,4]^..folding tail+-- [2,3,4]+folding :: (Foldable f, Applicative g, Gettable g) => (s -> f a) -> LensLike g s t a b+folding sfa agb = coerce . traverse_ agb . sfa+{-# INLINE folding #-}++-- | Obtain a 'Fold' from any 'Foldable'.+--+-- >>> Just 3^..folded+-- [3]+--+-- >>> Nothing^..folded+-- []+--+-- >>> [(1,2),(3,4)]^..folded.both+-- [1,2,3,4]+folded :: Foldable f => Fold (f a) a+folded f = coerce . getFolding . foldMap (Folding #. f)+{-# INLINE folded #-}++-- | 'Fold' by repeating the input forever.+--+-- @+-- 'repeat' ≡ 'toListOf' 'repeated'+-- @+--+-- >>> timingOut $ 5^..taking 20 repeated+-- [5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5]+repeated :: Fold a a+repeated f a = as where as = f a *> as+{-# INLINE repeated #-}++-- | A 'Fold' that replicates its input @n@ times.+--+-- @+-- 'replicate' n ≡ 'toListOf' ('replicated' n)+-- @+--+-- >>> 5^..replicated 20+-- [5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5]+replicated :: Int -> Fold a a+replicated n0 f a = go n0 where+  m = f a+  go 0 = noEffect+  go n = m *> go (n - 1)+{-# INLINE replicated #-}++-- | Transform a 'Fold' into a 'Fold' that loops over its elements over and over.+--+-- >>> timingOut $ [1,2,3]^..taking 7 (cycled traverse)+-- [1,2,3,1,2,3,1]+cycled :: (Applicative f, Gettable f) => LensLike f s t a b -> LensLike f s t a b+cycled l f a = as where as = l f a *> as+{-# INLINE cycled #-}++-- | Build a 'Fold' that unfolds its values from a seed.+--+-- @+-- 'Prelude.unfoldr' ≡ 'toListOf' '.' 'unfolded'+-- @+--+-- >>> 10^..unfolded (\b -> if b == 0 then Nothing else Just (b, b-1))+-- [10,9,8,7,6,5,4,3,2,1]+unfolded :: (b -> Maybe (a, b)) -> Fold b a+unfolded f g b0 = go b0 where+  go b = case f b of+    Just (a, b') -> g a *> go b'+    Nothing      -> noEffect+{-# INLINE unfolded #-}++-- | @x '^.' 'iterated' f@ returns an infinite 'Fold' of repeated applications of @f@ to @x@.+--+-- @+-- 'toListOf' ('iterated' f) a ≡ 'iterate' f a+-- @+iterated :: (a -> a) -> Fold a a+iterated f g a0 = go a0 where+  go a = g a *> go (f a)+{-# INLINE iterated #-}++-- | Obtain a 'Fold' that can be composed with to filter another 'Lens', 'Iso', 'Getter', 'Fold' (or 'Traversal').+--+-- Note: This is /not/ a legal 'Traversal', unless you are very careful not to invalidate the predicate on the target.+--+-- Note: This is also /not/ a legal 'Prism', unless you are very careful not to inject a value that matches the predicate.+--+-- As a counter example, consider that given @evens = 'filtered' 'even'@ the second 'Traversal' law is violated:+--+-- @+-- 'Control.Lens.Setter.over' evens 'succ' '.' 'Control.Lens.Setter.over' evens 'succ' '/=' 'Control.Lens.Setter.over' evens ('succ' '.' 'succ')+-- @+--+-- So, in order for this to qualify as a legal 'Traversal' you can only use it for actions that preserve the result of the predicate!+--+-- >>> [1..10]^..folded.filtered even+-- [2,4,6,8,10]+--+-- This will preserve an index if it is present.+filtered :: (Choice p, Applicative f) => (a -> Bool) -> Overloaded' p f a a+filtered p = dimap (\x -> if p x then Right x else Left x) (either pure id) . right'+{-# INLINE filtered #-}++-- | Obtain a 'Fold' by taking elements from another 'Fold', 'Lens', 'Iso', 'Getter' or 'Traversal' while a predicate holds.+--+-- @+-- 'takeWhile' p ≡ 'toListOf' ('takingWhile' p 'folded')+-- @+--+-- >>> timingOut $ toListOf (takingWhile (<=3) folded) [1..]+-- [1,2,3]+--+-- @+-- 'takingWhile' :: (a -> 'Bool') -> 'Fold' s a                         -> 'Fold' s a+-- 'takingWhile' :: (a -> 'Bool') -> 'Getter' s a                       -> 'Fold' s a+-- 'takingWhile' :: (a -> 'Bool') -> 'Traversal'' s a                   -> 'Fold' s a -- * See note below+-- 'takingWhile' :: (a -> 'Bool') -> 'Lens'' s a                        -> 'Fold' s a -- * See note below+-- 'takingWhile' :: (a -> 'Bool') -> 'Prism'' s a                       -> 'Fold' s a -- * See note below+-- 'takingWhile' :: (a -> 'Bool') -> 'Iso'' s a                         -> 'Fold' s a -- * See note below+-- 'takingWhile' :: (a -> 'Bool') -> 'Action' m s a                     -> 'MonadicFold' m s a+-- 'takingWhile' :: (a -> 'Bool') -> 'MonadicFold' m s a                -> 'MonadicFold' m s a+-- 'takingWhile' :: (a -> 'Bool') -> 'IndexedTraversal'' i s a          -> 'IndexedFold' i s a -- * See note below+-- 'takingWhile' :: (a -> 'Bool') -> 'IndexedLens'' i s a               -> 'IndexedFold' i s a -- * See note below+-- 'takingWhile' :: (a -> 'Bool') -> 'IndexedFold' i s a                -> 'IndexedFold' i s a+-- 'takingWhile' :: (a -> 'Bool') -> 'IndexedGetter' i s a              -> 'IndexedFold' i s a+-- 'takingWhile' :: (a -> 'Bool') -> 'IndexedAction' i m s a            -> 'IndexedMonadicFold' i m s a+-- 'takingWhile' :: (a -> 'Bool') -> 'IndexedMonadicFold' i m s a       -> 'IndexedMonadicFold' i m s a+-- @+--+-- /Note:/ When applied to a 'Traversal', 'takingWhile' yields something that can be used as if it were a 'Traversal', but+-- which is not a 'Traversal' per the laws, unless you are careful to ensure that you do not invalidate the predicate when+-- writing back through it.+takingWhile :: (Conjoined p, Applicative f) => (a -> Bool) -> Over p (TakingWhile p f a a) s t a a -> Over p f s t a a+takingWhile p l pafb = fmap runMagma . traverse (corep pafb) . runTakingWhile . l flag where+  flag = cotabulate $ \wa -> let a = extract wa; r = p a in TakingWhile r a $ \pr ->+    if pr && r then Magma () wa else MagmaPure a+{-# INLINE takingWhile #-}++-- | Obtain a 'Fold' by dropping elements from another 'Fold', 'Lens', 'Iso', 'Getter' or 'Traversal' while a predicate holds.+--+-- @+-- 'dropWhile' p ≡ 'toListOf' ('droppingWhile' p 'folded')+-- @+--+-- >>> toListOf (droppingWhile (<=3) folded) [1..6]+-- [4,5,6]+--+-- >>> toListOf (droppingWhile (<=3) folded) [1,6,1]+-- [6,1]+--+-- @+-- 'droppingWhile' :: (a -> 'Bool') -> 'Fold' s a                         -> 'Fold' s a+-- 'droppingWhile' :: (a -> 'Bool') -> 'Getter' s a                       -> 'Fold' s a+-- 'droppingWhile' :: (a -> 'Bool') -> 'Traversal'' s a                   -> 'Fold' s a                -- see notes+-- 'droppingWhile' :: (a -> 'Bool') -> 'Lens'' s a                        -> 'Fold' s a                -- see notes+-- 'droppingWhile' :: (a -> 'Bool') -> 'Prism'' s a                       -> 'Fold' s a                -- see notes+-- 'droppingWhile' :: (a -> 'Bool') -> 'Iso'' s a                         -> 'Fold' s a                -- see notes+-- @+--+-- @+-- 'droppingWhile' :: (a -> 'Bool') -> 'IndexPreservingTraversal'' s a    -> 'IndexPreservingFold' s a -- see notes+-- 'droppingWhile' :: (a -> 'Bool') -> 'IndexPreservingLens'' s a         -> 'IndexPreservingFold' s a -- see notes+-- 'droppingWhile' :: (a -> 'Bool') -> 'IndexPreservingGetter' s a        -> 'IndexPreservingFold' s a+-- 'droppingWhile' :: (a -> 'Bool') -> 'IndexPreservingFold' s a          -> 'IndexPreservingFold' s a+-- 'droppingWhile' :: (a -> 'Bool') -> 'IndexPreservingAction' m s a      -> 'IndexPreservingFold' m s a+-- @+--+-- @+-- 'droppingWhile' :: (a -> 'Bool') -> 'IndexPreservingMonadicFold' m s a -> 'IndexPreservingMonadicFold' m s a+-- @+--+-- @+-- 'droppingWhile' :: (a -> 'Bool') -> 'IndexedTraversal'' i s a          -> 'IndexedFold' i s a       -- see notes+-- 'droppingWhile' :: (a -> 'Bool') -> 'IndexedLens'' i s a               -> 'IndexedFold' i s a       -- see notes+-- 'droppingWhile' :: (a -> 'Bool') -> 'IndexedGetter' i s a              -> 'IndexedFold' i s a+-- 'droppingWhile' :: (a -> 'Bool') -> 'IndexedFold' i s a                -> 'IndexedFold' i s a+-- 'droppingWhile' :: (a -> 'Bool') -> 'IndexedAction' i m s a            -> 'IndexedFold' i m s a+-- @+--+-- @+-- 'droppingWhile' :: (a -> 'Bool') -> 'IndexedMonadicFold' i m s a       -> 'IndexedMonadicFold' i m s a+-- @+--+-- Note: Many uses of this combinator will yield something that meets the types, but not the laws of a valid+-- 'Traversal' or 'IndexedTraversal'. The 'Traversal' and 'IndexedTraversal' laws are only satisfied if the+-- new values you assign also pass the predicate! Otherwise subsequent traversals will visit fewer elements+-- and 'Traversal' fusion is not sound.+droppingWhile :: (Conjoined p, Profunctor q, Applicative f)+              => (a -> Bool)+              -> Overloading p q (Compose (State Bool) f) s t a a+              -> Overloading p q f s t a a+droppingWhile p l f = (flip evalState True .# getCompose) `rmap` l g where+  g = cotabulate $ \wa -> Compose $ state $ \b -> let+      a = extract wa+      b' = b && p a+    in (if b' then pure a else corep f wa, b')+{-# INLINE droppingWhile #-}++--------------------------+-- Fold/Getter combinators+--------------------------++-- | @+-- 'Data.Foldable.foldMap' = 'foldMapOf' 'folded'+-- @+--+-- @+-- 'foldMapOf' ≡ 'views'+-- 'ifoldMapOf' l = 'foldMapOf' l '.' 'Indexed'+-- @+--+-- @+-- 'foldMapOf' ::             'Getter' s a     -> (a -> r) -> s -> r+-- 'foldMapOf' :: 'Monoid' r => 'Fold' s a       -> (a -> r) -> s -> r+-- 'foldMapOf' ::             'Lens'' s a      -> (a -> r) -> s -> r+-- 'foldMapOf' ::             'Iso'' s a       -> (a -> r) -> s -> r+-- 'foldMapOf' :: 'Monoid' r => 'Traversal'' s a -> (a -> r) -> s -> r+-- 'foldMapOf' :: 'Monoid' r => 'Prism'' s a     -> (a -> r) -> s -> r+-- @+--+-- @+-- 'foldMapOf' :: 'Getting' r s t a b -> (a -> r) -> s -> r+-- @+foldMapOf :: Profunctor p => Accessing p r s t a b -> p a r -> s -> r+foldMapOf l f = runAccessor #. l (Accessor #. f)+{-# INLINE foldMapOf #-}++-- | @+-- 'Data.Foldable.fold' = 'foldOf' 'folded'+-- @+--+-- @+-- 'foldOf' ≡ 'view'+-- @+--+-- @+-- 'foldOf' ::             'Getter' s m     -> s -> m+-- 'foldOf' :: 'Monoid' m => 'Fold' s m       -> s -> m+-- 'foldOf' ::             'Lens'' s m      -> s -> m+-- 'foldOf' ::             'Iso'' s m       -> s -> m+-- 'foldOf' :: 'Monoid' m => 'Traversal'' s m -> s -> m+-- 'foldOf' :: 'Monoid' m => 'Prism'' s m     -> s -> m+-- @+foldOf :: Getting a s t a b -> s -> a+foldOf l = runAccessor #. l Accessor+{-# INLINE foldOf #-}++-- | Right-associative fold of parts of a structure that are viewed through a 'Lens', 'Getter', 'Fold' or 'Traversal'.+--+-- @+-- 'Data.Foldable.foldr' ≡ 'foldrOf' 'folded'+-- @+--+-- @+-- 'foldrOf' :: 'Getter' s a     -> (a -> r -> r) -> r -> s -> r+-- 'foldrOf' :: 'Fold' s a       -> (a -> r -> r) -> r -> s -> r+-- 'foldrOf' :: 'Lens'' s a      -> (a -> r -> r) -> r -> s -> r+-- 'foldrOf' :: 'Iso'' s a       -> (a -> r -> r) -> r -> s -> r+-- 'foldrOf' :: 'Traversal'' s a -> (a -> r -> r) -> r -> s -> r+-- 'foldrOf' :: 'Prism'' s a     -> (a -> r -> r) -> r -> s -> r+-- @+--+-- @+-- 'ifoldrOf' l ≡ 'foldrOf' l '.' 'Indexed'+-- @+--+-- @+-- 'foldrOf' :: 'Getting' ('Endo' r) s t a b -> (a -> r -> r) -> r -> s -> r+-- @+foldrOf :: Profunctor p => Accessing p (Endo r) s t a b -> p a (r -> r) -> r -> s -> r+foldrOf l f z = flip appEndo z `rmap` foldMapOf l (Endo #. f)+{-# INLINE foldrOf #-}++-- | Left-associative fold of the parts of a structure that are viewed through a 'Lens', 'Getter', 'Fold' or 'Traversal'.+--+-- @+-- 'Data.Foldable.foldl' ≡ 'foldlOf' 'folded'+-- @+--+-- @+-- 'foldlOf' :: 'Getter' s a     -> (r -> a -> r) -> r -> s -> r+-- 'foldlOf' :: 'Fold' s a       -> (r -> a -> r) -> r -> s -> r+-- 'foldlOf' :: 'Lens'' s a      -> (r -> a -> r) -> r -> s -> r+-- 'foldlOf' :: 'Iso'' s a       -> (r -> a -> r) -> r -> s -> r+-- 'foldlOf' :: 'Traversal'' s a -> (r -> a -> r) -> r -> s -> r+-- 'foldlOf' :: 'Prism'' s a     -> (r -> a -> r) -> r -> s -> r+-- @+foldlOf :: Getting (Dual (Endo r)) s t a b -> (r -> a -> r) -> r -> s -> r+foldlOf l f z = (flip appEndo z .# getDual) `rmap` foldMapOf l (Dual #. Endo #. flip f)+{-# INLINE foldlOf #-}++-- | Extract a list of the targets of a 'Fold'. See also ('^..').+--+-- @+-- 'Data.Foldable.toList' ≡ 'toListOf' 'folded'+-- ('^..') ≡ 'flip' 'toListOf'+-- @++-- >>> toListOf both ("hello","world")+-- ["hello","world"]+--+-- @+-- 'toListOf' :: 'Getter' s a     -> s -> [a]+-- 'toListOf' :: 'Fold' s a       -> s -> [a]+-- 'toListOf' :: 'Lens'' s a      -> s -> [a]+-- 'toListOf' :: 'Iso'' s a       -> s -> [a]+-- 'toListOf' :: 'Traversal'' s a -> s -> [a]+-- 'toListOf' :: 'Prism'' s a     -> s -> [a]+-- @+toListOf :: Getting (Endo [a]) s t a b -> s -> [a]+toListOf l = foldrOf l (:) []+{-# INLINE toListOf #-}++-- | A convenient infix (flipped) version of 'toListOf'.+--+-- >>> [[1,2],[3]]^..traverse.traverse+-- [1,2,3]+--+-- >>> (1,2)^..both+-- [1,2]+--+-- @+-- 'Data.Foldable.toList' xs ≡ xs '^..' 'folded'+-- ('^..') ≡ 'flip' 'toListOf'+-- @+--+-- @+-- ('^..') :: s -> 'Getter' s a     -> [a]+-- ('^..') :: s -> 'Fold' s a       -> [a]+-- ('^..') :: s -> 'Lens'' s a      -> [a]+-- ('^..') :: s -> 'Iso'' s a       -> [a]+-- ('^..') :: s -> 'Traversal'' s a -> [a]+-- ('^..') :: s -> 'Prism'' s a     -> [a]+-- @+(^..) :: s -> Getting (Endo [a]) s t a b -> [a]+s ^.. l = toListOf l s+{-# INLINE (^..) #-}++-- | Returns 'True' if every target of a 'Fold' is 'True'.+--+-- >>> andOf both (True,False)+-- False+-- >>> andOf both (True,True)+-- True+--+-- @+-- 'Data.Foldable.and' ≡ 'andOf' 'folded'+-- @+--+-- @+-- 'andOf' :: 'Getter' s 'Bool'     -> s -> 'Bool'+-- 'andOf' :: 'Fold' s 'Bool'       -> s -> 'Bool'+-- 'andOf' :: 'Lens'' s 'Bool'      -> s -> 'Bool'+-- 'andOf' :: 'Iso'' s 'Bool'       -> s -> 'Bool'+-- 'andOf' :: 'Traversal'' s 'Bool' -> s -> 'Bool'+-- 'andOf' :: 'Prism'' s 'Bool'     -> s -> 'Bool'+-- @+andOf :: Getting All s t Bool b -> s -> Bool+andOf l = getAll #. foldMapOf l All+{-# INLINE andOf #-}++-- | Returns 'True' if any target of a 'Fold' is 'True'.+--+-- >>> orOf both (True,False)+-- True+-- >>> orOf both (False,False)+-- False+--+-- @+-- 'Data.Foldable.or' ≡ 'orOf' 'folded'+-- @+--+-- @+-- 'orOf' :: 'Getter' s 'Bool'     -> s -> 'Bool'+-- 'orOf' :: 'Fold' s 'Bool'       -> s -> 'Bool'+-- 'orOf' :: 'Lens'' s 'Bool'      -> s -> 'Bool'+-- 'orOf' :: 'Iso'' s 'Bool'       -> s -> 'Bool'+-- 'orOf' :: 'Traversal'' s 'Bool' -> s -> 'Bool'+-- 'orOf' :: 'Prism'' s 'Bool'     -> s -> 'Bool'+-- @+orOf :: Getting Any s t Bool b -> s -> Bool+orOf l = getAny #. foldMapOf l Any+{-# INLINE orOf #-}++-- | Returns 'True' if any target of a 'Fold' satisfies a predicate.+--+-- >>> anyOf both (=='x') ('x','y')+-- True+-- >>> import Data.Data.Lens+-- >>> anyOf biplate (== "world") (((),2::Int),"hello",("world",11))+-- True+--+-- @+-- 'Data.Foldable.any' ≡ 'anyOf' 'folded'+-- @+--+-- @+-- 'ianyOf' l ≡ 'allOf' l '.' 'Indexed'+-- @+--+-- @+-- 'anyOf' :: 'Getter' s a     -> (a -> 'Bool') -> s -> 'Bool'+-- 'anyOf' :: 'Fold' s a       -> (a -> 'Bool') -> s -> 'Bool'+-- 'anyOf' :: 'Lens'' s a      -> (a -> 'Bool') -> s -> 'Bool'+-- 'anyOf' :: 'Iso'' s a       -> (a -> 'Bool') -> s -> 'Bool'+-- 'anyOf' :: 'Traversal'' s a -> (a -> 'Bool') -> s -> 'Bool'+-- 'anyOf' :: 'Prism'' s a     -> (a -> 'Bool') -> s -> 'Bool'+-- @+anyOf :: Profunctor p => Accessing p Any s t a b -> p a Bool -> s -> Bool+anyOf l f = getAny #. foldMapOf l (Any #. f)+{-# INLINE anyOf #-}++-- | Returns 'True' if every target of a 'Fold' satisfies a predicate.+--+-- >>> allOf both (>=3) (4,5)+-- True+-- >>> allOf folded (>=2) [1..10]+-- False+--+-- @+-- 'Data.Foldable.all' ≡ 'allOf' 'folded'+-- @+--+-- @+-- 'iallOf' l = 'allOf' l '.' 'Indexed'+-- @+--+-- @+-- 'allOf' :: 'Getter' s a     -> (a -> 'Bool') -> s -> 'Bool'+-- 'allOf' :: 'Fold' s a       -> (a -> 'Bool') -> s -> 'Bool'+-- 'allOf' :: 'Lens'' s a      -> (a -> 'Bool') -> s -> 'Bool'+-- 'allOf' :: 'Iso'' s a       -> (a -> 'Bool') -> s -> 'Bool'+-- 'allOf' :: 'Traversal'' s a -> (a -> 'Bool') -> s -> 'Bool'+-- 'allOf' :: 'Prism'' s a     -> (a -> 'Bool') -> s -> 'Bool'+-- @+allOf :: Profunctor p => Accessing p All s t a b -> p a Bool -> s -> Bool+allOf l f = getAll #. foldMapOf l (All #. f)+{-# INLINE allOf #-}++-- | Calculate the 'Product' of every number targeted by a 'Fold'.+--+-- >>> productOf both (4,5)+-- 20+-- >>> productOf folded [1,2,3,4,5]+-- 120+--+-- @+-- 'Data.Foldable.product' ≡ 'productOf' 'folded'+-- @++-- This operation may be more strict than you would expect. If you+-- want a lazier version use @'ala' 'Sum' '.' 'foldMapOf'@+--+-- @+-- 'productOf' :: 'Num' a => 'Getter' s a     -> s -> a+-- 'productOf' :: 'Num' a => 'Fold' s a       -> s -> a+-- 'productOf' :: 'Num' a => 'Lens'' s a      -> s -> a+-- 'productOf' :: 'Num' a => 'Iso'' s a       -> s -> a+-- 'productOf' :: 'Num' a => 'Traversal'' s a -> s -> a+-- 'productOf' :: 'Num' a => 'Prism'' s a     -> s -> a+-- @+productOf :: Num a => Getting (Endo (Endo a)) s t a b -> s -> a+productOf l = foldlOf' l (*) 1+{-# INLINE productOf #-}++-- | Calculate the 'Sum' of every number targeted by a 'Fold'.+--+-- >>> sumOf both (5,6)+-- 11+-- >>> sumOf folded [1,2,3,4]+-- 10+-- >>> sumOf (folded.both) [(1,2),(3,4)]+-- 10+-- >>> import Data.Data.Lens+-- >>> sumOf biplate [(1::Int,[]),(2,[(3::Int,4::Int)])] :: Int+-- 10+--+-- @+-- 'Data.Foldable.sum' ≡ 'sumOf' 'folded'+-- @+--+-- This operation may be more strict than you would expect. If you+-- want a lazier version use @'ala' 'Sum' '.' 'foldMapOf'@+--+-- @+-- 'sumOf' '_1' :: (a, b) -> a+-- 'sumOf' ('folded' '.' 'Control.Lens.Tuple._1') :: ('Foldable' f, 'Num' a) => f (a, b) -> a+-- @+--+-- @+-- 'sumOf' :: 'Num' a => 'Getter' s a     -> s -> a+-- 'sumOf' :: 'Num' a => 'Fold' s a       -> s -> a+-- 'sumOf' :: 'Num' a => 'Lens'' s a      -> s -> a+-- 'sumOf' :: 'Num' a => 'Iso'' s a       -> s -> a+-- 'sumOf' :: 'Num' a => 'Traversal'' s a -> s -> a+-- 'sumOf' :: 'Num' a => 'Prism'' s a     -> s -> a+-- @+sumOf :: Num a => Getting (Endo (Endo a)) s t a b -> s -> a+sumOf l = foldlOf' l (+) 0+{-# INLINE sumOf #-}++-- | Traverse over all of the targets of a 'Fold' (or 'Getter'), computing an 'Applicative' (or 'Functor')-based answer,+-- but unlike 'Control.Lens.Traversal.traverseOf' do not construct a new structure. 'traverseOf_' generalizes+-- 'Data.Foldable.traverse_' to work over any 'Fold'.+--+-- When passed a 'Getter', 'traverseOf_' can work over any 'Functor', but when passed a 'Fold', 'traverseOf_' requires+-- an 'Applicative'.+--+-- >>> traverseOf_ both putStrLn ("hello","world")+-- hello+-- world+--+-- @+-- 'Data.Foldable.traverse_' ≡ 'traverseOf_' 'folded'+-- @+--+-- @+-- 'traverseOf_' '_2' :: 'Functor' f => (c -> f r) -> (d, c) -> f ()+-- 'traverseOf_' 'Data.Either.Lens.traverseLeft' :: 'Applicative' f => (a -> f b) -> 'Either' a c -> f ()+-- @+--+-- @+-- 'itraverseOf_' l ≡ 'traverseOf_' l '.' 'Indexed'+-- @+--+-- The rather specific signature of 'traverseOf_' allows it to be used as if the signature was any of:+--+-- @+-- 'traverseOf_' :: 'Functor' f     => 'Getter' s a     -> (a -> f r) -> s -> f ()+-- 'traverseOf_' :: 'Applicative' f => 'Fold' s a       -> (a -> f r) -> s -> f ()+-- 'traverseOf_' :: 'Functor' f     => 'Lens'' s a      -> (a -> f r) -> s -> f ()+-- 'traverseOf_' :: 'Functor' f     => 'Iso'' s a       -> (a -> f r) -> s -> f ()+-- 'traverseOf_' :: 'Applicative' f => 'Traversal'' s a -> (a -> f r) -> s -> f ()+-- 'traverseOf_' :: 'Applicative' f => 'Prism'' s a     -> (a -> f r) -> s -> f ()+-- @+traverseOf_ :: (Profunctor p, Functor f) => Accessing p (Traversed r f) s t a b -> p a (f r) -> s -> f ()+traverseOf_ l f = void . getTraversed #. foldMapOf l (Traversed #. f)+{-# INLINE traverseOf_ #-}++-- | Traverse over all of the targets of a 'Fold' (or 'Getter'), computing an 'Applicative' (or 'Functor')-based answer,+-- but unlike 'Control.Lens.Traversal.forOf' do not construct a new structure. 'forOf_' generalizes+-- 'Data.Foldable.for_' to work over any 'Fold'.+--+-- When passed a 'Getter', 'forOf_' can work over any 'Functor', but when passed a 'Fold', 'forOf_' requires+-- an 'Applicative'.+--+-- @+-- 'for_' ≡ 'forOf_' 'folded'+-- @+--+-- The rather specific signature of 'forOf_' allows it to be used as if the signature was any of:+--+-- @+-- 'iforOf_' l s ≡ 'forOf_' l s '.' 'Indexed'+-- @+--+-- @+-- 'forOf_' :: 'Functor' f     => 'Getter' s a     -> s -> (a -> f r) -> f ()+-- 'forOf_' :: 'Applicative' f => 'Fold' s a       -> s -> (a -> f r) -> f ()+-- 'forOf_' :: 'Functor' f     => 'Lens'' s a      -> s -> (a -> f r) -> f ()+-- 'forOf_' :: 'Functor' f     => 'Iso'' s a       -> s -> (a -> f r) -> f ()+-- 'forOf_' :: 'Applicative' f => 'Traversal'' s a -> s -> (a -> f r) -> f ()+-- 'forOf_' :: 'Applicative' f => 'Prism'' s a     -> s -> (a -> f r) -> f ()+-- @+forOf_ :: (Profunctor p, Functor f) => Accessing p (Traversed r f) s t a b -> s -> p a (f r) -> f ()+forOf_ = flip . traverseOf_+{-# INLINE forOf_ #-}++-- | Evaluate each action in observed by a 'Fold' on a structure from left to right, ignoring the results.+--+-- @+-- 'sequenceA_' ≡ 'sequenceAOf_' 'folded'+-- @+--+-- @+-- 'sequenceAOf_' :: 'Functor' f     => 'Getter' s (f a)     -> s -> f ()+-- 'sequenceAOf_' :: 'Applicative' f => 'Fold' s (f a)       -> s -> f ()+-- 'sequenceAOf_' :: 'Functor' f     => 'Lens'' s (f a)      -> s -> f ()+-- 'sequenceAOf_' :: 'Functor' f     => 'Iso'' s (f a)       -> s -> f ()+-- 'sequenceAOf_' :: 'Applicative' f => 'Traversal'' s (f a) -> s -> f ()+-- 'sequenceAOf_' :: 'Applicative' f => 'Prism'' s (f a)     -> s -> f ()+-- @+sequenceAOf_ :: Functor f => Getting (Traversed a f) s t (f a) b -> s -> f ()+sequenceAOf_ l = void . getTraversed #. foldMapOf l Traversed+{-# INLINE sequenceAOf_ #-}++-- | Map each target of a 'Fold' on a structure to a monadic action, evaluate these actions from left to right, and ignore the results.+--+-- @+-- 'Data.Foldable.mapM_' ≡ 'mapMOf_' 'folded'+-- @+--+-- @+-- 'mapMOf_' :: 'Monad' m => 'Getter' s a     -> (a -> m r) -> s -> m ()+-- 'mapMOf_' :: 'Monad' m => 'Fold' s a       -> (a -> m r) -> s -> m ()+-- 'mapMOf_' :: 'Monad' m => 'Lens'' s a      -> (a -> m r) -> s -> m ()+-- 'mapMOf_' :: 'Monad' m => 'Iso'' s a       -> (a -> m r) -> s -> m ()+-- 'mapMOf_' :: 'Monad' m => 'Traversal'' s a -> (a -> m r) -> s -> m ()+-- 'mapMOf_' :: 'Monad' m => 'Prism'' s a     -> (a -> m r) -> s -> m ()+-- @+mapMOf_ :: (Profunctor p, Monad m) => Accessing p (Sequenced r m) s t a b -> p a (m r) -> s -> m ()+mapMOf_ l f = liftM skip . getSequenced #. foldMapOf l (Sequenced #. f)+{-# INLINE mapMOf_ #-}++-- | 'forMOf_' is 'mapMOf_' with two of its arguments flipped.+--+-- @+-- 'Data.Foldable.forM_' ≡ 'forMOf_' 'folded'+-- @+--+-- @+-- 'forMOf_' :: 'Monad' m => 'Getter' s a     -> s -> (a -> m r) -> m ()+-- 'forMOf_' :: 'Monad' m => 'Fold' s a       -> s -> (a -> m r) -> m ()+-- 'forMOf_' :: 'Monad' m => 'Lens'' s a      -> s -> (a -> m r) -> m ()+-- 'forMOf_' :: 'Monad' m => 'Iso'' s a       -> s -> (a -> m r) -> m ()+-- 'forMOf_' :: 'Monad' m => 'Traversal'' s a -> s -> (a -> m r) -> m ()+-- 'forMOf_' :: 'Monad' m => 'Prism'' s a     -> s -> (a -> m r) -> m ()+-- @+forMOf_ :: (Profunctor p, Monad m) => Accessing p (Sequenced r m) s t a b -> s -> p a (m r) -> m ()+forMOf_ = flip . mapMOf_+{-# INLINE forMOf_ #-}++-- | Evaluate each monadic action referenced by a 'Fold' on the structure from left to right, and ignore the results.+--+-- @+-- 'Data.Foldable.sequence_' ≡ 'sequenceOf_' 'folded'+-- @+--+-- @+-- 'sequenceOf_' :: 'Monad' m => 'Getter' s (m a)     -> s -> m ()+-- 'sequenceOf_' :: 'Monad' m => 'Fold' s (m a)       -> s -> m ()+-- 'sequenceOf_' :: 'Monad' m => 'Lens'' s (m a)      -> s -> m ()+-- 'sequenceOf_' :: 'Monad' m => 'Iso'' s (m a)       -> s -> m ()+-- 'sequenceOf_' :: 'Monad' m => 'Traversal'' s (m a) -> s -> m ()+-- 'sequenceOf_' :: 'Monad' m => 'Prism'' s (m a)     -> s -> m ()+-- @+sequenceOf_ :: Monad m => Getting (Sequenced a m) s t (m a) b -> s -> m ()+sequenceOf_ l = liftM skip . getSequenced #. foldMapOf l Sequenced+{-# INLINE sequenceOf_ #-}++-- | The sum of a collection of actions, generalizing 'concatOf'.+--+-- @+-- 'asum' ≡ 'asumOf' 'folded'+-- @+--+-- @+-- 'asumOf' :: 'Alternative' f => 'Getter' s a     -> s -> f a+-- 'asumOf' :: 'Alternative' f => 'Fold' s a       -> s -> f a+-- 'asumOf' :: 'Alternative' f => 'Lens'' s a      -> s -> f a+-- 'asumOf' :: 'Alternative' f => 'Iso'' s a       -> s -> f a+-- 'asumOf' :: 'Alternative' f => 'Traversal'' s a -> s -> f a+-- 'asumOf' :: 'Alternative' f => 'Prism'' s a     -> s -> f a+-- @+asumOf :: Alternative f => Getting (Endo (f a)) s t (f a) b -> s -> f a+asumOf l = foldrOf l (<|>) Applicative.empty+{-# INLINE asumOf #-}++-- | The sum of a collection of actions, generalizing 'concatOf'.+--+-- @+-- 'msum' ≡ 'msumOf' 'folded'+-- @+--+-- @+-- 'msumOf' :: 'MonadPlus' m => 'Getter' s a     -> s -> m a+-- 'msumOf' :: 'MonadPlus' m => 'Fold' s a       -> s -> m a+-- 'msumOf' :: 'MonadPlus' m => 'Lens'' s a      -> s -> m a+-- 'msumOf' :: 'MonadPlus' m => 'Iso'' s a       -> s -> m a+-- 'msumOf' :: 'MonadPlus' m => 'Traversal'' s a -> s -> m a+-- 'msumOf' :: 'MonadPlus' m => 'Prism'' s a     -> s -> m a+-- @+msumOf :: MonadPlus m => Getting (Endo (m a)) s t (m a) b -> s -> m a+msumOf l = foldrOf l mplus mzero+{-# INLINE msumOf #-}++-- | Does the element occur anywhere within a given 'Fold' of the structure?+--+-- >>> elemOf both "hello" ("hello","world")+-- True+--+-- @+-- 'elem' ≡ 'elemOf' 'folded'+-- @+--+-- @+-- 'elemOf' :: 'Eq' a => 'Getter' s a     -> a -> s -> 'Bool'+-- 'elemOf' :: 'Eq' a => 'Fold' s a       -> a -> s -> 'Bool'+-- 'elemOf' :: 'Eq' a => 'Lens'' s a      -> a -> s -> 'Bool'+-- 'elemOf' :: 'Eq' a => 'Iso'' s a       -> a -> s -> 'Bool'+-- 'elemOf' :: 'Eq' a => 'Traversal'' s a -> a -> s -> 'Bool'+-- 'elemOf' :: 'Eq' a => 'Prism'' s a     -> a -> s -> 'Bool'+-- @+elemOf :: Eq a => Getting Any s t a b -> a -> s -> Bool+elemOf l = anyOf l . (==)+{-# INLINE elemOf #-}++-- | Does the element not occur anywhere within a given 'Fold' of the structure?+--+-- @+-- 'notElem' ≡ 'notElemOf' 'folded'+-- @+--+-- @+-- 'notElemOf' :: 'Eq' a => 'Getter' s a     -> a -> s -> 'Bool'+-- 'notElemOf' :: 'Eq' a => 'Fold' s a       -> a -> s -> 'Bool'+-- 'notElemOf' :: 'Eq' a => 'Iso'' s a       -> a -> s -> 'Bool'+-- 'notElemOf' :: 'Eq' a => 'Lens'' s a      -> a -> s -> 'Bool'+-- 'notElemOf' :: 'Eq' a => 'Traversal'' s a -> a -> s -> 'Bool'+-- 'notElemOf' :: 'Eq' a => 'Prism'' s a     -> a -> s -> 'Bool'+-- @+notElemOf :: Eq a => Getting All s t a b -> a -> s -> Bool+notElemOf l = allOf l . (/=)+{-# INLINE notElemOf #-}++-- | Map a function over all the targets of a 'Fold' of a container and concatenate the resulting lists.+--+-- @+-- 'concatMap' ≡ 'concatMapOf' 'folded'+-- @+--+-- @+-- 'concatMapOf' :: 'Getter' s a     -> (a -> [r]) -> s -> [r]+-- 'concatMapOf' :: 'Fold' s a       -> (a -> [r]) -> s -> [r]+-- 'concatMapOf' :: 'Lens'' s a      -> (a -> [r]) -> s -> [r]+-- 'concatMapOf' :: 'Iso'' s a       -> (a -> [r]) -> s -> [r]+-- 'concatMapOf' :: 'Traversal'' s a -> (a -> [r]) -> s -> [r]+-- @+concatMapOf :: Profunctor p => Accessing p [r] s t a b -> p a [r] -> s -> [r]+concatMapOf l ces = runAccessor #. l (Accessor #. ces)+{-# INLINE concatMapOf #-}++-- | Concatenate all of the lists targeted by a 'Fold' into a longer list.+--+-- >>> concatOf both ("pan","ama")+-- "panama"+--+-- @+-- 'concat' ≡ 'concatOf' 'folded'+-- 'concatOf' ≡ 'view'+-- @+--+-- @+-- 'concatOf' :: 'Getter' s [r]     -> s -> [r]+-- 'concatOf' :: 'Fold' s [r]       -> s -> [r]+-- 'concatOf' :: 'Iso'' s [r]       -> s -> [r]+-- 'concatOf' :: 'Lens'' s [r]      -> s -> [r]+-- 'concatOf' :: 'Traversal'' s [r] -> s -> [r]+-- @+concatOf :: Getting [r] s t [r] b -> s -> [r]+concatOf l = runAccessor #. l Accessor+{-# INLINE concatOf #-}++-- | Calculate the number of targets there are for a 'Fold' in a given container.+--+-- /Note:/ This can be rather inefficient for large containers and just like 'length',+-- this will not terminate for infinite folds.+--+-- @+-- 'length' ≡ 'lengthOf' 'folded'+-- @+--+-- >>> lengthOf _1 ("hello",())+-- 1+--+-- @+-- 'lengthOf' ('folded' '.' 'folded') :: 'Foldable' f => f (g a) -> 'Int'+-- @+--+-- @+-- 'lengthOf' :: 'Getter' s a     -> s -> 'Int'+-- 'lengthOf' :: 'Fold' s a       -> s -> 'Int'+-- 'lengthOf' :: 'Lens'' s a      -> s -> 'Int'+-- 'lengthOf' :: 'Iso'' s a       -> s -> 'Int'+-- 'lengthOf' :: 'Traversal'' s a -> s -> 'Int'+-- @+lengthOf :: Getting (Endo (Endo Int)) s t a b -> s -> Int+lengthOf l = foldlOf' l (\a _ -> a + 1) 0+{-# INLINE lengthOf #-}++-- | Perform a safe 'head' of a 'Fold' or 'Traversal' or retrieve 'Just' the result+-- from a 'Getter' or 'Lens'.+--+-- When using a 'Traversal' as a partial 'Lens', or a 'Fold' as a partial 'Getter' this can be a convenient+-- way to extract the optional value.+--+-- Note: if you get stack overflows due to this, you may want to use 'firstOf' instead, which can deal+-- more gracefully with heavily left-biased trees.+--+-- @+-- ('^?') ≡ 'flip' 'preview'+-- @+--+-- @+-- ('^?') :: s -> 'Getter' s a     -> 'Maybe' a+-- ('^?') :: s -> 'Fold' s a       -> 'Maybe' a+-- ('^?') :: s -> 'Lens'' s a      -> 'Maybe' a+-- ('^?') :: s -> 'Iso'' s a       -> 'Maybe' a+-- ('^?') :: s -> 'Traversal'' s a -> 'Maybe' a+-- @+(^?) :: s -> Getting (First a) s t a b -> Maybe a+s ^? l = getFirst (foldMapOf l (First #. Just) s)+{-# INLINE (^?) #-}++-- | Perform an *UNSAFE* 'head' of a 'Fold' or 'Traversal' assuming that it is there.+--+-- @+-- ('^?!') :: s -> 'Getter' s a     -> a+-- ('^?!') :: s -> 'Fold' s a       -> a+-- ('^?!') :: s -> 'Lens'' s a      -> a+-- ('^?!') :: s -> 'Iso'' s a       -> a+-- ('^?!') :: s -> 'Traversal'' s a -> a+-- @+(^?!) :: s -> Getting (Endo a) s t a b -> a+s ^?! l = foldrOf l const (error "(^?!): empty Fold") s+{-# INLINE (^?!) #-}++-- | Retrieve the 'First' entry of a 'Fold' or 'Traversal' or retrieve 'Just' the result+-- from a 'Getter' or 'Lens'.+--+-- The answer is computed in a manner that leaks space less than @'ala' 'First' '.' 'foldMapOf'@+-- and gives you back access to the outermost 'Just' constructor more quickly, but may have worse+-- constant factors.+--+-- @+-- 'firstOf' :: 'Getter' s a     -> s -> 'Maybe' a+-- 'firstOf' :: 'Fold' s a       -> s -> 'Maybe' a+-- 'firstOf' :: 'Lens'' s a      -> s -> 'Maybe' a+-- 'firstOf' :: 'Iso'' s a       -> s -> 'Maybe' a+-- 'firstOf' :: 'Traversal'' s a -> s -> 'Maybe' a+-- @+firstOf :: Getting (Leftmost a) s t a b -> s -> Maybe a+firstOf l = getLeftmost . foldMapOf l LLeaf+{-# INLINE firstOf #-}++-- | Retrieve the 'Last' entry of a 'Fold' or 'Traversal' or retrieve 'Just' the result+-- from a 'Getter' or 'Lens'.+--+-- The answer is computed in a manner that leaks space less than @'ala' 'Last' '.' 'foldMapOf'@+-- and gives you back access to the outermost 'Just' constructor more quickly, but may have worse+-- constant factors.+--+-- @+-- 'lastOf' :: 'Getter' s a     -> s -> 'Maybe' a+-- 'lastOf' :: 'Fold' s a       -> s -> 'Maybe' a+-- 'lastOf' :: 'Lens'' s a      -> s -> 'Maybe' a+-- 'lastOf' :: 'Iso'' s a       -> s -> 'Maybe' a+-- 'lastOf' :: 'Traversal'' s a -> s -> 'Maybe' a+-- @+lastOf :: Getting (Rightmost a) s t a b -> s -> Maybe a+lastOf l = getRightmost . foldMapOf l RLeaf+{-# INLINE lastOf #-}++-- | Returns 'True' if this 'Fold' or 'Traversal' has no targets in the given container.+--+-- Note: 'nullOf' on a valid 'Iso', 'Lens' or 'Getter' should always return 'False'.+--+-- @+-- 'null' ≡ 'nullOf' 'folded'+-- @+--+-- This may be rather inefficient compared to the 'null' check of many containers.+--+-- >>> nullOf _1 (1,2)+-- False+--+-- @+-- 'nullOf' ('folded' '.' '_1' '.' 'folded') :: 'Foldable' f => f (g a, b) -> 'Bool'+-- @+--+-- @+-- 'nullOf' :: 'Getter' s a     -> s -> 'Bool'+-- 'nullOf' :: 'Fold' s a       -> s -> 'Bool'+-- 'nullOf' :: 'Iso'' s a       -> s -> 'Bool'+-- 'nullOf' :: 'Lens'' s a      -> s -> 'Bool'+-- 'nullOf' :: 'Traversal'' s a -> s -> 'Bool'+-- @+nullOf :: Getting All s t a b -> s -> Bool+nullOf l = getAll #. foldMapOf l (\_ -> All False)+{-# INLINE nullOf #-}+++-- | Returns 'True' if this 'Fold' or 'Traversal' has any targets in the given container.+--+-- Note: 'notNullOf' on a valid 'Iso', 'Lens' or 'Getter' should always return 'True'.+--+-- @+-- 'null' ≡ 'notNullOf' 'folded'+-- @+--+-- This may be rather inefficient compared to the @'not' '.' 'null'@ check of many containers.+--+-- >>> notNullOf _1 (1,2)+-- True+--+-- @+-- 'notNullOf' ('folded' '.' '_1' '.' 'folded') :: 'Foldable' f => f (g a, b) -> 'Bool'+-- @+--+-- @+-- 'notNullOf' :: 'Getter' s a     -> s -> 'Bool'+-- 'notNullOf' :: 'Fold' s a       -> s -> 'Bool'+-- 'notNullOf' :: 'Iso'' s a       -> s -> 'Bool'+-- 'notNullOf' :: 'Lens'' s a      -> s -> 'Bool'+-- 'notNullOf' :: 'Traversal'' s a -> s -> 'Bool'+-- @+notNullOf :: Getting Any s t a b -> s -> Bool+notNullOf l = getAny #. foldMapOf l (\_ -> Any True)+{-# INLINE notNullOf #-}++-- | Obtain the maximum element (if any) targeted by a 'Fold' or 'Traversal' safely.+--+-- Note: 'maximumOf' on a valid 'Iso', 'Lens' or 'Getter' will always return 'Just' a value.+--+-- @+-- 'maximum' ≡ 'fromMaybe' ('error' \"empty\") '.' 'maximumOf' 'folded'+-- @+--+-- In the interest of efficiency, This operation has semantics more strict than strictly necessary.+-- @'rmap' 'getMax' ('foldMapOf' l 'Max')@ has lazier semantics but could leak memory.+--+-- @+-- 'maximumOf' :: 'Ord' a => 'Getter' s a     -> s -> 'Maybe' a+-- 'maximumOf' :: 'Ord' a => 'Fold' s a       -> s -> 'Maybe' a+-- 'maximumOf' :: 'Ord' a => 'Iso'' s a       -> s -> 'Maybe' a+-- 'maximumOf' :: 'Ord' a => 'Lens'' s a      -> s -> 'Maybe' a+-- 'maximumOf' :: 'Ord' a => 'Traversal'' s a -> s -> 'Maybe' a+-- @+maximumOf :: Ord a => Getting (Endo (Endo (Maybe a))) s t a b -> s -> Maybe a+maximumOf l = foldlOf' l mf Nothing where+  mf Nothing y = Just $! y+  mf (Just x) y = Just $! max x y++{-# INLINE maximumOf #-}++-- | Obtain the minimum element (if any) targeted by a 'Fold' or 'Traversal' safely.+--+-- Note: 'minimumOf' on a valid 'Iso', 'Lens' or 'Getter' will always return 'Just' a value.+--+-- @+-- 'minimum' ≡ 'Data.Maybe.fromMaybe' ('error' \"empty\") '.' 'minimumOf' 'folded'+-- @+--+-- In the interest of efficiency, This operation has semantics more strict than strictly necessary.+-- @'rmap' 'getMin' ('foldMapOf' l 'Min')@ has lazier semantics but could leak memory.+--+--+-- @+-- 'minimumOf' :: 'Ord' a => 'Getter' s a     -> s -> 'Maybe' a+-- 'minimumOf' :: 'Ord' a => 'Fold' s a       -> s -> 'Maybe' a+-- 'minimumOf' :: 'Ord' a => 'Iso'' s a       -> s -> 'Maybe' a+-- 'minimumOf' :: 'Ord' a => 'Lens'' s a      -> s -> 'Maybe' a+-- 'minimumOf' :: 'Ord' a => 'Traversal'' s a -> s -> 'Maybe' a+-- @++minimumOf :: Ord a => Getting (Endo (Endo (Maybe a))) s t a b -> s -> Maybe a+minimumOf l = foldlOf' l mf Nothing where+  mf Nothing y = Just $! y+  mf (Just x) y = Just $! min x y++-- minimumOf :: Getting (Min a) s t a b -> s -> Maybe a+-- minimumOf l = getMin `rmap` foldMapOf l Min+{-# INLINE minimumOf #-}++-- | Obtain the maximum element (if any) targeted by a 'Fold', 'Traversal', 'Lens', 'Iso',+-- or 'Getter' according to a user supplied 'Ordering'.+--+-- In the interest of efficiency, This operation has semantics more strict than strictly necessary.+--+-- @+-- 'Data.Foldable.maximumBy' cmp ≡ 'Data.Maybe.fromMaybe' ('error' \"empty\") '.' 'maximumByOf' 'folded' cmp+-- @+--+-- @+-- 'maximumByOf' :: 'Getter' s a     -> (a -> a -> 'Ordering') -> s -> 'Maybe' a+-- 'maximumByOf' :: 'Fold' s a       -> (a -> a -> 'Ordering') -> s -> 'Maybe' a+-- 'maximumByOf' :: 'Iso'' s a       -> (a -> a -> 'Ordering') -> s -> 'Maybe' a+-- 'maximumByOf' :: 'Lens'' s a      -> (a -> a -> 'Ordering') -> s -> 'Maybe' a+-- 'maximumByOf' :: 'Traversal'' s a -> (a -> a -> 'Ordering') -> s -> 'Maybe' a+-- @+maximumByOf :: Getting (Endo (Endo (Maybe a))) s t a b -> (a -> a -> Ordering) -> s -> Maybe a+maximumByOf l cmp = foldlOf' l mf Nothing where+  mf Nothing y = Just $! y+  mf (Just x) y = Just $! if cmp x y == GT then x else y++-- maximumByOf :: Getting (Endo (Maybe a)) s t a b -> (a -> a -> Ordering) -> s -> Maybe a+-- maximumByOf l cmp = foldrOf l step Nothing where+--   step a Nothing  = Just a+--   step a (Just b) = Just (if cmp a b == GT then a else b)+{-# INLINE maximumByOf #-}++-- | Obtain the minimum element (if any) targeted by a 'Fold', 'Traversal', 'Lens', 'Iso'+-- or 'Getter' according to a user supplied 'Ordering'.+--+-- In the interest of efficiency, This operation has semantics more strict than strictly necessary.+--+-- @+-- 'minimumBy' cmp ≡ 'Data.Maybe.fromMaybe' ('error' \"empty\") '.' 'minimumByOf' 'folded' cmp+-- @+--+-- @+-- 'minimumByOf' :: 'Getter' s a     -> (a -> a -> 'Ordering') -> s -> 'Maybe' a+-- 'minimumByOf' :: 'Fold' s a       -> (a -> a -> 'Ordering') -> s -> 'Maybe' a+-- 'minimumByOf' :: 'Iso'' s a       -> (a -> a -> 'Ordering') -> s -> 'Maybe' a+-- 'minimumByOf' :: 'Lens'' s a      -> (a -> a -> 'Ordering') -> s -> 'Maybe' a+-- 'minimumByOf' :: 'Traversal'' s a -> (a -> a -> 'Ordering') -> s -> 'Maybe' a+-- @+minimumByOf :: Getting (Endo (Endo (Maybe a))) s t a b -> (a -> a -> Ordering) -> s -> Maybe a+minimumByOf l cmp = foldlOf' l mf Nothing where+  mf Nothing y = Just $! y+  mf (Just x) y = Just $! if cmp x y == GT then y else x++-- minimumByOf :: Getting (Endo (Maybe a)) s t a b -> (a -> a -> Ordering) -> s -> Maybe a+-- minimumByOf l cmp = foldrOf l step Nothing where+--   step a Nothing  = Just a+--   step a (Just b) = Just (if cmp a b == GT then b else a)+{-# INLINE minimumByOf #-}++-- | The 'findOf' function takes a 'Lens' (or 'Getter', 'Iso', 'Fold', or 'Traversal'),+-- a predicate and a structure and returns the leftmost element of the structure+-- matching the predicate, or 'Nothing' if there is no such element.+--+-- @+-- 'findOf' :: 'Getter' s a     -> (a -> 'Bool') -> s -> 'Maybe' a+-- 'findOf' :: 'Fold' s a       -> (a -> 'Bool') -> s -> 'Maybe' a+-- 'findOf' :: 'Iso'' s a       -> (a -> 'Bool') -> s -> 'Maybe' a+-- 'findOf' :: 'Lens'' s a      -> (a -> 'Bool') -> s -> 'Maybe' a+-- 'findOf' :: 'Traversal'' s a -> (a -> 'Bool') -> s -> 'Maybe' a+-- @+--+-- @+-- 'ifindOf' l = 'findOf' l '.' 'Indexed'+-- @+--+-- A simpler version that didn't permit indexing, would be:+--+-- @+-- 'findOf' :: 'Getting' ('Endo' ('Maybe' a)) s t a b -> (a -> 'Bool') -> s -> 'Maybe' a+-- 'findOf' l p = 'foldrOf' l (\a y -> if p a then 'Just' a else y) 'Nothing'+-- @+findOf :: Conjoined p => Accessing p (Endo (Maybe a)) s t a b -> p a Bool -> s -> Maybe a+findOf l p = foldrOf l (cotabulate $ \wa y -> if corep p wa then Just (extract wa) else y) Nothing+{-# INLINE findOf #-}++-- | A variant of 'foldrOf' that has no base case and thus may only be applied+-- to lenses and structures such that the 'Lens' views at least one element of+-- the structure.+--+-- @+-- 'foldr1Of' l f ≡ 'Prelude.foldr1' f '.' 'toListOf' l+-- 'Data.Foldable.foldr1' ≡ 'foldr1Of' 'folded'+-- @+--+-- @+-- 'foldr1Of' :: 'Getter' s a     -> (a -> a -> a) -> s -> a+-- 'foldr1Of' :: 'Fold' s a       -> (a -> a -> a) -> s -> a+-- 'foldr1Of' :: 'Iso'' s a       -> (a -> a -> a) -> s -> a+-- 'foldr1Of' :: 'Lens'' s a      -> (a -> a -> a) -> s -> a+-- 'foldr1Of' :: 'Traversal'' s a -> (a -> a -> a) -> s -> a+-- @+foldr1Of :: Getting (Endo (Maybe a)) s t a b -> (a -> a -> a) -> s -> a+foldr1Of l f xs = fromMaybe (error "foldr1Of: empty structure")+                            (foldrOf l mf Nothing xs) where+  mf x my = Just $ case my of+    Nothing -> x+    Just y -> f x y+{-# INLINE foldr1Of #-}++-- | A variant of 'foldlOf' that has no base case and thus may only be applied to lenses and structures such+-- that the 'Lens' views at least one element of the structure.+--+-- @+-- 'foldl1Of' l f ≡ 'Prelude.foldl1' f '.' 'toListOf' l+-- 'Data.Foldable.foldl1' ≡ 'foldl1Of' 'folded'+-- @+--+-- @+-- 'foldl1Of' :: 'Getter' s a     -> (a -> a -> a) -> s -> a+-- 'foldl1Of' :: 'Fold' s a       -> (a -> a -> a) -> s -> a+-- 'foldl1Of' :: 'Iso'' s a       -> (a -> a -> a) -> s -> a+-- 'foldl1Of' :: 'Lens'' s a      -> (a -> a -> a) -> s -> a+-- 'foldl1Of' :: 'Traversal'' s a -> (a -> a -> a) -> s -> a+-- @+foldl1Of :: Getting (Dual (Endo (Maybe a))) s t a b -> (a -> a -> a) -> s -> a+foldl1Of l f xs = fromMaybe (error "foldl1Of: empty structure") (foldlOf l mf Nothing xs) where+  mf mx y = Just $ case mx of+    Nothing -> y+    Just x  -> f x y+{-# INLINE foldl1Of #-}++-- | Strictly fold right over the elements of a structure.+--+-- @+-- 'Data.Foldable.foldr'' ≡ 'foldrOf'' 'folded'+-- @+--+-- @+-- 'foldrOf'' :: 'Getter' s a     -> (a -> r -> r) -> r -> s -> r+-- 'foldrOf'' :: 'Fold' s a       -> (a -> r -> r) -> r -> s -> r+-- 'foldrOf'' :: 'Iso'' s a       -> (a -> r -> r) -> r -> s -> r+-- 'foldrOf'' :: 'Lens'' s a      -> (a -> r -> r) -> r -> s -> r+-- 'foldrOf'' :: 'Traversal'' s a -> (a -> r -> r) -> r -> s -> r+-- @+foldrOf' :: Getting (Dual (Endo (Endo r))) s t a b -> (a -> r -> r) -> r -> s -> r+foldrOf' l f z0 xs = foldlOf l f' (Endo id) xs `appEndo` z0+  where f' (Endo k) x = Endo $ \ z -> k $! f x z+{-# INLINE foldrOf' #-}++-- | Fold over the elements of a structure, associating to the left, but strictly.+--+-- @+-- 'Data.Foldable.foldl'' ≡ 'foldlOf'' 'folded'+-- @+--+-- @+-- 'foldlOf'' :: 'Getter' s a     -> (r -> a -> r) -> r -> s -> r+-- 'foldlOf'' :: 'Fold' s a       -> (r -> a -> r) -> r -> s -> r+-- 'foldlOf'' :: 'Iso'' s a       -> (r -> a -> r) -> r -> s -> r+-- 'foldlOf'' :: 'Lens'' s a      -> (r -> a -> r) -> r -> s -> r+-- 'foldlOf'' :: 'Traversal'' s a -> (r -> a -> r) -> r -> s -> r+-- @+foldlOf' :: Getting (Endo (Endo r)) s t a b -> (r -> a -> r) -> r -> s -> r+foldlOf' l f z0 xs = foldrOf l f' (Endo id) xs `appEndo` z0+  where f' x (Endo k) = Endo $ \z -> k $! f z x+{-# INLINE foldlOf' #-}++-- | A variant of 'foldrOf'' that has no base case and thus may only be applied+-- to folds and structures such that the fold views at least one element of the+-- structure.+--+-- @+-- 'foldr1Of' l f ≡ 'Prelude.foldr1' f '.' 'toListOf' l+-- @+--+-- @+-- 'foldr1Of'' :: 'Getter' s a     -> (a -> a -> a) -> s -> a+-- 'foldr1Of'' :: 'Fold' s a       -> (a -> a -> a) -> s -> a+-- 'foldr1Of'' :: 'Iso'' s a       -> (a -> a -> a) -> s -> a+-- 'foldr1Of'' :: 'Lens'' s a      -> (a -> a -> a) -> s -> a+-- 'foldr1Of'' :: 'Traversal'' s a -> (a -> a -> a) -> s -> a+-- @+foldr1Of' :: Getting (Dual (Endo (Endo (Maybe a)))) s t a b -> (a -> a -> a) -> s -> a+foldr1Of' l f xs = fromMaybe (error "foldr1Of': empty structure") (foldrOf' l mf Nothing xs) where+  mf x Nothing = Just $! x+  mf x (Just y) = Just $! f x y+{-# INLINE foldr1Of' #-}++-- | A variant of 'foldlOf'' that has no base case and thus may only be applied+-- to folds and structures such that the fold views at least one element of+-- the structure.+--+-- @+-- 'foldl1Of'' l f ≡ 'Data.List.foldl1'' f '.' 'toListOf' l+-- @+--+-- @+-- 'foldl1Of'' :: 'Getter' s a     -> (a -> a -> a) -> s -> a+-- 'foldl1Of'' :: 'Fold' s a       -> (a -> a -> a) -> s -> a+-- 'foldl1Of'' :: 'Iso'' s a       -> (a -> a -> a) -> s -> a+-- 'foldl1Of'' :: 'Lens'' s a      -> (a -> a -> a) -> s -> a+-- 'foldl1Of'' :: 'Traversal'' s a -> (a -> a -> a) -> s -> a+-- @+foldl1Of' :: Getting (Endo (Endo (Maybe a))) s t a b -> (a -> a -> a) -> s -> a+foldl1Of' l f xs = fromMaybe (error "foldl1Of': empty structure") (foldlOf' l mf Nothing xs) where+  mf Nothing y = Just $! y+  mf (Just x) y = Just $! f x y+{-# INLINE foldl1Of' #-}++-- | Monadic fold over the elements of a structure, associating to the right,+-- i.e. from right to left.+--+-- @+-- 'Data.Foldable.foldrM' ≡ 'foldrMOf' 'folded'+-- @+--+-- @+-- 'foldrMOf' :: 'Monad' m => 'Getter' s a     -> (a -> r -> m r) -> r -> s -> m r+-- 'foldrMOf' :: 'Monad' m => 'Fold' s a       -> (a -> r -> m r) -> r -> s -> m r+-- 'foldrMOf' :: 'Monad' m => 'Iso'' s a       -> (a -> r -> m r) -> r -> s -> m r+-- 'foldrMOf' :: 'Monad' m => 'Lens'' s a      -> (a -> r -> m r) -> r -> s -> m r+-- 'foldrMOf' :: 'Monad' m => 'Traversal'' s a -> (a -> r -> m r) -> r -> s -> m r+-- @+foldrMOf :: Monad m+         => Getting (Dual (Endo (r -> m r))) s t a b+         -> (a -> r -> m r) -> r -> s -> m r+foldrMOf l f z0 xs = foldlOf l f' return xs z0+  where f' k x z = f x z >>= k+{-# INLINE foldrMOf #-}++-- | Monadic fold over the elements of a structure, associating to the left,+-- i.e. from left to right.+--+-- @+-- 'Data.Foldable.foldlM' ≡ 'foldlMOf' 'folded'+-- @+--+-- @+-- 'foldlMOf' :: 'Monad' m => 'Getter' s a     -> (r -> a -> m r) -> r -> s -> m r+-- 'foldlMOf' :: 'Monad' m => 'Fold' s a       -> (r -> a -> m r) -> r -> s -> m r+-- 'foldlMOf' :: 'Monad' m => 'Iso'' s a       -> (r -> a -> m r) -> r -> s -> m r+-- 'foldlMOf' :: 'Monad' m => 'Lens'' s a      -> (r -> a -> m r) -> r -> s -> m r+-- 'foldlMOf' :: 'Monad' m => 'Traversal'' s a -> (r -> a -> m r) -> r -> s -> m r+-- @+foldlMOf :: Monad m+         => Getting (Endo (r -> m r)) s t a b+         -> (r -> a -> m r) -> r -> s -> m r+foldlMOf l f z0 xs = foldrOf l f' return xs z0+  where f' x k z = f z x >>= k+{-# INLINE foldlMOf #-}++-- | Check to see if this 'Fold' or 'Traversal' matches 1 or more entries.+--+-- >>> has (element 0) []+-- False+--+-- >>> has _Left (Left 12)+-- True+--+-- >>> has _Right (Left 12)+-- False+--+-- This will always return 'True' for a 'Lens' or 'Getter'.+--+-- >>> has _1 ("hello","world")+-- True+--+-- @+-- 'has' :: 'Getter' s a     -> s -> 'Bool'+-- 'has' :: 'Fold' s a       -> s -> 'Bool'+-- 'has' :: 'Iso'' s a       -> s -> 'Bool'+-- 'has' :: 'Lens'' s a      -> s -> 'Bool'+-- 'has' :: 'Traversal'' s a -> s -> 'Bool'+-- @+has :: Getting Any s t a b -> s -> Bool+has l = getAny #. foldMapOf l (\_ -> Any True)+{-# INLINE has #-}++-- | Check to see if this 'Fold' or 'Traversal' has no matches.+--+-- >>> hasn't _Left (Right 12)+-- True+--+-- >>> hasn't _Left (Left 12)+-- False+hasn't :: Getting All s t a b -> s -> Bool+hasn't l = getAll #. foldMapOf l (\_ -> All False)+{-# INLINE hasn't #-}++------------------------------------------------------------------------------+-- Pre+------------------------------------------------------------------------------++-- | This converts a 'Fold' to a 'IndexPreservingGetter' that returns the first element if it+-- exists as a 'Maybe'.+--+-- @+-- 'pre' :: 'Getter' s a        -> 'IndexPreservingGetter' s ('Maybe' a)+-- 'pre' :: 'Fold' s a          -> 'IndexPreservingGetter' s ('Maybe' a)+-- 'pre' :: 'Traversal' s t a b -> 'IndexPreservingGetter' s ('Maybe' a)+-- 'pre' :: 'Lens' s t a b      -> 'IndexPreservingGetter' s ('Maybe' a)+-- 'pre' :: 'Iso' s t a b       -> 'IndexPreservingGetter' s ('Maybe' a)+-- 'pre' :: 'Prism' s t a b     -> 'IndexPreservingGetter' s ('Maybe' a)+-- @+pre :: Getting (First a) s t a b -> IndexPreservingGetter s (Maybe a)+pre l = dimap (getFirst . runAccessor #. l (Accessor #. First #. Just)) coerce+++-- | This converts an 'IndexedFold' to an 'IndexPreservingGetter' that returns the first index+-- and element if it exists as a 'Maybe'.+--+-- @+-- 'ipre' :: 'IndexedGetter' i s a        -> 'IndexPreservingGetter' s ('Maybe' (i, a))+-- 'ipre' :: 'IndexedFold' i s a          -> 'IndexPreservingGetter' s ('Maybe' (i, a))+-- 'ipre' :: 'IndexedTraversal' i s t a b -> 'IndexPreservingGetter' s ('Maybe' (i, a))+-- 'ipre' :: 'IndexedLens' i s t a b      -> 'IndexPreservingGetter' s ('Maybe' (i, a))+-- @+ipre :: IndexedGetting i (First (i, a)) s t a b -> IndexPreservingGetter s (Maybe (i, a))+ipre l = dimap (getFirst . runAccessor #. l (Indexed $ \i a -> Accessor (First (Just (i, a))))) coerce++------------------------------------------------------------------------------+-- Preview+------------------------------------------------------------------------------++-- | Retrieve the first value targeted by a 'Fold' or 'Traversal' (or 'Just' the result+-- from a 'Getter' or 'Lens'). See also ('^?').+--+-- @+-- 'Data.Maybe.listToMaybe' '.' 'toList' ≡ 'preview' 'folded'+-- @+--+-- This is usually applied in the 'Control.Monad.Reader.Reader'+-- 'Control.Monad.Monad' @(->) s@.+--+-- @+-- 'preview' = 'view' '.' 'pre'+-- @+--+-- @+-- 'preview' :: 'Getter' s a     -> s -> 'Maybe' a+-- 'preview' :: 'Fold' s a       -> s -> 'Maybe' a+-- 'preview' :: 'Lens'' s a      -> s -> 'Maybe' a+-- 'preview' :: 'Iso'' s a       -> s -> 'Maybe' a+-- 'preview' :: 'Traversal'' s a -> s -> 'Maybe' a+-- @+--+-- However, it may be useful to think of its full generality when working with+-- a 'Control.Monad.Monad' transformer stack:+--+-- @+-- 'preview' :: 'MonadReader' s m => 'Getter' s a     -> m ('Maybe' a)+-- 'preview' :: 'MonadReader' s m => 'Fold' s a       -> m ('Maybe' a)+-- 'preview' :: 'MonadReader' s m => 'Lens'' s a      -> m ('Maybe' a)+-- 'preview' :: 'MonadReader' s m => 'Iso'' s a       -> m ('Maybe' a)+-- 'preview' :: 'MonadReader' s m => 'Traversal'' s a -> m ('Maybe' a)+-- @+preview :: MonadReader s m => Getting (First a) s t a b -> m (Maybe a)+preview l = asks (getFirst #. foldMapOf l (First #. Just))+{-# INLINE preview #-}++-- | Retrieve the first index and value targeted by a 'Fold' or 'Traversal' (or 'Just' the result+-- from a 'Getter' or 'Lens'). See also ('^@?').+--+-- @+-- 'ipreview' = 'view' '.' 'ipre'+-- @+--+-- This is usually applied in the 'Control.Monad.Reader.Reader'+-- 'Control.Monad.Monad' @(->) s@.+--+-- @+-- 'ipreview' :: 'IndexedGetter' i s a     -> s -> 'Maybe' (i, a)+-- 'ipreview' :: 'IndexedFold' i s a       -> s -> 'Maybe' (i, a)+-- 'ipreview' :: 'IndexedLens'' i s a      -> s -> 'Maybe' (i, a)+-- 'ipreview' :: 'IndexedTraversal'' i s a -> s -> 'Maybe' (i, a)+-- @+--+-- However, it may be useful to think of its full generality when working with+-- a 'Control.Monad.Monad' transformer stack:+--+-- @+-- 'ipreview' :: 'MonadReader' s m => 'IndexedGetter' s a     -> m ('Maybe' (i, a))+-- 'ipreview' :: 'MonadReader' s m => 'IndexedFold' s a       -> m ('Maybe' (i, a))+-- 'ipreview' :: 'MonadReader' s m => 'IndexedLens'' s a      -> m ('Maybe' (i, a))+-- 'ipreview' :: 'MonadReader' s m => 'IndexedTraversal'' s a -> m ('Maybe' (i, a))+-- @+ipreview :: MonadReader s m => IndexedGetting i (First (i, a)) s t a b -> m (Maybe (i, a))+ipreview l = asks (getFirst #. ifoldMapOf l (\i a -> First (Just (i, a))))+{-# INLINE ipreview #-}++-- | Retrieve a function of the first value targeted by a 'Fold' or+-- 'Traversal' (or 'Just' the result from a 'Getter' or 'Lens').+--+-- This is usually applied in the 'Control.Monad.Reader.Reader'+-- 'Control.Monad.Monad' @(->) s@.++-- @+-- 'previews' = 'views' '.' 'pre'+-- @+--+-- @+-- 'previews' :: 'Getter' s a     -> (a -> r) -> s -> 'Maybe' r+-- 'previews' :: 'Fold' s a       -> (a -> r) -> s -> 'Maybe' r+-- 'previews' :: 'Lens'' s a      -> (a -> r) -> s -> 'Maybe' r+-- 'previews' :: 'Iso'' s a       -> (a -> r) -> s -> 'Maybe' r+-- 'previews' :: 'Traversal'' s a -> (a -> r) -> s -> 'Maybe' r+-- @+--+-- However, it may be useful to think of its full generality when working with+-- a 'Monad' transformer stack:+--+-- @+-- 'previews' :: 'MonadReader' s m => 'Getter' s a     -> (a -> r) -> m ('Maybe' r)+-- 'previews' :: 'MonadReader' s m => 'Fold' s a       -> (a -> r) -> m ('Maybe' r)+-- 'previews' :: 'MonadReader' s m => 'Lens'' s a      -> (a -> r) -> m ('Maybe' r)+-- 'previews' :: 'MonadReader' s m => 'Iso'' s a       -> (a -> r) -> m ('Maybe' r)+-- 'previews' :: 'MonadReader' s m => 'Traversal'' s a -> (a -> r) -> m ('Maybe' r)+-- @+previews :: MonadReader s m => Getting (First r) s t a b -> (a -> r) -> m (Maybe r)+previews l f = asks (getFirst . foldMapOf l (First #. Just . f))+{-# INLINE previews #-}++-- | Retrieve a function of the first index and value targeted by an 'IndexedFold' or+-- 'IndexedTraversal' (or 'Just' the result from an 'IndexedGetter' or 'IndexedLens').+-- See also ('^@?').+--+-- @+-- 'ipreviews' = 'views' '.' 'ipre'+-- @+--+-- This is usually applied in the 'Control.Monad.Reader.Reader'+-- 'Control.Monad.Monad' @(->) s@.+--+-- @+-- 'ipreviews' :: 'IndexedGetter' i s a     -> (i -> a -> r) -> s -> 'Maybe' r+-- 'ipreviews' :: 'IndexedFold' i s a       -> (i -> a -> r) -> s -> 'Maybe' r+-- 'ipreviews' :: 'IndexedLens'' i s a      -> (i -> a -> r) -> s -> 'Maybe' r+-- 'ipreviews' :: 'IndexedTraversal'' i s a -> (i -> a -> r) -> s -> 'Maybe' r+-- @+--+-- However, it may be useful to think of its full generality when working with+-- a 'Control.Monad.Monad' transformer stack:+--+-- @+-- 'ipreviews' :: 'MonadReader' s m => 'IndexedGetter' s a     -> (i -> a -> r) -> m ('Maybe' r)+-- 'ipreviews' :: 'MonadReader' s m => 'IndexedFold' s a       -> (i -> a -> r) -> m ('Maybe' r)+-- 'ipreviews' :: 'MonadReader' s m => 'IndexedLens'' s a      -> (i -> a -> r) -> m ('Maybe' r)+-- 'ipreviews' :: 'MonadReader' s m => 'IndexedTraversal'' s a -> (i -> a -> r) -> m ('Maybe' r)+-- @+ipreviews :: MonadReader s m => IndexedGetting i (First r) s t a b -> (i -> a -> r) -> m (Maybe r)+ipreviews l f = asks (getFirst . ifoldMapOf l (\i -> First #. Just . f i))+{-# INLINE ipreviews #-}++------------------------------------------------------------------------------+-- Preuse+------------------------------------------------------------------------------++-- | Retrieve the first value targeted by a 'Fold' or 'Traversal' (or 'Just' the result+-- from a 'Getter' or 'Lens') into the current state.+--+-- @+-- 'preuse' = 'use' '.' 'pre'+-- @+--+-- @+-- 'preuse' :: 'MonadState' s m => 'Getter' s a     -> m ('Maybe' a)+-- 'preuse' :: 'MonadState' s m => 'Fold' s a       -> m ('Maybe' a)+-- 'preuse' :: 'MonadState' s m => 'Lens'' s a      -> m ('Maybe' a)+-- 'preuse' :: 'MonadState' s m => 'Iso'' s a       -> m ('Maybe' a)+-- 'preuse' :: 'MonadState' s m => 'Traversal'' s a -> m ('Maybe' a)+-- @+preuse :: MonadState s m => Getting (First a) s t a b -> m (Maybe a)+preuse l = gets (preview l)+{-# INLINE preuse #-}++-- | Retrieve the first index and value targeted by an 'IndexedFold' or 'IndexedTraversal' (or 'Just' the index +-- and result from an 'IndexedGetter' or 'IndexedLens') into the current state.+--+-- @+-- 'ipreuse' = 'use' '.' 'ipre'+-- @+--+-- @+-- 'ipreuse' :: 'MonadState' s m => 'IndexedGetter' i s a     -> m ('Maybe' (i, a))+-- 'ipreuse' :: 'MonadState' s m => 'IndexedFold' i s a       -> m ('Maybe' (i, a))+-- 'ipreuse' :: 'MonadState' s m => 'IndexedLens'' i s a      -> m ('Maybe' (i, a))+-- 'ipreuse' :: 'MonadState' s m => 'IndexedTraversal'' i s a -> m ('Maybe' (i, a))+-- @+ipreuse :: MonadState s m => IndexedGetting i (First (i, a)) s t a b -> m (Maybe (i, a))+ipreuse l = gets (ipreview l)+{-# INLINE ipreuse #-}++-- | Retrieve a function of the first value targeted by a 'Fold' or+-- 'Traversal' (or 'Just' the result from a 'Getter' or 'Lens') into the current state.+--+-- @+-- 'preuses' = 'uses' '.' 'pre'+-- @+--+-- @+-- 'preuses' :: 'MonadState' s m => 'Getter' s a     -> (a -> r) -> m ('Maybe' r)+-- 'preuses' :: 'MonadState' s m => 'Fold' s a       -> (a -> r) -> m ('Maybe' r)+-- 'preuses' :: 'MonadState' s m => 'Lens'' s a      -> (a -> r) -> m ('Maybe' r)+-- 'preuses' :: 'MonadState' s m => 'Iso'' s a       -> (a -> r) -> m ('Maybe' r)+-- 'preuses' :: 'MonadState' s m => 'Traversal'' s a -> (a -> r) -> m ('Maybe' r)+-- @+preuses :: MonadState s m => Getting (First r) s t a b -> (a -> r) -> m (Maybe r)+preuses l f = gets (previews l f)+{-# INLINE preuses #-}++-- | Retrieve a function of the first index and value targeted by an 'IndexedFold' or+-- 'IndexedTraversal' (or a function of 'Just' the index and result from an 'IndexedGetter'+-- or 'IndexedLens') into the current state.+--+-- @+-- 'ipreuses' = 'uses' '.' 'ipre'+-- @+--+-- @+-- 'ipreuses' :: 'MonadState' s m => 'IndexedGetter' i s a     -> (i -> a -> r) -> m ('Maybe' r)+-- 'ipreuses' :: 'MonadState' s m => 'IndexedFold' i s a       -> (i -> a -> r) -> m ('Maybe' r)+-- 'ipreuses' :: 'MonadState' s m => 'IndexedLens'' i s a      -> (i -> a -> r) -> m ('Maybe' r)+-- 'ipreuses' :: 'MonadState' s m => 'IndexedTraversal'' i s a -> (i -> a -> r) -> m ('Maybe' r)+-- @+ipreuses :: MonadState s m => IndexedGetting i (First r) s t a b -> (i -> a -> r) -> m (Maybe r)+ipreuses l f = gets (ipreviews l f)+{-# INLINE ipreuses #-}++------------------------------------------------------------------------------+-- Profunctors+------------------------------------------------------------------------------+++-- | This allows you to 'Control.Traversable.traverse' the elements of a pretty much any 'LensLike' construction in the opposite order.+--+-- This will preserve indexes on 'Indexed' types and will give you the elements of a (finite) 'Fold' or 'Traversal' in the opposite order.+--+-- This has no practical impact on a 'Getter', 'Setter', 'Lens' or 'Iso'.+--+-- /NB:/ To write back through an 'Iso', you want to use 'Control.Lens.Isomorphic.from'.+-- Similarly, to write back through an 'Prism', you want to use 'Control.Lens.Review.re'.+backwards :: (Profunctor p, Profunctor q) => Overloading p q (Backwards f) s t a b -> Overloading p q f s t a b+backwards l f = forwards #. l (Backwards #. f)+{-# INLINE backwards #-}++------------------------------------------------------------------------------+-- Indexed Folds+------------------------------------------------------------------------------++-- | Fold an 'IndexedFold' or 'IndexedTraversal' by mapping indices and values to an arbitrary 'Monoid' with access+-- to the @i@.+--+-- When you don't need access to the index then 'foldMapOf' is more flexible in what it accepts.+--+-- @+-- 'foldMapOf' l ≡ 'ifoldMapOf' l '.' 'const'+-- @+--+-- @+-- 'ifoldMapOf' ::             'IndexedGetter' i s a     -> (i -> a -> m) -> s -> m+-- 'ifoldMapOf' :: 'Monoid' m => 'IndexedFold' i s a       -> (i -> a -> m) -> s -> m+-- 'ifoldMapOf' ::             'IndexedLens'' i s a      -> (i -> a -> m) -> s -> m+-- 'ifoldMapOf' :: 'Monoid' m => 'IndexedTraversal'' i s a -> (i -> a -> m) -> s -> m+-- @+--+ifoldMapOf :: IndexedGetting i m s t a b -> (i -> a -> m) -> s -> m+ifoldMapOf l = foldMapOf l .# Indexed+{-# INLINE ifoldMapOf #-}++-- | Right-associative fold of parts of a structure that are viewed through an 'IndexedFold' or 'IndexedTraversal' with+-- access to the @i@.+--+-- When you don't need access to the index then 'foldrOf' is more flexible in what it accepts.+--+-- @+-- 'foldrOf' l ≡ 'ifoldrOf' l '.' 'const'+-- @+--+-- @+-- 'ifoldrOf' :: 'IndexedGetter' i s a     -> (i -> a -> r -> r) -> r -> s -> r+-- 'ifoldrOf' :: 'IndexedFold' i s a       -> (i -> a -> r -> r) -> r -> s -> r+-- 'ifoldrOf' :: 'IndexedLens'' i s a      -> (i -> a -> r -> r) -> r -> s -> r+-- 'ifoldrOf' :: 'IndexedTraversal'' i s a -> (i -> a -> r -> r) -> r -> s -> r+-- @+ifoldrOf :: IndexedGetting i (Endo r) s t a b -> (i -> a -> r -> r) -> r -> s -> r+ifoldrOf l = foldrOf l .# Indexed+{-# INLINE ifoldrOf #-}++-- | Left-associative fold of the parts of a structure that are viewed through an 'IndexedFold' or 'IndexedTraversal' with+-- access to the @i@.+--+-- When you don't need access to the index then 'foldlOf' is more flexible in what it accepts.+--+-- @+-- 'foldlOf' l ≡ 'ifoldlOf' l '.' 'const'+-- @+--+-- @+-- 'ifoldlOf' :: 'IndexedGetter' i s a     -> (i -> r -> a -> r) -> r -> s -> r+-- 'ifoldlOf' :: 'IndexedFold' i s a       -> (i -> r -> a -> r) -> r -> s -> r+-- 'ifoldlOf' :: 'IndexedLens'' i s a      -> (i -> r -> a -> r) -> r -> s -> r+-- 'ifoldlOf' :: 'IndexedTraversal'' i s a -> (i -> r -> a -> r) -> r -> s -> r+-- @+ifoldlOf :: IndexedGetting i (Dual (Endo r)) s t a b -> (i -> r -> a -> r) -> r -> s -> r+ifoldlOf l f z = (flip appEndo z .# getDual) `rmap` ifoldMapOf l (\i -> Dual #. Endo #. flip (f i))+{-# INLINE ifoldlOf #-}++-- | Return whether or not any element viewed through an 'IndexedFold' or 'IndexedTraversal'+-- satisfy a predicate, with access to the @i@.+--+-- When you don't need access to the index then 'anyOf' is more flexible in what it accepts.+--+-- @+-- 'anyOf' l ≡ 'ianyOf' l '.' 'const'+-- @+--+-- @+-- 'ianyOf' :: 'IndexedGetter' i s a     -> (i -> a -> 'Bool') -> s -> 'Bool'+-- 'ianyOf' :: 'IndexedFold' i s a       -> (i -> a -> 'Bool') -> s -> 'Bool'+-- 'ianyOf' :: 'IndexedLens'' i s a      -> (i -> a -> 'Bool') -> s -> 'Bool'+-- 'ianyOf' :: 'IndexedTraversal'' i s a -> (i -> a -> 'Bool') -> s -> 'Bool'+-- @+ianyOf :: IndexedGetting i Any s t a b -> (i -> a -> Bool) -> s -> Bool+ianyOf l = anyOf l .# Indexed+{-# INLINE ianyOf #-}++-- | Return whether or not all elements viewed through an 'IndexedFold' or 'IndexedTraversal'+-- satisfy a predicate, with access to the @i@.+--+-- When you don't need access to the index then 'allOf' is more flexible in what it accepts.+--+-- @+-- 'allOf' l ≡ 'iallOf' l '.' 'const'+-- @+--+-- @+-- 'iallOf' :: 'IndexedGetter' i s a     -> (i -> a -> 'Bool') -> s -> 'Bool'+-- 'iallOf' :: 'IndexedFold' i s a       -> (i -> a -> 'Bool') -> s -> 'Bool'+-- 'iallOf' :: 'IndexedLens'' i s a      -> (i -> a -> 'Bool') -> s -> 'Bool'+-- 'iallOf' :: 'IndexedTraversal'' i s a -> (i -> a -> 'Bool') -> s -> 'Bool'+-- @+iallOf :: IndexedGetting i All s t a b -> (i -> a -> Bool) -> s -> Bool+iallOf l = allOf l .# Indexed+{-# INLINE iallOf #-}++-- | Traverse the targets of an 'IndexedFold' or 'IndexedTraversal' with access to the @i@, discarding the results.+--+-- When you don't need access to the index then 'traverseOf_' is more flexible in what it accepts.+--+-- @+-- 'traverseOf_' l ≡ 'Control.Lens.Traversal.itraverseOf' l '.' 'const'+-- @+--+-- @+-- 'itraverseOf_' :: 'Functor' f     => 'IndexedGetter' i s a     -> (i -> a -> f r) -> s -> f ()+-- 'itraverseOf_' :: 'Applicative' f => 'IndexedFold' i s a       -> (i -> a -> f r) -> s -> f ()+-- 'itraverseOf_' :: 'Functor' f     => 'IndexedLens'' i s a      -> (i -> a -> f r) -> s -> f ()+-- 'itraverseOf_' :: 'Applicative' f => 'IndexedTraversal'' i s a -> (i -> a -> f r) -> s -> f ()+-- @+itraverseOf_ :: Functor f => IndexedGetting i (Traversed r f) s t a b -> (i -> a -> f r) -> s -> f ()+itraverseOf_ l = traverseOf_ l .# Indexed+{-# INLINE itraverseOf_ #-}++-- | Traverse the targets of an 'IndexedFold' or 'IndexedTraversal' with access to the index, discarding the results+-- (with the arguments flipped).+--+-- @+-- 'iforOf_' ≡ 'flip' '.' 'itraverseOf_'+-- @+--+-- When you don't need access to the index then 'forOf_' is more flexible in what it accepts.+--+-- @+-- 'forOf_' l a ≡ 'iforOf_' l a '.' 'const'+-- @+--+-- @+-- 'iforOf_' :: 'Functor' f     => 'IndexedGetter' i s a     -> s -> (i -> a -> f r) -> f ()+-- 'iforOf_' :: 'Applicative' f => 'IndexedFold' i s a       -> s -> (i -> a -> f r) -> f ()+-- 'iforOf_' :: 'Functor' f     => 'IndexedLens'' i s a      -> s -> (i -> a -> f r) -> f ()+-- 'iforOf_' :: 'Applicative' f => 'IndexedTraversal'' i s a -> s -> (i -> a -> f r) -> f ()+-- @+iforOf_ :: Functor f => IndexedGetting i (Traversed r f) s t a b -> s -> (i -> a -> f r) -> f ()+iforOf_ = flip . itraverseOf_+{-# INLINE iforOf_ #-}++-- | Run monadic actions for each target of an 'IndexedFold' or 'IndexedTraversal' with access to the index,+-- discarding the results.+--+-- When you don't need access to the index then 'mapMOf_' is more flexible in what it accepts.+--+-- @+-- 'mapMOf_' l ≡ 'Control.Lens.Setter.imapMOf' l '.' 'const'+-- @+--+-- @+-- 'imapMOf_' :: 'Monad' m => 'IndexedGetter' i s a     -> (i -> a -> m r) -> s -> m ()+-- 'imapMOf_' :: 'Monad' m => 'IndexedFold' i s a       -> (i -> a -> m r) -> s -> m ()+-- 'imapMOf_' :: 'Monad' m => 'IndexedLens'' i s a      -> (i -> a -> m r) -> s -> m ()+-- 'imapMOf_' :: 'Monad' m => 'IndexedTraversal'' i s a -> (i -> a -> m r) -> s -> m ()+-- @+imapMOf_ :: Monad m => IndexedGetting i (Sequenced r m) s t a b -> (i -> a -> m r) -> s -> m ()+imapMOf_ l = mapMOf_ l .# Indexed+{-# INLINE imapMOf_ #-}++-- | Run monadic actions for each target of an 'IndexedFold' or 'IndexedTraversal' with access to the index,+-- discarding the results (with the arguments flipped).+--+-- @+-- 'iforMOf_' ≡ 'flip' '.' 'imapMOf_'+-- @+--+-- When you don't need access to the index then 'forMOf_' is more flexible in what it accepts.+--+-- @+-- 'forMOf_' l a ≡ 'Control.Lens.Traversal.iforMOf' l a '.' 'const'+-- @+--+-- @+-- 'iforMOf_' :: 'Monad' m => 'IndexedGetter' i s a     -> s -> (i -> a -> m r) -> m ()+-- 'iforMOf_' :: 'Monad' m => 'IndexedFold' i s a       -> s -> (i -> a -> m r) -> m ()+-- 'iforMOf_' :: 'Monad' m => 'IndexedLens'' i s a      -> s -> (i -> a -> m r) -> m ()+-- 'iforMOf_' :: 'Monad' m => 'IndexedTraversal'' i s a -> s -> (i -> a -> m r) -> m ()+-- @+iforMOf_ :: Monad m => IndexedGetting i (Sequenced r m) s t a b -> s -> (i -> a -> m r) -> m ()+iforMOf_ = flip . imapMOf_+{-# INLINE iforMOf_ #-}++-- | Concatenate the results of a function of the elements of an 'IndexedFold' or 'IndexedTraversal'+-- with access to the index.+--+-- When you don't need access to the index then 'concatMapOf'  is more flexible in what it accepts.+--+-- @+-- 'concatMapOf' l ≡ 'iconcatMapOf' l '.' 'const'+-- 'iconcatMapOf' ≡ 'ifoldMapOf'+-- @+--+-- @+-- 'iconcatMapOf' :: 'IndexedGetter' i s a     -> (i -> a -> [r]) -> s -> [r]+-- 'iconcatMapOf' :: 'IndexedFold' i s a       -> (i -> a -> [r]) -> s -> [r]+-- 'iconcatMapOf' :: 'IndexedLens'' i s a      -> (i -> a -> [r]) -> s -> [r]+-- 'iconcatMapOf' :: 'IndexedTraversal'' i s a -> (i -> a -> [r]) -> s -> [r]+-- @+iconcatMapOf :: IndexedGetting i [r] s t a b -> (i -> a -> [r]) -> s -> [r]+iconcatMapOf = ifoldMapOf+{-# INLINE iconcatMapOf #-}++-- | The 'findOf' function takes an 'IndexedFold' or 'IndexedTraversal', a predicate that is also+-- supplied the index, a structure and returns the left-most element of the structure+-- matching the predicate, or 'Nothing' if there is no such element.+--+-- When you don't need access to the index then 'findOf' is more flexible in what it accepts.+--+-- @+-- 'findOf' l ≡ 'ifindOf' l '.' 'const'+-- @+--+-- @+-- 'ifindOf' :: 'IndexedGetter' s a     -> (i -> a -> 'Bool') -> s -> 'Maybe' a+-- 'ifindOf' :: 'IndexedFold' s a       -> (i -> a -> 'Bool') -> s -> 'Maybe' a+-- 'ifindOf' :: 'IndexedLens'' s a      -> (i -> a -> 'Bool') -> s -> 'Maybe' a+-- 'ifindOf' :: 'IndexedTraversal'' s a -> (i -> a -> 'Bool') -> s -> 'Maybe' a+-- @+ifindOf :: IndexedGetting i (Endo (Maybe a)) s t a b -> (i -> a -> Bool) -> s -> Maybe a+ifindOf l = findOf l .# Indexed+{-# INLINE ifindOf #-}++-- | /Strictly/ fold right over the elements of a structure with an index.+--+-- When you don't need access to the index then 'foldrOf'' is more flexible in what it accepts.+--+-- @+-- 'foldrOf'' l ≡ 'ifoldrOf'' l '.' 'const'+-- @+--+-- @+-- 'ifoldrOf'' :: 'IndexedGetter' i s a     -> (i -> a -> r -> r) -> r -> s -> r+-- 'ifoldrOf'' :: 'IndexedFold' i s a       -> (i -> a -> r -> r) -> r -> s -> r+-- 'ifoldrOf'' :: 'IndexedLens'' i s a      -> (i -> a -> r -> r) -> r -> s -> r+-- 'ifoldrOf'' :: 'IndexedTraversal'' i s a -> (i -> a -> r -> r) -> r -> s -> r+-- @+ifoldrOf' :: IndexedGetting i (Dual (Endo (r -> r))) s t a b -> (i -> a -> r -> r) -> r -> s -> r+ifoldrOf' l f z0 xs = ifoldlOf l f' id xs z0+  where f' i k x z = k $! f i x z+{-# INLINE ifoldrOf' #-}++-- | Fold over the elements of a structure with an index, associating to the left, but /strictly/.+--+-- When you don't need access to the index then 'foldlOf'' is more flexible in what it accepts.+--+-- @+-- 'foldlOf'' l ≡ 'ifoldlOf'' l '.' 'const'+-- @+--+-- @+-- 'ifoldlOf'' :: 'IndexedGetter' i s a       -> (i -> r -> a -> r) -> r -> s -> r+-- 'ifoldlOf'' :: 'IndexedFold' i s a         -> (i -> r -> a -> r) -> r -> s -> r+-- 'ifoldlOf'' :: 'IndexedLens'' i s a        -> (i -> r -> a -> r) -> r -> s -> r+-- 'ifoldlOf'' :: 'IndexedTraversal'' i s a   -> (i -> r -> a -> r) -> r -> s -> r+-- @+ifoldlOf' :: IndexedGetting i (Endo (r -> r)) s t a b -> (i -> r -> a -> r) -> r -> s -> r+ifoldlOf' l f z0 xs = ifoldrOf l f' id xs z0+  where f' i x k z = k $! f i z x+{-# INLINE ifoldlOf' #-}++-- | Monadic fold right over the elements of a structure with an index.+--+-- When you don't need access to the index then 'foldrMOf' is more flexible in what it accepts.+--+-- @+-- 'foldrMOf' l ≡ 'ifoldrMOf' l '.' 'const'+-- @+--+-- @+-- 'ifoldrMOf' :: 'Monad' m => 'IndexedGetter' i s a     -> (i -> a -> r -> m r) -> r -> s -> r+-- 'ifoldrMOf' :: 'Monad' m => 'IndexedFold' i s a       -> (i -> a -> r -> m r) -> r -> s -> r+-- 'ifoldrMOf' :: 'Monad' m => 'IndexedLens'' i s a      -> (i -> a -> r -> m r) -> r -> s -> r+-- 'ifoldrMOf' :: 'Monad' m => 'IndexedTraversal'' i s a -> (i -> a -> r -> m r) -> r -> s -> r+-- @+ifoldrMOf :: Monad m => IndexedGetting i (Dual (Endo (r -> m r))) s t a b -> (i -> a -> r -> m r) -> r -> s -> m r+ifoldrMOf l f z0 xs = ifoldlOf l f' return xs z0+  where f' i k x z = f i x z >>= k+{-# INLINE ifoldrMOf #-}++-- | Monadic fold over the elements of a structure with an index, associating to the left.+--+-- When you don't need access to the index then 'foldlMOf' is more flexible in what it accepts.+--+-- @+-- 'foldlMOf' l ≡ 'ifoldlMOf' l '.' 'const'+-- @+--+-- @+-- 'ifoldlOf'' :: 'Monad' m => 'IndexedGetter' i s a     -> (i -> r -> a -> m r) -> r -> s -> r+-- 'ifoldlOf'' :: 'Monad' m => 'IndexedFold' i s a       -> (i -> r -> a -> m r) -> r -> s -> r+-- 'ifoldlOf'' :: 'Monad' m => 'IndexedLens'' i s a      -> (i -> r -> a -> m r) -> r -> s -> r+-- 'ifoldlOf'' :: 'Monad' m => 'IndexedTraversal'' i s a -> (i -> r -> a -> m r) -> r -> s -> r+-- @+ifoldlMOf :: Monad m => IndexedGetting i (Endo (r -> m r)) s t a b -> (i -> r -> a -> m r) -> r -> s -> m r+ifoldlMOf l f z0 xs = ifoldrOf l f' return xs z0+  where f' i x k z = f i z x >>= k+{-# INLINE ifoldlMOf #-}++-- | Extract the key-value pairs from a structure.+--+-- When you don't need access to the indices in the result, then 'toListOf' is more flexible in what it accepts.+--+-- @+-- 'toListOf' l ≡ 'map' 'fst' '.' 'itoListOf' l+-- @+--+-- @+-- 'itoListOf' :: 'IndexedGetter' i s a     -> s -> [(i,a)]+-- 'itoListOf' :: 'IndexedFold' i s a       -> s -> [(i,a)]+-- 'itoListOf' :: 'IndexedLens'' i s a      -> s -> [(i,a)]+-- 'itoListOf' :: 'IndexedTraversal'' i s a -> s -> [(i,a)]+-- @+itoListOf :: IndexedGetting i (Endo [(i,a)]) s t a b -> s -> [(i,a)]+itoListOf l = ifoldrOf l (\i a -> ((i,a):)) []+{-# INLINE itoListOf #-}++-- | An infix version of 'itoListOf'.++-- @+-- ('^@..') :: s -> 'IndexedGetter' i s a     -> [(i,a)]+-- ('^@..') :: s -> 'IndexedFold' i s a       -> [(i,a)]+-- ('^@..') :: s -> 'IndexedLens'' i s a      -> [(i,a)]+-- ('^@..') :: s -> 'IndexedTraversal'' i s a -> [(i,a)]+-- @+(^@..) :: s -> IndexedGetting i (Endo [(i,a)]) s t a b -> [(i,a)]+s ^@.. l = ifoldrOf l (\i a -> ((i,a):)) [] s++-- | Perform a safe 'head' (with index) of an 'IndexedFold' or 'IndexedTraversal' or retrieve 'Just' the index and result+-- from an 'IndexedGetter' or 'IndexedLens'.+--+-- When using a 'IndexedTraversal' as a partial 'IndexedLens', or an 'IndexedFold' as a partial 'IndexedGetter' this can be a convenient+-- way to extract the optional value.+--+-- @+-- ('^@?') :: s -> 'IndexedGetter' i s a -> 'Maybe' (i, a)+-- ('^@?') :: s -> 'IndexedFold' i s a   -> 'Maybe' (i, a)+-- ('^@?') :: s -> 'IndexedLens'' i s a  -> 'Maybe' (i, a)+-- ('^@?') :: s -> 'Iso'' i s a          -> 'Maybe' (i, a)+-- ('^@?') :: s -> 'Traversal'' i s a    -> 'Maybe' (i, a)+-- @+(^@?) :: s -> IndexedGetting i (Endo (Maybe (i, a))) s t a b -> Maybe (i, a)+s ^@? l = ifoldrOf l (\i x _ -> Just (i,x)) Nothing s+{-# INLINE (^@?) #-}++-- | Perform an *UNSAFE* 'head' (with index) of an 'IndexedFold' or 'IndexedTraversal' assuming that it is there.+--+-- @+-- ('^@?!') :: s -> 'IndexedGetter' i s a -> (i, a)+-- ('^@?!') :: s -> 'IndexedFold' i s a   -> (i, a)+-- ('^@?!') :: s -> 'Lens'' i s a         -> (i, a)+-- ('^@?!') :: s -> 'Iso'' i s a          -> (i, a)+-- ('^@?!') :: s -> 'Traversal'' i s a    -> (i, a)+-- @+(^@?!) :: s -> IndexedGetting i (Endo (i, a)) s t a b -> (i, a)+s ^@?! l = ifoldrOf l (\i x _ -> (i,x)) (error "(^@?!): empty Fold") s+{-# INLINE (^@?!) #-}++-------------------------------------------------------------------------------+-- Converting to Folds+-------------------------------------------------------------------------------++-- | Filter an 'IndexedFold' or 'IndexedGetter', obtaining an 'IndexedFold'.+--+-- >>> [0,0,0,5,5,5]^..traversed.ifiltered (\i a -> i <= a)+-- [0,5,5,5]+--+-- Compose with 'filtered' to filter another 'IndexedLens', 'IndexedIso', 'IndexedGetter', 'IndexedFold' (or 'IndexedTraversal') with+-- access to both the value and the index.+--+-- Note: As with 'filtered', this is /not/ a legal 'IndexedTraversal', unless you are very careful not to invalidate the predicate on the target!+ifiltered :: (Indexable i p, Applicative f) => (i -> a -> Bool) -> Overloading' p (Indexed i) f a a+ifiltered p f = Indexed $ \i a -> if p i a then indexed f i a else pure a+{-# INLINE ifiltered #-}++-- | Obtain an 'IndexedFold' by taking elements from another+-- 'IndexedFold', 'IndexedLens', 'IndexedGetter' or 'IndexedTraversal' while a predicate holds.+--+-- @+-- 'itakingWhile' :: (i -> a -> 'Bool') -> 'IndexedFold' i s a          -> 'IndexedFold' i s a+-- 'itakingWhile' :: (i -> a -> 'Bool') -> 'IndexedTraversal'' i s a    -> 'IndexedFold' i s a+-- 'itakingWhile' :: (i -> a -> 'Bool') -> 'IndexedLens'' i s a         -> 'IndexedFold' i s a+-- 'itakingWhile' :: (i -> a -> 'Bool') -> 'IndexedGetter' i s a        -> 'IndexedFold' i s a+-- 'itakingWhile' :: (i -> a -> 'Bool') -> 'IndexedMonadicFold' i m s a -> 'IndexedMonadicFold' i m s a+-- 'itakingWhile' :: (i -> a -> 'Bool') -> 'IndexedAction' i m s a      -> 'IndexedMonadicFold' i m s a+-- @+itakingWhile :: (Indexable i p, Profunctor q, Applicative f, Gettable f)+         => (i -> a -> Bool)+         -> Overloading (Indexed i) q (Accessor (Endo (f s))) s s a a+         -> Overloading p q f s s a a+itakingWhile p l f = (flip appEndo noEffect .# runAccessor) `rmap` l g where+  g = Indexed $ \i a -> Accessor . Endo $ if p i a then (indexed f i a *>) else const noEffect+{-# INLINE itakingWhile #-}++-- | Obtain an 'IndexedFold' by dropping elements from another 'IndexedFold', 'IndexedLens', 'IndexedGetter' or 'IndexedTraversal' while a predicate holds.+--+-- @+-- 'idroppingWhile' :: (i -> a -> 'Bool') -> 'IndexedFold' i s a          -> 'IndexedFold' i s a+-- 'idroppingWhile' :: (i -> a -> 'Bool') -> 'IndexedTraversal'' i s a    -> 'IndexedFold' i s a -- see notes+-- 'idroppingWhile' :: (i -> a -> 'Bool') -> 'IndexedLens'' i s a         -> 'IndexedFold' i s a -- see notes+-- 'idroppingWhile' :: (i -> a -> 'Bool') -> 'IndexedGetter' i s a        -> 'IndexedFold' i s a+-- 'idroppingWhile' :: (i -> a -> 'Bool') -> 'IndexedMonadicFold' i m s a -> 'IndexedMonadicFold' i m s a+-- 'idroppingWhile' :: (i -> a -> 'Bool') -> 'IndexedAction' i m s a      -> 'IndexedMonadicFold' i m s a+-- @+--+-- Applying 'idroppingWhile' to an 'IndexedLens' or 'IndexedTraversal' will still allow you to use it as a+-- pseudo-'IndexedTraversal', but if you change the value of the targets to ones where the predicate returns+-- 'True', then you will break the 'Traversal' laws and 'Traversal' fusion will no longer be sound.+idroppingWhile :: (Indexable i p, Profunctor q, Applicative f)+              => (i -> a -> Bool)+              -> Overloading (Indexed i) q (Compose (State Bool) f) s t a a+              -> Overloading p q f s t a a+idroppingWhile p l f = (flip evalState True .# getCompose) `rmap` l g where+  g = Indexed $ \ i a -> Compose $ state $ \b -> let+      b' = b && p i a+    in (if b' then pure a else indexed f i a, b')+{-# INLINE idroppingWhile #-}++------------------------------------------------------------------------------+-- Deprecated+------------------------------------------------------------------------------++-- | A deprecated alias for 'firstOf'.+headOf :: Getting (First a) s t a b -> s -> Maybe a+headOf l = getFirst #. foldMapOf l (First #. Just)+{-# INLINE headOf #-}+{-# DEPRECATED headOf "`headOf' will be removed in 3.9. (Use `preview' or `firstOf')" #-}++------------------------------------------------------------------------------+-- Misc.+------------------------------------------------------------------------------++skip :: a -> ()+skip _ = ()+{-# INLINE skip #-}
src/Control/Lens/Getter.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE MagicHash #-} {-# LANGUAGE CPP #-} {-# LANGUAGE Rank2Types #-} {-# LANGUAGE MultiParamTypeClasses #-}@@ -9,7 +8,7 @@ ------------------------------------------------------------------------------- -- | -- Module      :  Control.Lens.Getter--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  provisional@@ -44,33 +43,35 @@ module Control.Lens.Getter   (   -- * Getters-    Getter-  , Getting+    Getter, IndexedGetter+  , Getting, IndexedGetting+  , Accessing   -- * Building Getters   , to   -- * Combinators for Getters and Folds-  , (^.), (^$)-  , (&), (^&)-  , view-  , views-  , use-  , uses-  -- * Simple Getter Operations-  , view'-  , views'-  , use'-  , uses'-  -- * Storing Getters-  , ReifiedGetter(..)-  , Gettable-  , Accessor+  , (^.)+  , view, views, view', views'+  , use, uses, use', uses'+  , listening, listenings+  -- * Indexed Getters+  -- ** Indexed Getter Combinators+  , (^@.)+  , iview, iviews+  , iuse, iuses+  , ilistening, ilistenings+  -- * Implementation Details+  , Gettable(..)+  , Accessor(..)   ) where -import Control.Lens.Classes-import Control.Lens.Internal-import Control.Lens.Internal.Combinators+import Control.Lens.Internal.Getter+import Control.Lens.Internal.Indexed+import Control.Lens.Type import Control.Monad.Reader.Class as Reader import Control.Monad.State        as State+import Control.Monad.Writer       as Writer+import Data.Profunctor+import Data.Profunctor.Unsafe  -- $setup -- >>> import Control.Lens@@ -80,74 +81,21 @@ -- >>> let f :: Expr -> Expr; f = Debug.SimpleReflect.Vars.f -- >>> let g :: Expr -> Expr; g = Debug.SimpleReflect.Vars.g -infixl 8 ^., ^&-infixl 1 &-infixr 0 ^$------------------------------------------------------------------------------------ Pipelining------------------------------------------------------------------------------------ | Passes the result of the left side to the function on the right side (forward pipe operator).------ This is the flipped version of ('$'), which is more common in languages like F# as (@|>@) where it is needed--- for inference. Here it is supplied for notational convenience and given a precedence that allows it--- to be nested inside uses of ('$').------ >>> a & f--- f a------ >>> "hello" & length & succ--- 6------ This combinator is commonly used when applying multiple lens operations in sequence.------ >>> ("hello","world") & _1.element 0 .~ 'j' & _1.element 4 .~ 'y'--- ("jelly","world")------ This reads somewhat similar to:------ >>> flip execState ("hello","world") $ do _1.element 0 .= 'j'; _1.element 4 .= 'y'--- ("jelly","world")-----(&) :: a -> (a -> b) -> b-a & f = f a-{-# INLINE (&) #-}---- | A version of ('&') with much tighter precedence that can be interleaved with ('^.')------ >>> a ^& f--- f a------ >>> "hello" ^& length--- 5------ >>> ("hello","world")^._1^&reverse^?!_head--- 'o'-(^&) :: a -> (a -> b) -> b-a ^& f = f a+infixl 8 ^., ^@.  ------------------------------------------------------------------------------- -- Getters ------------------------------------------------------------------------------- --- | A 'Getter' describes how to retrieve a single value in a way that can be--- composed with other lens-like constructions.------ Unlike a 'Control.Lens.Type.Lens' a 'Getter' is read-only. Since a 'Getter'--- cannot be used to write back there are no lens laws that can be applied to--- it. In fact, it is isomorphic to an arbitrary function from @(a -> s)@.------ Moreover, a 'Getter' can be used directly as a 'Control.Lens.Fold.Fold',--- since it just ignores the 'Applicative'.-type Getter s a = forall f. Gettable f => (a -> f a) -> s -> f s- -- | Build a 'Getter' from an arbitrary Haskell function. ----- @'to' f . 'to' g ≡ 'to' (g . f)@+-- @+-- 'to' f '.' 'to' g ≡ 'to' (g '.' f)+-- @ ----- @a '^.' 'to' f ≡ f a@+-- @+-- a '^.' 'to' f ≡ f a+-- @ -- -- >>> a ^.to f -- f a@@ -160,42 +108,49 @@ -- -- >>> (0, -5)^._2.to abs -- 5-to :: (s -> a) -> Getter s a-to f g = coerce . g . f+to :: (s -> a) -> IndexPreservingGetter s a+to f = dimap f coerce {-# INLINE to #-} ---- |--- When you see this in a type signature it indicates that you can--- pass the function a 'Control.Lens.Type.Lens', 'Getter',+-- | When you see this in a type signature it indicates that you can+-- pass the function a 'Lens', 'Getter', -- 'Control.Lens.Traversal.Traversal', 'Control.Lens.Fold.Fold', -- 'Control.Lens.Prism.Prism', 'Control.Lens.Iso.Iso', or one of -- the indexed variants, and it will just \"do the right thing\". -- -- Most 'Getter' combinators are able to be used with both a 'Getter' or a -- 'Control.Lens.Fold.Fold' in limited situations, to do so, they need to be--- monomorphic in what we are going to extract with 'Const'. To be compatible--- with 'Control.Lens.Type.Lens', 'Control.Lens.Traversal.Traversal' and+-- monomorphic in what we are going to extract with 'Control.Applicative.Const'. To be compatible+-- with 'Lens', 'Control.Lens.Traversal.Traversal' and -- 'Control.Lens.Iso.Iso' we also restricted choices of the irrelevant @t@ and -- @b@ parameters. ----- If a function accepts a @'Getting' r s t a b@, then when @r@ is a 'Monoid', then+-- If a function accepts a @'Getting' r s t a b@, then when @r@ is a 'Data.Monoid.Monoid', then -- you can pass a 'Control.Lens.Fold.Fold' (or -- 'Control.Lens.Traversal.Traversal'), otherwise you can only pass this a--- 'Getter' or 'Control.Lens.Type.Lens'.+-- 'Getter' or 'Lens'. -- type Getting r s t a b = (a -> Accessor r b) -> s -> Accessor r t +-- | Used to consume an 'Control.Lens.Fold.IndexedFold'.+type IndexedGetting i m s t a b = Indexed i a (Accessor m b) -> s -> Accessor m t++-- | This is a convenient alias used when consuming (indexed) getters and (indexed) folds+-- in a highly general fashion.+type Accessing p m s t a b = p a (Accessor m b) -> s -> Accessor m t+ ------------------------------------------------------------------------------- -- Getting Values -------------------------------------------------------------------------------  -- | View the value pointed to by a 'Getter', 'Control.Lens.Iso.Iso' or--- 'Control.Lens.Type.Lens' or the result of folding over all the results of a+-- 'Lens' or the result of folding over all the results of a -- 'Control.Lens.Fold.Fold' or 'Control.Lens.Traversal.Traversal' that points--- at a monoidal values.+-- at a monoidal value. ----- @'view' . 'to' ≡ 'id'@+-- @+-- 'view' '.' 'to' ≡ 'id'+-- @ -- -- >>> view (to f) a -- f a@@ -210,39 +165,37 @@ -- "world" -- ----- As @views@ is commonly used to access the target of a 'Getter' or obtain a monoidal summary of the targets of a 'Fold',--- It may be useful to think of it as having one of these more restrictive signatures:+-- As 'view' is commonly used to access the target of a 'Getter' or obtain a monoidal summary of the targets of a 'Fold',+-- It may be useful to think of it as having one of these more restricted signatures: -- -- @--- 'view' ::             'Getter' s a             -> s -> a--- 'view' :: 'Monoid' m => 'Control.Lens.Fold.Fold' s m               -> s -> m--- 'view' ::             'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a         -> s -> a--- 'view' ::             'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a        -> s -> a--- 'view' :: 'Monoid' m => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s m   -> s -> m+-- 'view' ::             'Getter' s a     -> s -> a+-- 'view' :: 'Data.Monoid.Monoid' m => 'Control.Lens.Fold.Fold' s m       -> s -> m+-- 'view' ::             'Control.Lens.Iso.Iso'' s a       -> s -> a+-- 'view' ::             'Lens'' s a      -> s -> a+-- 'view' :: 'Data.Monoid.Monoid' m => 'Control.Lens.Traversal.Traversal'' s m -> s -> m -- @ ----- In a more general setting, such as when working with a monad transformer stack you can use:+-- In a more general setting, such as when working with a 'Monad' transformer stack you can use: -- -- @--- 'view' :: 'MonadReader' s m             => 'Getter' s a           -> m a--- 'view' :: ('MonadReader' s m, 'Monoid' a) => 'Control.Lens.Fold.Fold' s a             -> m a--- 'view' :: 'MonadReader' s m             => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a       -> m a--- 'view' :: 'MonadReader' s m             => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a      -> m a--- 'view' :: ('MonadReader' s m, 'Monoid' a) => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a -> m a+-- 'view' :: 'MonadReader' s m             => 'Getter' s a     -> m a+-- 'view' :: ('MonadReader' s m, 'Data.Monoid.Monoid' a) => 'Control.Lens.Fold.Fold' s a       -> m a+-- 'view' :: 'MonadReader' s m             => 'Control.Lens.Iso.Iso'' s a       -> m a+-- 'view' :: 'MonadReader' s m             => 'Lens'' s a      -> m a+-- 'view' :: ('MonadReader' s m, 'Data.Monoid.Monoid' a) => 'Control.Lens.Traversal.Traversal'' s a -> m a -- @ view :: MonadReader s m => Getting a s t a b -> m a-view l = Reader.asks (runAccessor# (l Accessor))+view l = Reader.asks (runAccessor #. l Accessor) {-# INLINE view #-} --- | View the value of a 'Getter', 'Control.Lens.Iso.Iso',--- 'Control.Lens.Type.Lens' or the result of folding over the result of mapping--- the targets of a 'Control.Lens.Fold.Fold' or+-- | View a function of the value pointed to by a 'Getter' or 'Lens' or the result of+-- folding over the result of mapping the targets of a 'Control.Lens.Fold.Fold' or -- 'Control.Lens.Traversal.Traversal'. ----- It may be useful to think of 'views' as having these more restrictive--- signatures:------ @'views' l f ≡ 'view' (l '.' 'to' f)@+-- @+-- 'views' l f ≡ 'view' (l '.' 'to' f)+-- @ -- -- >>> views (to f) g a -- g (f a)@@ -250,64 +203,42 @@ -- >>> views _2 length (1,"hello") -- 5 ----- As @views@ is commonly used to access the target of a 'Getter' or obtain a monoidal summary of the targets of a 'Fold',--- It may be useful to think of it as having one of these more restrictive signatures:+-- As 'views' is commonly used to access the target of a 'Getter' or obtain a monoidal summary of the targets of a 'Fold',+-- It may be useful to think of it as having one of these more restricted signatures: -- -- @--- 'views' ::             'Getter' s a             -> (a -> r) -> s -> r--- 'views' :: 'Monoid' m => 'Control.Lens.Fold.Fold' s a               -> (a -> m) -> s -> m--- 'views' ::             'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a         -> (a -> r) -> s -> r--- 'views' ::             'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a        -> (a -> r) -> s -> r--- 'views' :: 'Monoid' m => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a   -> (a -> m) -> s -> m+-- 'views' ::             'Getter' s a     -> (a -> r) -> s -> r+-- 'views' :: 'Data.Monoid.Monoid' m => 'Control.Lens.Fold.Fold' s a       -> (a -> m) -> s -> m+-- 'views' ::             'Control.Lens.Iso.Iso'' s a       -> (a -> r) -> s -> r+-- 'views' ::             'Lens'' s a      -> (a -> r) -> s -> r+-- 'views' :: 'Data.Monoid.Monoid' m => 'Control.Lens.Traversal.Traversal'' s a -> (a -> m) -> s -> m -- @ ----- In a more general setting, such as when working with a monad transformer stack you can use:+-- In a more general setting, such as when working with a 'Monad' transformer stack you can use: -- -- @--- 'view' :: 'MonadReader' s m             => 'Getter' s a           -> m a--- 'view' :: ('MonadReader' s m, 'Monoid' a) => 'Control.Lens.Fold.Fold' s a             -> m a--- 'view' :: 'MonadReader' s m             => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a       -> m a--- 'view' :: 'MonadReader' s m             => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a      -> m a--- 'view' :: ('MonadReader' s m, 'Monoid' a) => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a -> m a+-- 'view' :: 'MonadReader' s m             => 'Getter' s a     -> m a+-- 'view' :: ('MonadReader' s m, 'Data.Monoid.Monoid' a) => 'Control.Lens.Fold.Fold' s a       -> m a+-- 'view' :: 'MonadReader' s m             => 'Control.Lens.Iso.Iso'' s a       -> m a+-- 'view' :: 'MonadReader' s m             => 'Lens'' s a      -> m a+-- 'view' :: ('MonadReader' s m, 'Data.Monoid.Monoid' a) => 'Control.Lens.Traversal.Traversal'' s a -> m a -- @-views :: MonadReader s m => Getting r s t a b -> (a -> r) -> m r-views l f = Reader.asks (runAccessor# (l (accessor# f)))-{-# INLINE views #-}---- | View the value pointed to by a 'Getter', 'Control.Lens.Iso.Iso' or--- 'Control.Lens.Type.Lens' or the result of folding over all the results of a--- 'Control.Lens.Fold.Fold' or 'Control.Lens.Traversal.Traversal' that points--- at a monoidal values. ----- This is the same operation as 'view', only infix.------ @'to' f '^$' x ≡ f x@------ >>> to f ^$ x--- f x------ >>> _2 ^$ (1, "hello")--- "hello"--- -- @--- ('^$') ::             'Getter' s a             -> s -> a--- ('^$') :: 'Monoid' m => 'Control.Lens.Fold.Fold' s m               -> s -> m--- ('^$') ::             'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a         -> s -> a--- ('^$') ::             'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a        -> s -> a--- ('^$') :: 'Monoid' m => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s m   -> s -> m+-- 'views' :: 'MonadReader' s m => 'Getting' r s t a b -> (a -> r) -> m r -- @-(^$) :: Getting a s t a b -> s -> a-l ^$ s = runAccessor (l Accessor s)-{-# INLINE (^$) #-}+views :: (Profunctor p, MonadReader s m) => Overloading p (->) (Accessor r) s t a b -> p a r -> m r+views l f = Reader.asks (runAccessor #. l (rmap Accessor f))+{-# INLINE views #-} --- | View the value pointed to by a 'Getter' or 'Control.Lens.Type.Lens' or the+-- | View the value pointed to by a 'Getter' or 'Lens' or the -- result of folding over all the results of a 'Control.Lens.Fold.Fold' or -- 'Control.Lens.Traversal.Traversal' that points at a monoidal values. -- -- This is the same operation as 'view' with the arguments flipped. -- -- The fixity and semantics are such that subsequent field accesses can be--- performed with ('Prelude..')+-- performed with ('Prelude..'). -- -- >>> (a,b)^._2 -- b@@ -320,11 +251,11 @@ -- 2.23606797749979 -- -- @--- ('^.') ::             s -> 'Getter' s a             -> a--- ('^.') :: 'Monoid' m => s -> 'Control.Lens.Fold.Fold' s m               -> m--- ('^.') ::             s -> 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a         -> a--- ('^.') ::             s -> 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a        -> a--- ('^.') :: 'Monoid' m => s -> 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s m   -> m+-- ('^.') ::             s -> 'Getter' s a     -> a+-- ('^.') :: 'Data.Monoid.Monoid' m => s -> 'Control.Lens.Fold.Fold' s m       -> m+-- ('^.') ::             s -> 'Control.Lens.Iso.Iso'' s a       -> a+-- ('^.') ::             s -> 'Lens'' s a      -> a+-- ('^.') :: 'Data.Monoid.Monoid' m => s -> 'Control.Lens.Traversal.Traversal'' s m -> m -- @ (^.) :: s -> Getting a s t a b -> a s ^. l = runAccessor (l Accessor s)@@ -334,8 +265,7 @@ -- MonadState ------------------------------------------------------------------------------- --- |--- Use the target of a 'Control.Lens.Type.Lens', 'Control.Lens.Iso.Iso', or+-- | Use the target of a 'Lens', 'Control.Lens.Iso.Iso', or -- 'Getter' in the current state, or use a summary of a -- 'Control.Lens.Fold.Fold' or 'Control.Lens.Traversal.Traversal' that points -- to a monoidal value.@@ -347,18 +277,17 @@ -- "hello" -- -- @--- 'use' :: 'MonadState' s m             => 'Getter' s a             -> m a--- 'use' :: ('MonadState' s m, 'Monoid' r) => 'Control.Lens.Fold.Fold' s r               -> m r--- 'use' :: 'MonadState' s m             => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a         -> m a--- 'use' :: 'MonadState' s m             => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a        -> m a--- 'use' :: ('MonadState' s m, 'Monoid' r) => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s r   -> m r+-- 'use' :: 'MonadState' s m             => 'Getter' s a     -> m a+-- 'use' :: ('MonadState' s m, 'Data.Monoid.Monoid' r) => 'Control.Lens.Fold.Fold' s r       -> m r+-- 'use' :: 'MonadState' s m             => 'Control.Lens.Iso.Iso'' s a       -> m a+-- 'use' :: 'MonadState' s m             => 'Lens'' s a      -> m a+-- 'use' :: ('MonadState' s m, 'Data.Monoid.Monoid' r) => 'Control.Lens.Traversal.Traversal'' s r -> m r -- @ use :: MonadState s m => Getting a s t a b -> m a use l = State.gets (view l) {-# INLINE use #-} --- |--- Use the target of a 'Control.Lens.Type.Lens', 'Control.Lens.Iso.Iso' or+-- | Use the target of a 'Lens', 'Control.Lens.Iso.Iso' or -- 'Getter' in the current state, or use a summary of a -- 'Control.Lens.Fold.Fold' or 'Control.Lens.Traversal.Traversal' that -- points to a monoidal value.@@ -367,25 +296,101 @@ -- 5 -- -- @--- 'uses' :: 'MonadState' s m             => 'Getter' s a           -> (a -> r) -> m r--- 'uses' :: ('MonadState' s m, 'Monoid' r) => 'Control.Lens.Fold.Fold' s a             -> (a -> r) -> m r--- 'uses' :: 'MonadState' s m             => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a      -> (a -> r) -> m r--- 'uses' :: 'MonadState' s m             => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a       -> (a -> r) -> m r--- 'uses' :: ('MonadState' s m, 'Monoid' r) => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a -> (a -> r) -> m r+-- 'uses' :: 'MonadState' s m             => 'Getter' s a     -> (a -> r) -> m r+-- 'uses' :: ('MonadState' s m, 'Data.Monoid.Monoid' r) => 'Control.Lens.Fold.Fold' s a       -> (a -> r) -> m r+-- 'uses' :: 'MonadState' s m             => 'Lens'' s a      -> (a -> r) -> m r+-- 'uses' :: 'MonadState' s m             => 'Control.Lens.Iso.Iso'' s a       -> (a -> r) -> m r+-- 'uses' :: ('MonadState' s m, 'Data.Monoid.Monoid' r) => 'Control.Lens.Traversal.Traversal'' s a -> (a -> r) -> m r -- @-uses :: MonadState s m => Getting r s t a b -> (a -> r) -> m r+--+-- @+-- 'uses' :: 'MonadState' s m => 'Getting' r s t a b -> (a -> r) -> m r+-- @+uses :: (Profunctor p, MonadState s m) => Overloading p (->) (Accessor r) s t a b -> p a r -> m r uses l f = State.gets (views l f) {-# INLINE uses #-} +-- | This is a generalized form of 'listen' that only extracts the portion of+-- the log that is focused on by a 'Getter'. If given a 'Fold' or a 'Traversal'+-- then a monoidal summary of the parts of the log that are visited will be+-- returned.+--+-- @+-- 'listening' :: 'MonadWriter' w m             => 'Getter' w u     -> m a -> m (a, u)+-- 'listening' :: 'MonadWriter' w m             => 'Lens'' w u      -> m a -> m (a, u)+-- 'listening' :: 'MonadWriter' w m             => 'Iso'' w u       -> m a -> m (a, u)+-- 'listening' :: ('MonadWriter' w m, 'Monoid' u) => 'Fold' w u       -> m a -> m (a, u)+-- 'listening' :: ('MonadWriter' w m, 'Monoid' u) => 'Traversal'' w u -> m a -> m (a, u)+-- 'listening' :: ('MonadWriter' w m, 'Monoid' u) => 'Prism'' w u     -> m a -> m (a, u)+-- @+listening :: MonadWriter w m => Getting u w t u b -> m a -> m (a, u)+listening l m = do+  (a, w) <- listen m+  return (a, view l w)+{-# INLINE listening #-} +-- | This is a generalized form of 'listen' that only extracts the portion of+-- the log that is focused on by a 'Getter'. If given a 'Fold' or a 'Traversal'+-- then a monoidal summary of the parts of the log that are visited will be+-- returned.+--+-- @+-- 'ilistening' :: 'MonadWriter' w m             => 'IndexedGetter' i w u     -> m a -> m (a, (i, u))+-- 'ilistening' :: 'MonadWriter' w m             => 'IndexedLens'' i w u      -> m a -> m (a, (i, u))+-- 'ilistening' :: ('MonadWriter' w m, 'Monoid' u) => 'IndexedFold' i w u       -> m a -> m (a, (i, u))+-- 'ilistening' :: ('MonadWriter' w m, 'Monoid' u) => 'IndexedTraversal'' i w u -> m a -> m (a, (i, u))+-- @+ilistening :: MonadWriter w m => IndexedGetting i (i, u) w t u b -> m a -> m (a, (i, u))+ilistening l m = do+  (a, w) <- listen m+  return (a, iview l w)+{-# INLINE ilistening #-}++-- | This is a generalized form of 'listen' that only extracts the portion of+-- the log that is focused on by a 'Getter'. If given a 'Fold' or a 'Traversal'+-- then a monoidal summary of the parts of the log that are visited will be+-- returned.+--+-- @+-- 'listenings' :: 'MonadWriter' w m             => 'Getter' w u     -> (u -> v) -> m a -> m (a, v)+-- 'listenings' :: 'MonadWriter' w m             => 'Lens'' w u      -> (u -> v) -> m a -> m (a, v)+-- 'listenings' :: 'MonadWriter' w m             => 'Iso'' w u       -> (u -> v) -> m a -> m (a, v)+-- 'listenings' :: ('MonadWriter' w m, 'Monoid' v) => 'Fold' w u       -> (u -> v) -> m a -> m (a, v)+-- 'listenings' :: ('MonadWriter' w m, 'Monoid' v) => 'Traversal'' w u -> (u -> v) -> m a -> m (a, v)+-- 'listenings' :: ('MonadWriter' w m, 'Monoid' v) => 'Prism'' w u     -> (u -> v) -> m a -> m (a, v)+-- @+listenings :: MonadWriter w m => Getting v w t u b -> (u -> v) -> m a -> m (a, v)+listenings l uv m = do+  (a, w) <- listen m+  return (a, views l uv w)+{-# INLINE listenings #-}++-- | This is a generalized form of 'listen' that only extracts the portion of+-- the log that is focused on by a 'Getter'. If given a 'Fold' or a 'Traversal'+-- then a monoidal summary of the parts of the log that are visited will be+-- returned.+--+-- @+-- 'ilistenings' :: 'MonadWriter' w m             => 'IndexedGetter' w u     -> (i -> u -> v) -> m a -> m (a, v)+-- 'ilistenings' :: 'MonadWriter' w m             => 'IndexedLens'' w u      -> (i -> u -> v) -> m a -> m (a, v)+-- 'ilistenings' :: ('MonadWriter' w m, 'Monoid' v) => 'IndexedFold' w u       -> (i -> u -> v) -> m a -> m (a, v)+-- 'ilistenings' :: ('MonadWriter' w m, 'Monoid' v) => 'IndexedTraversal'' w u -> (i -> u -> v) -> m a -> m (a, v)+-- @+ilistenings :: MonadWriter w m => IndexedGetting i v w t u b -> (i -> u -> v) -> m a -> m (a, v)+ilistenings l iuv m = do+  (a, w) <- listen m+  return (a, iviews l iuv w)+{-# INLINE ilistenings #-}++-- | View the value of a 'Getter', 'Control.Lens.Iso.Iso',+ ------------------------------------------------------------------------------ -- Accessing State, Simplified ------------------------------------------------------------------------------ --- |--- This is a type restricted version of 'use' that expects a 'Simple' 'Getter'.+-- | This is a type restricted version of 'use' that expects a 'Simple' 'Getter'. ----- Use the target of a 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens', 'Control.Lens.Iso.Iso', or+-- Use the target of a 'Lens'', 'Control.Lens.Iso.Iso', or -- 'Getter' in the current state, or use a summary of a -- 'Control.Lens.Fold.Fold' or 'Control.Lens.Traversal.Traversal' that points -- to a monoidal value.@@ -401,20 +406,19 @@ -- "hello" -- -- @--- 'use'' :: 'MonadState' s m             => 'Getter' s a             -> m a--- 'use'' :: ('MonadState' s m, 'Monoid' r) => 'Control.Lens.Fold.Fold' s r               -> m r--- 'use'' :: 'MonadState' s m             => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a         -> m a--- 'use'' :: 'MonadState' s m             => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a        -> m a--- 'use'' :: ('MonadState' s m, 'Monoid' r) => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s r   -> m r+-- 'use'' :: 'MonadState' s m             => 'Getter' s a     -> m a+-- 'use'' :: ('MonadState' s m, 'Data.Monoid.Monoid' r) => 'Control.Lens.Fold.Fold' s r       -> m r+-- 'use'' :: 'MonadState' s m             => 'Control.Lens.Iso.Iso'' s a       -> m a+-- 'use'' :: 'MonadState' s m             => 'Lens'' s a      -> m a+-- 'use'' :: ('MonadState' s m, 'Data.Monoid.Monoid' r) => 'Control.Lens.Traversal.Traversal'' s r -> m r -- @ use' :: MonadState s m => Getting a s s a a -> m a use' l = State.gets (view' l) {-# INLINE use' #-} --- |--- This is a type restricted version of 'uses' that expects a 'Simple' 'Getter'.+-- | This is a type restricted version of 'uses' that expects a 'Simple' 'Getter'. ----- Use the target of a 'Control.Lens.Type.Lens', 'Control.Lens.Iso.Iso' or+-- Use the target of a 'Lens', 'Control.Lens.Iso.Iso' or -- 'Getter' in the current state, or use a summary of a -- 'Control.Lens.Fold.Fold' or 'Control.Lens.Traversal.Traversal' that -- points to a monoidal value.@@ -423,13 +427,17 @@ -- 5 -- -- @--- 'uses'' :: 'MonadState' s m             => 'Getter' s a           -> (a -> r) -> m r--- 'uses'' :: ('MonadState' s m, 'Monoid' r) => 'Control.Lens.Fold.Fold' s a             -> (a -> r) -> m r--- 'uses'' :: 'MonadState' s m             => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a      -> (a -> r) -> m r--- 'uses'' :: 'MonadState' s m             => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a       -> (a -> r) -> m r--- 'uses'' :: ('MonadState' s m, 'Monoid' r) => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a -> (a -> r) -> m r+-- 'uses'' :: 'MonadState' s m             => 'Getter' s a     -> (a -> r) -> m r+-- 'uses'' :: ('MonadState' s m, 'Data.Monoid.Monoid' r) => 'Control.Lens.Fold.Fold' s a       -> (a -> r) -> m r+-- 'uses'' :: 'MonadState' s m             => 'Lens'' s a      -> (a -> r) -> m r+-- 'uses'' :: 'MonadState' s m             => 'Control.Lens.Iso.Iso'' s a       -> (a -> r) -> m r+-- 'uses'' :: ('MonadState' s m, 'Data.Monoid.Monoid' r) => 'Control.Lens.Traversal.Traversal'' s a -> (a -> r) -> m r -- @-uses' :: MonadState s m => Getting r s s a a -> (a -> r) -> m r+--+-- @+-- 'uses'' :: 'MonadState' s m => 'Getting' r s s a a -> (a -> r) -> m r+-- @+uses' :: (Profunctor p, MonadState s m) => Overloading' p (->) (Accessor r) s a -> p a r -> m r uses' l f = State.gets (views' l f) {-# INLINE uses' #-} @@ -440,11 +448,13 @@ -- | This is a type restricted version of 'view' that expects a 'Simple' 'Getter'. -- -- View the value pointed to by a 'Getter', 'Control.Lens.Iso.Iso' or--- 'Control.Lens.Type.Lens' or the result of folding over all the results of a+-- 'Lens' or the result of folding over all the results of a -- 'Control.Lens.Fold.Fold' or 'Control.Lens.Traversal.Traversal' that points -- at a monoidal values. ----- @'view'' . 'to' ≡ 'id'@+-- @+-- 'view'' '.' 'to' ≡ 'id'+-- @ -- -- >>> view' (to f) a -- f a@@ -459,71 +469,128 @@ -- "world" -- -- As 'view'' is commonly used to access the target of a 'Getter' or obtain a monoidal summary of the targets of a 'Fold',--- It may be useful to think of it as having one of these more restrictive signatures:+-- It may be useful to think of it as having one of these more restricted signatures: -- -- @--- 'view'' ::             'Getter' s a             -> s -> a--- 'view'' :: 'Monoid' m => 'Control.Lens.Fold.Fold' s m               -> s -> m--- 'view'' ::             'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a         -> s -> a--- 'view'' ::             'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a        -> s -> a--- 'view'' :: 'Monoid' m => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s m   -> s -> m+-- 'view'' ::             'Getter' s a     -> s -> a+-- 'view'' :: 'Data.Monoid.Monoid' m => 'Control.Lens.Fold.Fold' s m       -> s -> m+-- 'view'' ::             'Control.Lens.Iso.Iso'' s a       -> s -> a+-- 'view'' ::             'Lens'' s a      -> s -> a+-- 'view'' :: 'Data.Monoid.Monoid' m => 'Control.Lens.Traversal.Traversal'' s m -> s -> m -- @ ----- In a more general setting, such as when working with a monad transformer stack you can use:+-- In a more general setting, such as when working with a 'Monad' transformer stack you can use: -- -- @--- 'view'' :: 'MonadReader' s m             => 'Getter' s a           -> m a--- 'view'' :: ('MonadReader' s m, 'Monoid' a) => 'Control.Lens.Fold.Fold' s a             -> m a--- 'view'' :: 'MonadReader' s m             => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a       -> m a--- 'view'' :: 'MonadReader' s m             => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a      -> m a--- 'view'' :: ('MonadReader' s m, 'Monoid' a) => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a -> m a+-- 'view'' :: 'MonadReader' s m             => 'Getter' s a     -> m a+-- 'view'' :: ('MonadReader' s m, 'Data.Monoid.Monoid' a) => 'Control.Lens.Fold.Fold' s a       -> m a+-- 'view'' :: 'MonadReader' s m             => 'Control.Lens.Iso.Iso'' s a       -> m a+-- 'view'' :: 'MonadReader' s m             => 'Lens'' s a      -> m a+-- 'view'' :: ('MonadReader' s m, 'Data.Monoid.Monoid' a) => 'Control.Lens.Traversal.Traversal'' s a -> m a -- @ view' :: MonadReader s m => Getting a s s a a -> m a-view' l = Reader.asks (runAccessor# (l Accessor))+view' l = Reader.asks (runAccessor #. l Accessor) {-# INLINE view' #-}  -- | This is a type restricted version of 'views' that expects a 'Simple' 'Getter'. -- -- View the value of a 'Getter', 'Control.Lens.Iso.Iso',--- 'Control.Lens.Type.Lens' or the result of folding over the result of mapping+-- 'Lens' or the result of folding over the result of mapping -- the targets of a 'Control.Lens.Fold.Fold' or -- 'Control.Lens.Traversal.Traversal'. ----- It may be useful to think of 'perviews' as having these more restrictive--- signatures:------ @'views'' l f ≡ 'view'' (l '.' 'to' f)@+-- @+-- 'views'' l f ≡ 'view'' (l '.' 'to' f)+-- @ -- -- >>> views' _2 length (1,"hello") -- 5 -- -- As 'views'' is commonly used to access the target of a 'Getter' or obtain a monoidal summary of the targets of a 'Fold',--- It may be useful to think of it as having one of these more restrictive signatures:+-- It may be useful to think of it as having one of these more restricted signatures: -- -- @--- 'views'' ::             'Getter' s a             -> (a -> r) -> s -> r--- 'views'' :: 'Monoid' m => 'Control.Lens.Fold.Fold' s a               -> (a -> m) -> s -> m--- 'views'' ::             'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a         -> (a -> r) -> s -> r--- 'views'' ::             'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a        -> (a -> r) -> s -> r--- 'views'' :: 'Monoid' m => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a   -> (a -> m) -> s -> m+-- 'views'' ::             'Getter' s a     -> (a -> r) -> s -> r+-- 'views'' :: 'Data.Monoid.Monoid' m => 'Control.Lens.Fold.Fold' s a       -> (a -> m) -> s -> m+-- 'views'' ::             'Control.Lens.Iso.Iso'' s a       -> (a -> r) -> s -> r+-- 'views'' ::             'Lens'' s a      -> (a -> r) -> s -> r+-- 'views'' :: 'Data.Monoid.Monoid' m => 'Control.Lens.Traversal.Traversal'' s a -> (a -> m) -> s -> m -- @ ----- In a more general setting, such as when working with a monad transformer stack you can use:+-- In a more general setting, such as when working with a 'Monad' transformer stack you can use: -- -- @--- 'views'' :: 'MonadReader' s m             => 'Getter' s a           -> (a -> r) -> m r--- 'views'' :: ('MonadReader' s m, 'Monoid' a) => 'Control.Lens.Fold.Fold' s a             -> (a -> r) -> m r--- 'views'' :: 'MonadReader' s m             => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a       -> (a -> r) -> m r--- 'views'' :: 'MonadReader' s m             => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a      -> (a -> r) -> m r--- 'views'' :: ('MonadReader' s m, 'Monoid' a) => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a -> (a -> r) -> m r+-- 'views'' :: 'MonadReader' s m             => 'Getter' s a     -> (a -> r) -> m r+-- 'views'' :: ('MonadReader' s m, 'Data.Monoid.Monoid' a) => 'Control.Lens.Fold.Fold' s a       -> (a -> r) -> m r+-- 'views'' :: 'MonadReader' s m             => 'Control.Lens.Iso.Iso'' s a       -> (a -> r) -> m r+-- 'views'' :: 'MonadReader' s m             => 'Lens'' s a      -> (a -> r) -> m r+-- 'views'' :: ('MonadReader' s m, 'Data.Monoid.Monoid' a) => 'Control.Lens.Traversal.Traversal'' s a -> (a -> r) -> m r -- @-views' :: MonadReader s m => Getting r s s a a -> (a -> r) -> m r-views' l f = Reader.asks (runAccessor# (l (accessor# f)))+--+-- @+-- 'views'' :: 'MonadReader' s m => 'Getting' r s s a a -> (a -> r) -> m r+-- @+views' :: (Profunctor p, MonadReader s m) => Overloading' p (->) (Accessor r) s a -> p a r -> m r+views' l f = Reader.asks (runAccessor #. l (rmap Accessor f)) {-# INLINE views' #-}  --------------------------------------------------------------------------------- Reified Getters+-- Indexed Getters ------------------------------------------------------------------------------ --- | Useful for storing getters in containers.-newtype ReifiedGetter s a = ReifyGetter { reflectGetter :: Getter s a }+-- | View the index and value of an 'IndexedGetter' into the current environment as a pair.+--+-- When applied to an 'IndexedFold' the result will most likely be a nonsensical monoidal summary of+-- the indices tupled with a monoidal summary of the values and probably not whatever it is you wanted.+iview :: MonadReader s m => IndexedGetting i (i,a) s t a b -> m (i,a)+iview l = asks (runAccessor #. l (Indexed $ \i -> Accessor #. (,) i))+{-# INLINE iview #-}++-- | View a function of the index and value of an 'IndexedGetter' into the current environment.+--+-- When applied to an 'IndexedFold' the result will be a monoidal summary instead of a single answer.+--+-- @+-- 'iviews' ≡ 'Control.Lens.Fold.ifoldMapOf'+-- @+iviews :: MonadReader s m => IndexedGetting i r s t a b -> (i -> a -> r) -> m r+iviews l = views l .# Indexed+{-# INLINE iviews #-}++-- | Use the index and value of an 'IndexedGetter' into the current state as a pair.+--+-- When applied to an 'IndexedFold' the result will most likely be a nonsensical monoidal summary of+-- the indices tupled with a monoidal summary of the values and probably not whatever it is you wanted.+iuse :: MonadState s m => IndexedGetting i (i,a) s t a b -> m (i,a)+iuse l = gets (runAccessor #. l (Indexed $ \i -> Accessor #. (,) i))+{-# INLINE iuse #-}++-- | Use a function of the index and value of an 'IndexedGetter' into the current state.+--+-- When applied to an 'IndexedFold' the result will be a monoidal summary instead of a single answer.+iuses :: MonadState s m => IndexedGetting i r s t a b -> (i -> a -> r) -> m r+iuses l = uses l .# Indexed+{-# INLINE iuses #-}++-- | View the value pointed to by a 'Getter' or 'Lens'.+--+-- This is the same operation as 'iview' with the arguments flipped.+--+-- The fixity and semantics are such that subsequent field accesses can be+-- performed with ('Prelude..').+--+-- >>> (a,b,c,d)^@._2+-- (1,b)+--+-- >>> ("hello","world","!!!")^@._2+-- (1,"world")+--+-- @+-- ('^@.') :: s -> 'IndexedGetter' i s a -> (i, a)+-- ('^@.') :: s -> 'IndexedLens'' i s a  -> (i, a)+-- @+--+-- The result probably doesn't have much meaning when applied to an 'IndexedFold'.+(^@.) :: s -> IndexedGetting i (i, a) s t a b -> (i, a)+s ^@. l = runAccessor $ l (Indexed $ \i -> Accessor #. (,) i) s+{-# INLINE (^@.) #-}
src/Control/Lens/Indexed.hs view
@@ -1,99 +1,681 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE GADTs #-} {-# LANGUAGE Rank2Types #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE ScopedTypeVariables #-}------------------------------------------------------------------------------+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE UndecidableInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FunctionalDependencies #-}+#ifdef DEFAULT_SIGNATURES+{-# LANGUAGE DefaultSignatures #-}+#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 706+#define MPTC_DEFAULTS+#endif+#endif+#ifdef TRUSTWORTHY+{-# LANGUAGE Trustworthy #-} -- vector, hashable+#endif++#ifndef MIN_VERSION_containers+#define MIN_VERSION_containers(x,y,z) 1+#endif+------------------------------------------------------------------------------- -- | -- Module      :  Control.Lens.Indexed--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  provisional--- Portability :  rank 2 types, MPTCs, TFs, flexible+-- Portability :  Rank2Types ----- Combinators for working with 'Indexed' functions.-----------------------------------------------------------------------------+-- (The classes in here need to be defined together for @DefaultSignatures@ to work.)+------------------------------------------------------------------------------- module Control.Lens.Indexed-  ( Indexable(..)-  -- * Indexed Functions+  (+  -- * Indexing+    Indexable(..)+  , Conjoined(..)   , Indexed(..)-  , (<.>), (<.), (.>)-  , icompose+  , (<.), (<.>), (.>)   , reindexed-  -- * Indexing existing lenses, traversals, etc.+  , icompose   , indexing   , indexing64+  -- * Indexed Functors+  , FunctorWithIndex(..)+  -- * Indexed Foldables+  , FoldableWithIndex(..)+  , ifolding+  -- ** Indexed Foldable Combinators+  , iany+  , iall+  , itraverse_+  , ifor_+  , imapM_+  , iforM_+  , iconcatMap+  , ifind+  , ifoldrM+  , ifoldlM+  , itoList+  -- * Converting to Folds+  , withIndex+  , asIndex+  -- * Restricting by Index+  , indices+  , index+  -- * Indexed Traversables+  , TraversableWithIndex(..)+  -- * Indexed Traversable Combinators+  , ifor+  , imapM+  , iforM+  , imapAccumR+  , imapAccumL   ) where -import Control.Lens.Classes-import Control.Lens.Internal-import Data.Int+import Control.Applicative+import Control.Applicative.Backwards+import Control.Monad (void, liftM)+import Control.Monad.Trans.State.Lazy as Lazy+import Control.Lens.Fold+import Control.Lens.Internal.Fold+import Control.Lens.Internal.Getter+import Control.Lens.Internal.Indexed+import Control.Lens.Internal.Level+import Control.Lens.Internal.Magma+import Control.Lens.Setter+import Control.Lens.Traversal+import Control.Lens.Type+import Data.Foldable+import Data.Functor.Identity+import Data.Functor.Reverse+import Data.Hashable+import Data.HashMap.Lazy as HashMap+import Data.IntMap as IntMap+import Data.Map as Map+import Data.Monoid+import Data.Profunctor.Unsafe+import Data.Sequence hiding (index)+import Data.Traversable+import Data.Tuple (swap)+import Data.Vector (Vector)+import qualified Data.Vector as V  infixr 9 <.>, <., .> +-- $setup+-- >>> import Control.Lens+ -- | Compose an 'Indexed' function with a non-indexed function. -- -- Mnemonically, the @<@ points to the indexing we want to preserve.-(<.)  :: Indexable i k => Indexed i b c -> (a -> b) -> k a c-Indexed ibc <. ab = indexed $ \ia -> ibc (ab . ia)+(<.) :: Indexable i p => (Indexed i s t -> r) -> ((a -> b) -> s -> t) -> p a b -> r+(<.) f g h = f . Indexed $ g . indexed h {-# INLINE (<.) #-}  -- | Compose a non-indexed function with an 'Indexed' function. -- -- Mnemonically, the @>@ points to the indexing we want to preserve.-(.>)  :: Indexable i k => (b -> c) -> Indexed i a b -> k a c-bc .> Indexed iab = indexed (bc . iab)+--+-- This is the same as @('.')@. +--+-- @f '.' g@ (and @f '.>' g@) gives you the index of @g@ unless @g@ is index-preserving, like a+-- 'Prism', 'Iso' or 'Equality', in which case it'll pass through the index of @f@.+(.>) :: (st -> r) -> (kab -> st) -> kab -> r+(.>) = (.) {-# INLINE (.>) #-}  -- | Remap the index.-reindexed :: Indexable j k => (i -> j) -> Indexed i a b -> k a b-reindexed ij (Indexed iab) = indexed $ \ ja -> iab $ \i -> ja (ij i)+reindexed :: Indexable j p => (i -> j) -> (Indexed i a b -> r) -> p a b -> r+reindexed ij f g = f . Indexed $ indexed g . ij {-# INLINE reindexed #-} --- | Composition of 'Indexed' functions+-- | Composition of 'Indexed' functions. -- -- Mnemonically, the @\<@ and @\>@ points to the fact that we want to preserve the indices.-(<.>) :: Indexable (i, j) k => Indexed i b c -> Indexed j a b -> k a c+(<.>) :: Indexable (i, j) p => (Indexed i s t -> r) -> (Indexed j a b -> s -> t) -> p a b -> r f <.> g = icompose (,) f g {-# INLINE (<.>) #-} --- | Composition of 'Indexed' functions with a user supplied function for combining indices-icompose :: Indexable k r => (i -> j -> k) -> Indexed i b c -> Indexed j a b -> r a c-icompose ijk (Indexed ibc) (Indexed jab) = indexed $ \ka -> ibc $ \i -> jab $ \j -> ka (ijk i j)+-- | Composition of 'Indexed' functions with a user supplied function for combining indices.+icompose :: Indexable p c => (i -> j -> p) -> (Indexed i s t -> r) -> (Indexed j a b -> s -> t) -> c a b -> r+icompose ijk istr jabst cab = istr . Indexed $ \i -> jabst . Indexed $ \j -> indexed cab $ ijk i j {-# INLINE icompose #-} --- | Transform a 'Traversal' into an 'Control.Lens.IndexedTraversal.IndexedTraversal' or--- a 'Fold' into an 'Control.Lens.IndexedFold.IndexedFold', etc.+-------------------------------------------------------------------------------+-- Converting to Folds+-------------------------------------------------------------------------------++-- | Fold a container with indices returning both the indices and the values. --+-- The result is only valid to compose in a 'Traversal', if you don't edit the+-- index as edits to the index have no effect.+withIndex :: (Indexable i p, Functor f) => Overloading p (Indexed i) f s t (i, s) (j, t)+withIndex f = Indexed $ \i a -> snd <$> indexed f i (i, a)+{-# INLINE withIndex #-}++-- | When composed with an 'IndexedFold' or 'IndexedTraversal' this yields an+-- ('Indexed') 'Fold' of the indices.+asIndex :: (Indexable i p, Functor f, Gettable f) => Overloading' p (Indexed i) f s i+asIndex f = Indexed $ \i _ -> coerce (indexed f i i)+{-# INLINE asIndex #-}++-------------------------------------------------------------------------------+-- Restricting by index+-------------------------------------------------------------------------------++-- | This allows you to filter an 'IndexedFold', 'IndexedGetter', 'IndexedTraversal' or 'IndexedLens' based on a predicate+-- on the indices.+--+-- >>> ["hello","the","world","!!!"]^..traversed.indices even+-- ["hello","world"]+--+-- >>> over (traversed.indices (>0)) Prelude.reverse $ ["He","was","stressed","o_O"]+-- ["He","saw","desserts","O_o"]+indices :: (Indexable i p, Applicative f) => (i -> Bool) -> Overloading' p (Indexed i) f a a+indices p f = Indexed $ \i a -> if p i then indexed f i a else pure a+{-# INLINE indices #-}++-- | This allows you to filter an 'IndexedFold', 'IndexedGetter', 'IndexedTraversal' or 'IndexedLens' based on an index.+--+-- >>> ["hello","the","world","!!!"]^?traversed.index 2+-- Just "world"+index :: (Indexable i p, Eq i, Applicative f) => i -> Overloading' p (Indexed i) f a a+index j f = Indexed $ \i a -> if j == i then indexed f i a else pure a+{-# INLINE index #-}+++-------------------------------------------------------------------------------+-- FunctorWithIndex+-------------------------------------------------------------------------------++-- | A 'Functor' with an additional index.+--+-- Instances must satisfy a modified form of the 'Functor' laws:+-- -- @--- 'indexing' :: 'Control.Lens.Traversal.Traversal' s t a b -> 'Control.Lens.IndexedTraversal.IndexedTraversal' 'Int' s t a b--- 'indexing' :: 'Control.Lens.Prism.Prism' s t a b         -> 'Control.Lens.IndexedLens.IndexedTraversal' 'Int' s t a b--- 'indexing' :: 'Control.Lens.Type.Lens' s t a b           -> 'Control.Lens.IndexedLens.IndexedLens' 'Int' s t a b--- 'indexing' :: 'Control.Lens.Iso.Iso' s t a b             -> 'Control.Lens.IndexedLens.IndexedLens' 'Int' s t a b--- 'indexing' :: 'Control.Lens.Fold.Fold' s t               -> 'Control.Lens.IndexedFold.IndexedFold' 'Int' s t--- 'indexing' :: 'Control.Lens.Getter.Getter' s t           -> 'Control.Lens.IndexedGetter.IndexedGetter' 'Int' s t a b+-- 'imap' f '.' 'imap' g ≡ 'imap' (\\i -> f i '.' g i)+-- 'imap' (\\_ a -> a) ≡ 'id' -- @-indexing :: Indexable Int k => ((a -> Indexing f b) -> s -> Indexing f t) -> k (a -> f b) (s -> f t)-indexing l = indexed $ \iafb s -> case runIndexing (l (\a -> Indexing (\i -> i `seq` (iafb i a, i + 1))) s) 0 of-  (r, _) -> r-{-# INLINE indexing #-}+class Functor f => FunctorWithIndex i f | f -> i where+  -- | Map with access to the index.+  imap :: (i -> a -> b) -> f a -> f b+#ifdef MPTC_DEFAULTS+  default imap :: TraversableWithIndex i f => (i -> a -> b) -> f a -> f b+  imap = iover itraversed+  {-# INLINE imap #-}+#endif --- | Transform a 'Traversal' into an 'Control.Lens.IndexedTraversal.IndexedTraversal' or--- a 'Fold' into an 'Control.Lens.IndexedFold.IndexedFold', etc.+  -- | The 'IndexedSetter' for a 'FunctorWithIndex'.+  --+  -- If you don't need access to the index, then 'mapped' is more flexible in what it accepts.+  imapped :: FunctorWithIndex i f => IndexedSetter i (f a) (f b) a b+  imapped = conjoined mapped (isets imap)+  {-# INLINE imapped #-}++-------------------------------------------------------------------------------+-- FoldableWithIndex+-------------------------------------------------------------------------------++-- | A container that supports folding with an additional index.+class Foldable f => FoldableWithIndex i f | f -> i where+  --+  -- | Fold a container by mapping value to an arbitrary 'Monoid' with access to the index @i@.+  --+  -- When you don't need access to the index then 'foldMap' is more flexible in what it accepts.+  --+  -- @+  -- 'foldMap' ≡ 'ifoldMap' '.' 'const'+  -- @+  ifoldMap :: Monoid m => (i -> a -> m) -> f a -> m+#ifdef MPTC_DEFAULTS+  default ifoldMap :: (TraversableWithIndex i f, Monoid m) => (i -> a -> m) -> f a -> m+  ifoldMap = ifoldMapOf itraversed+  {-# INLINE ifoldMap #-}+#endif++  -- | The 'IndexedFold' of a 'FoldableWithIndex' container.+  ifolded :: IndexedFold i (f a) a+  ifolded = conjoined folded $ \f -> coerce . getFolding . ifoldMap (\i -> Folding #. indexed f i)+  {-# INLINE ifolded #-}++  -- | Right-associative fold of an indexed container with access to the index @i@.+  --+  -- When you don't need access to the index then 'Data.Foldable.foldr' is more flexible in what it accepts.+  --+  -- @+  -- 'Data.Foldable.foldr' ≡ 'ifoldr' '.' 'const'+  -- @+  ifoldr   :: (i -> a -> b -> b) -> b -> f a -> b+  ifoldr f z t = appEndo (ifoldMap (\i -> Endo #. f i) t) z++  -- | Left-associative fold of an indexed container with access to the index @i@.+  --+  -- When you don't need access to the index then 'Data.Foldable.foldl' is more flexible in what it accepts.+  --+  -- @+  -- 'Data.Foldable.foldl' ≡ 'ifoldl' '.' 'const'+  -- @+  ifoldl :: (i -> b -> a -> b) -> b -> f a -> b+  ifoldl f z t = appEndo (getDual (ifoldMap (\i -> Dual #. Endo #. flip (f i)) t)) z++  -- | /Strictly/ fold right over the elements of a structure with access to the index @i@.+  --+  -- When you don't need access to the index then 'foldr'' is more flexible in what it accepts.+  --+  -- @+  -- 'foldr'' ≡ 'ifoldr'' '.' 'const'+  -- @+  ifoldr' :: (i -> a -> b -> b) -> b -> f a -> b+  ifoldr' f z0 xs = ifoldl f' id xs z0+    where f' i k x z = k $! f i x z++  -- | Fold over the elements of a structure with an index, associating to the left, but /strictly/.+  --+  -- When you don't need access to the index then 'Control.Lens.Fold.foldlOf'' is more flexible in what it accepts.+  --+  -- @+  -- 'Control.Lens.Fold.foldlOf'' l ≡ 'ifoldlOf'' l '.' 'const'+  -- @+  ifoldl' :: (i -> b -> a -> b) -> b -> f a -> b+  ifoldl' f z0 xs = ifoldr f' id xs z0+    where f' i x k z = k $! f i z x++-- | Obtain a 'Fold' by lifting an operation that returns a 'Foldable' result. ----- This combinator is like 'indexing' except that it handles large 'Traversal's and 'Fold's gracefully.+-- This can be useful to lift operations from @'Data.List'@ and elsewhere into a 'Fold'.+ifolding :: FoldableWithIndex i f => (s -> f a) -> IndexedFold i s a+ifolding sfa iagb = coerce . itraverse_ (indexed iagb) . sfa+{-# INLINE ifolding #-}++-- | Return whether or not any element in a container satisfies a predicate, with access to the index @i@. --+-- When you don't need access to the index then 'any' is more flexible in what it accepts.+-- -- @--- 'indexing64' :: 'Control.Lens.Traversal.Traversal' s t a b -> 'Control.Lens.IndexedTraversal.IndexedTraversal' 'Int64' s t a b--- 'indexing64' :: 'Control.Lens.Prism.Prism' s t a b         -> 'Control.Lens.IndexedLens.IndexedTraversal' 'Int64' s t a b--- 'indexing64' :: 'Control.Lens.Type.Lens' s t a b           -> 'Control.Lens.IndexedLens.IndexedLens' 'Int64' s t a b--- 'indexing64' :: 'Control.Lens.Iso.Iso' s t a b             -> 'Control.Lens.IndexedLens.IndexedLens' 'Int64' s t a b--- 'indexing64' :: 'Control.Lens.Fold.Fold' s t               -> 'Control.Lens.IndexedFold.IndexedFold' 'Int64' s t--- 'indexing64' :: 'Control.Lens.Getter.Getter' s t           -> 'Control.Lens.IndexedGetter.IndexedGetter' 'Int64' s t a b+-- 'any' ≡ 'iany' '.' 'const' -- @-indexing64 :: Indexable Int64 k => ((a -> Indexing64 f b) -> s -> Indexing64 f t) -> k (a -> f b) (s -> f t)-indexing64 l = indexed $ \iafb s -> case runIndexing64 (l (\a -> Indexing64 (\i -> i `seq` (iafb i a, i + 1))) s) 0 of-  (r, _) -> r-{-# INLINE indexing64 #-}+iany :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Bool+iany f = getAny #. ifoldMap (\i -> Any #. f i)+{-# INLINE iany #-}++-- | Return whether or not all elements in a container satisfy a predicate, with access to the index @i@.+--+-- When you don't need access to the index then 'all' is more flexible in what it accepts.+--+-- @+-- 'all' ≡ 'iall' '.' 'const'+-- @+iall :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Bool+iall f = getAll #. ifoldMap (\i -> All #. f i)+{-# INLINE iall #-}++-- | Traverse elements with access to the index @i@, discarding the results.+--+-- When you don't need access to the index then 'traverse_' is more flexible in what it accepts.+--+-- @+-- 'traverse_' l = 'itraverse' '.' 'const'+-- @+itraverse_ :: (FoldableWithIndex i t, Applicative f) => (i -> a -> f b) -> t a -> f ()+itraverse_ f = getTraversed #. ifoldMap (\i -> Traversed #. void . f i)+{-# INLINE itraverse_ #-}++-- | Traverse elements with access to the index @i@, discarding the results (with the arguments flipped).+--+-- @+-- 'ifor_' ≡ 'flip' 'itraverse_'+-- @+--+-- When you don't need access to the index then 'for_' is more flexible in what it accepts.+--+-- @+-- 'for_' a ≡ 'ifor_' a '.' 'const'+-- @+ifor_ :: (FoldableWithIndex i t, Applicative f) => t a -> (i -> a -> f b) -> f ()+ifor_ = flip itraverse_+{-# INLINE ifor_ #-}++-- | Run monadic actions for each target of an 'IndexedFold' or 'Control.Lens.IndexedTraversal.IndexedTraversal' with access to the index,+-- discarding the results.+--+-- When you don't need access to the index then 'Control.Lens.Fold.mapMOf_' is more flexible in what it accepts.+--+-- @+-- 'mapM_' ≡ 'imapM' '.' 'const'+-- @+imapM_ :: (FoldableWithIndex i t, Monad m) => (i -> a -> m b) -> t a -> m ()+imapM_ f = getSequenced #. ifoldMap (\i -> Sequenced #. liftM skip . f i)+{-# INLINE imapM_ #-}++-- | Run monadic actions for each target of an 'IndexedFold' or 'Control.Lens.IndexedTraversal.IndexedTraversal' with access to the index,+-- discarding the results (with the arguments flipped).+--+-- @+-- 'iforM_' ≡ 'flip' 'imapM_'+-- @+--+-- When you don't need access to the index then 'Control.Lens.Fold.forMOf_' is more flexible in what it accepts.+--+-- @+-- 'Control.Lens.Fold.forMOf_' l a ≡ 'iforMOf' l a '.' 'const'+-- @+iforM_ :: (FoldableWithIndex i t, Monad m) => t a -> (i -> a -> m b) -> m ()+iforM_ = flip imapM_+{-# INLINE iforM_ #-}++-- | Concatenate the results of a function of the elements of an indexed container with access to the index.+--+-- When you don't need access to the index then 'concatMap' is more flexible in what it accepts.+--+-- @+-- 'concatMap' ≡ 'iconcatMap' '.' 'const'+-- 'iconcatMap' ≡ 'ifoldMap'+-- @+iconcatMap :: FoldableWithIndex i f => (i -> a -> [b]) -> f a -> [b]+iconcatMap = ifoldMap+{-# INLINE iconcatMap #-}++-- | Searches a container with a predicate that is also supplied the index, returning the left-most element of the structure+-- matching the predicate, or 'Nothing' if there is no such element.+--+-- When you don't need access to the index then 'find' is more flexible in what it accepts.+--+-- @+-- 'find' ≡ 'ifind' '.' 'const'+-- @+ifind :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Maybe (i, a)+ifind p = ifoldr (\i a y -> if p i a then Just (i, a) else y) Nothing+{-# INLINE ifind #-}++-- | Monadic fold right over the elements of a structure with an index.+--+-- When you don't need access to the index then 'foldrM' is more flexible in what it accepts.+--+-- @+-- 'foldrM' ≡ 'ifoldrM' '.' 'const'+-- @+ifoldrM :: (FoldableWithIndex i f, Monad m) => (i -> a -> b -> m b) -> b -> f a -> m b+ifoldrM f z0 xs = ifoldl f' return xs z0+  where f' i k x z = f i x z >>= k+{-# INLINE ifoldrM #-}++-- | Monadic fold over the elements of a structure with an index, associating to the left.+--+-- When you don't need access to the index then 'foldlM' is more flexible in what it accepts.+--+-- @+-- 'foldlM' ≡ 'ifoldlM' '.' 'const'+-- @+ifoldlM :: (FoldableWithIndex i f, Monad m) => (i -> b -> a -> m b) -> b -> f a -> m b+ifoldlM f z0 xs = ifoldr f' return xs z0+  where f' i x k z = f i z x >>= k+{-# INLINE ifoldlM #-}++-- | Extract the key-value pairs from a structure.+--+-- When you don't need access to the indices in the result, then 'Data.Foldable.toList' is more flexible in what it accepts.+--+-- @+-- 'Data.Foldable.toList' ≡ 'Data.List.map' 'fst' '.' 'itoList'+-- @+itoList :: FoldableWithIndex i f => f a -> [(i,a)]+itoList = ifoldr (\i c -> ((i,c):)) []+{-# INLINE itoList #-}++-------------------------------------------------------------------------------+-- TraversableWithIndex+-------------------------------------------------------------------------------++-- | A 'Traversable' with an additional index.+--+-- An instance must satisfy a (modified) form of the 'Traversable' laws:+--+-- @+-- 'itraverse' ('const' 'Identity') ≡ 'Identity'+-- 'fmap' ('itraverse' f) '.' 'itraverse' g ≡ 'Data.Functor.Compose.getCompose' '.' 'itraverse' (\\i -> 'Data.Functor.Compose.Compose' '.' 'fmap' (f i) '.' g i)+-- @+class (FunctorWithIndex i t, FoldableWithIndex i t, Traversable t) => TraversableWithIndex i t | t -> i where+  -- | Traverse an indexed container.+  itraverse :: Applicative f => (i -> a -> f b) -> t a -> f (t b)+#ifdef MPTC_DEFAULTS+  default itraverse :: Applicative f => (Int -> a -> f b) -> t a -> f (t b)+  itraverse = traversed .# Indexed+  {-# INLINE itraverse #-}+#endif++  -- | The 'IndexedTraversal' of a 'TraversableWithIndex' container.+  itraversed :: IndexedTraversal i (t a) (t b) a b+  itraversed = conjoined traverse (itraverse . indexed)+  {-# INLINE itraversed #-}+++-- | Traverse with an index (and the arguments flipped).+--+-- @+-- 'for' a ≡ 'ifor' a '.' 'const'+-- 'ifor' ≡ 'flip' 'itraverse'+-- @+ifor :: (TraversableWithIndex i t, Applicative f) => t a -> (i -> a -> f b) -> f (t b)+ifor = flip itraverse+{-# INLINE ifor #-}++-- | Map each element of a structure to a monadic action,+-- evaluate these actions from left to right, and collect the results, with access+-- the index.+--+-- When you don't need access to the index 'mapM' is more liberal in what it can accept.+--+-- @+-- 'mapM' ≡ 'imapM' '.' 'const'+-- @+imapM :: (TraversableWithIndex i t, Monad m) => (i -> a -> m b) -> t a -> m (t b)+imapM f = unwrapMonad #. itraverse (\i -> WrapMonad #. f i)+{-# INLINE imapM #-}++-- | Map each element of a structure to a monadic action,+-- evaluate these actions from left to right, and collect the results, with access+-- its position (and the arguments flipped).+--+-- @+-- 'forM' a ≡ 'iforM' a '.' 'const'+-- 'iforM' ≡ 'flip' 'imapM'+-- @+iforM :: (TraversableWithIndex i t, Monad m) => t a -> (i -> a -> m b) -> m (t b)+iforM = flip imapM+{-# INLINE iforM #-}++-- | Generalizes 'Data.Traversable.mapAccumR' to add access to the index.+--+-- 'imapAccumROf' accumulates state from right to left.+--+-- @+-- 'Control.Lens.Traversal.mapAccumR' ≡ 'imapAccumR' '.' 'const'+-- @+imapAccumR :: TraversableWithIndex i t => (i -> s -> a -> (s, b)) -> s -> t a -> (s, t b)+imapAccumR f s0 a = swap (Lazy.runState (forwards (itraverse (\i c -> Backwards (Lazy.state (\s -> swap (f i s c)))) a)) s0)+{-# INLINE imapAccumR #-}++-- | Generalizes 'Data.Traversable.mapAccumL' to add access to the index.+--+-- 'imapAccumLOf' accumulates state from left to right.+--+-- @+-- 'Control.Lens.Traversal.mapAccumLOf' ≡ 'imapAccumL' '.' 'const'+-- @+imapAccumL :: TraversableWithIndex i t => (i -> s -> a -> (s, b)) -> s -> t a -> (s, t b)+imapAccumL f s0 a = swap (Lazy.runState (itraverse (\i c -> Lazy.state (\s -> swap (f i s c))) a) s0)+{-# INLINE imapAccumL #-}++-------------------------------------------------------------------------------+-- Instances+-------------------------------------------------------------------------------++instance FunctorWithIndex i f => FunctorWithIndex i (Backwards f) where+  imap f  = Backwards . imap f . forwards++instance FoldableWithIndex i f => FoldableWithIndex i (Backwards f) where+  ifoldMap f = ifoldMap f . forwards++instance TraversableWithIndex i f => TraversableWithIndex i (Backwards f) where+  itraverse f = fmap Backwards . itraverse f . forwards++instance FunctorWithIndex i f => FunctorWithIndex i (Reverse f) where+  imap f = Reverse . imap f . getReverse++instance FoldableWithIndex i f => FoldableWithIndex i (Reverse f) where+  ifoldMap f = getDual . ifoldMap (\i -> Dual #. f i) . getReverse++instance TraversableWithIndex i f => TraversableWithIndex i (Reverse f) where+  itraverse f = fmap Reverse . forwards . itraverse (\i -> Backwards . f i) . getReverse++instance FunctorWithIndex () Identity where+  imap f (Identity a) = Identity (f () a)++instance FoldableWithIndex () Identity where+  ifoldMap f (Identity a) = f () a++instance TraversableWithIndex () Identity where+  itraverse f (Identity a) = Identity <$> f () a++instance FunctorWithIndex k ((,) k) where+  imap f (k,a) = (k, f k a)+  {-# INLINE imap #-}++instance FoldableWithIndex k ((,) k) where+  ifoldMap = uncurry+  {-# INLINE ifoldMap #-}++instance TraversableWithIndex k ((,) k) where+  itraverse f (k, a) = (,) k <$> f k a+  {-# INLINE itraverse #-}++-- | The position in the list is available as the index.+instance FunctorWithIndex Int [] where+  imap = iover itraversed+  {-# INLINE imap #-}+instance FoldableWithIndex Int [] where+  ifoldMap = ifoldMapOf itraversed+  {-# INLINE ifoldMap #-}+instance TraversableWithIndex Int [] where+  itraverse = itraverseOf traversed+  {-# INLINE itraverse #-}++-- | The position in the 'Seq' is available as the index.+instance FunctorWithIndex Int Seq where+  imap = iover itraversed+  {-# INLINE imap #-}+instance FoldableWithIndex Int Seq where+  ifoldMap = ifoldMapOf itraversed+  {-# INLINE ifoldMap #-}+instance TraversableWithIndex Int Seq where+  itraverse = itraverseOf traversed+  {-# INLINE itraverse #-}++instance FunctorWithIndex Int Vector where+  imap = V.imap+  {-# INLINE imap #-}+instance FoldableWithIndex Int Vector where+  ifoldMap = ifoldMapOf itraversed+  {-# INLINE ifoldMap #-}+  ifoldr = V.ifoldr+  ifoldl = V.ifoldl . flip+  ifoldr' = V.ifoldr'+  ifoldl' = V.ifoldl' . flip+instance TraversableWithIndex Int Vector where+  itraverse f = sequenceA . V.imap f+  {-# INLINE itraverse #-}++instance FunctorWithIndex Int IntMap where+  imap = iover itraversed+  {-# INLINE imap #-}+instance FoldableWithIndex Int IntMap where+  ifoldMap = ifoldMapOf itraversed+  {-# INLINE ifoldMap #-}+instance TraversableWithIndex Int IntMap where+#if MIN_VERSION_containers(0,5,0)+  itraverse = IntMap.traverseWithKey+#else+  itraverse f = sequenceA . IntMap.mapWithKey f+#endif+  {-# INLINE itraverse #-}++instance FunctorWithIndex k (Map k) where+  imap = iover itraversed+  {-# INLINE imap #-}+instance FoldableWithIndex k (Map k) where+  ifoldMap = ifoldMapOf itraversed+  {-# INLINE ifoldMap #-}+instance TraversableWithIndex k (Map k) where+#if MIN_VERSION_containers(0,5,0)+  itraverse = Map.traverseWithKey+#else+  itraverse f = sequenceA . Map.mapWithKey f+#endif+  {-# INLINE itraverse #-}++instance (Eq k, Hashable k) => FunctorWithIndex k (HashMap k) where+  imap = iover itraversed+  {-# INLINE imap #-}+instance (Eq k, Hashable k) => FoldableWithIndex k (HashMap k) where+  ifoldMap = ifoldMapOf itraversed+  {-# INLINE ifoldMap #-}+instance (Eq k, Hashable k) => TraversableWithIndex k (HashMap k) where+  itraverse = HashMap.traverseWithKey+  {-# INLINE itraverse #-}++instance FunctorWithIndex r ((->) r) where+  imap f g x = f x (g x)+  {-# INLINE imap #-}++instance FunctorWithIndex i (Level i) where+  imap f = go where+    go (Two n l r) = Two n (go l) (go r)+    go (One i a)   = One i (f i a)+    go Zero        = Zero+  {-# INLINE imap #-}++instance FoldableWithIndex i (Level i) where+  ifoldMap f = go where+    go (Two _ l r) = go l `mappend` go r+    go (One i a)   = f i a+    go Zero        = mempty+  {-# INLINE ifoldMap #-}++instance TraversableWithIndex i (Level i) where+  itraverse f = go where+    go (Two n l r) = Two n <$> go l <*> go r+    go (One i a)   = One i <$> f i a+    go Zero        = pure Zero+  {-# INLINE itraverse #-}++instance FunctorWithIndex i (Magma i t b) where+  imap f (MagmaAp x y)    = MagmaAp (imap f x) (imap f y)+  imap _ (MagmaPure x)    = MagmaPure x+  imap f (MagmaFmap xy x) = MagmaFmap xy (imap f x)+  imap f (Magma i a)      = Magma i (f i a)+  {-# INLINE imap #-}++instance FoldableWithIndex i (Magma i t b) where+  ifoldMap f (MagmaAp x y)   = ifoldMap f x `mappend` ifoldMap f y+  ifoldMap _ MagmaPure{}     = mempty+  ifoldMap f (MagmaFmap _ x) = ifoldMap f x+  ifoldMap f (Magma i a)     = f i a+  {-# INLINE ifoldMap #-}++instance TraversableWithIndex i (Magma i t b) where+  itraverse f (MagmaAp x y)    = MagmaAp <$> itraverse f x <*> itraverse f y+  itraverse _ (MagmaPure x)    = pure (MagmaPure x)+  itraverse f (MagmaFmap xy x) = MagmaFmap xy <$> itraverse f x+  itraverse f (Magma i a)      = Magma i <$> f i a+  {-# INLINE itraverse #-}++-------------------------------------------------------------------------------+-- Misc.+-------------------------------------------------------------------------------++skip :: a -> ()+skip _ = ()+{-# INLINE skip #-}+
− src/Control/Lens/IndexedFold.hs
@@ -1,464 +0,0 @@-{-# LANGUAGE MagicHash #-}-{-# LANGUAGE Rank2Types #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE FlexibleContexts #-}--------------------------------------------------------------------------------- |--- Module      :  Control.Lens.IndexedFold--- Copyright   :  (C) 2012 Edward Kmett--- License     :  BSD-style (see the file LICENSE)--- Maintainer  :  Edward Kmett <ekmett@gmail.com>--- Stability   :  provisional--- Portability :  rank 2 types, MPTCs, TFs, flexible---------------------------------------------------------------------------------module Control.Lens.IndexedFold-  (-  -- * Indexed Folds-    IndexedFold--  -- * Consuming Indexed Folds-  , ifoldMapOf-  , ifoldrOf-  , ifoldlOf-  , ianyOf-  , iallOf-  , itraverseOf_-  , iforOf_-  , imapMOf_-  , iforMOf_-  , iconcatMapOf-  , ifindOf-  , ifoldrOf'-  , ifoldlOf'-  , ifoldrMOf-  , ifoldlMOf-  , itoListOf--  -- * Converting to Folds-  , withIndicesOf-  , indicesOf--  -- * Building Indexed Folds-  , ifiltering-  , ibackwards-  , itakingWhile-  , idroppingWhile--  -- * Storing Indexed Folds-  , ReifiedIndexedFold(..)-  ) where--import Control.Applicative-import Control.Applicative.Backwards-import Control.Lens.Classes-import Control.Lens.Indexed-import Control.Lens.IndexedGetter-import Control.Lens.Internal-import Control.Lens.Internal.Combinators-import Control.Lens.Type-import Control.Monad-import Data.Monoid----------------------------------------------------------------------------------- Indexed Folds----------------------------------------------------------------------------------- | Every 'IndexedFold' is a valid 'Control.Lens.Fold.Fold'.-type IndexedFold i s a = forall k f.-  (Indexable i k, Applicative f, Gettable f) => k (a -> f a) (s -> f s)---- |--- Fold an 'IndexedFold' or 'Control.Lens.IndexedTraversal.IndexedTraversal' by mapping indices and values to an arbitrary 'Monoid' with access--- to the @i@.------ When you don't need access to the index then 'Control.Lens.Fold.foldMapOf' is more flexible in what it accepts.------ @'Control.Lens.Fold.foldMapOf' l ≡ 'ifoldMapOf' l '.' 'const'@------ @--- 'ifoldMapOf' ::             'IndexedGetter' i a s          -> (i -> s -> m) -> a -> m--- 'ifoldMapOf' :: 'Monoid' m => 'IndexedFold' i a s            -> (i -> s -> m) -> a -> m--- 'ifoldMapOf' ::             'Control.Lens.IndexedLens.SimpleIndexedLens' i a s      -> (i -> s -> m) -> a -> m--- 'ifoldMapOf' :: 'Monoid' m => 'Control.Lens.IndexedTraversal.SimpleIndexedTraversal' i a s -> (i -> s -> m) -> a -> m--- @-ifoldMapOf :: IndexedGetting i m s t a b -> (i -> a -> m) -> s -> m-ifoldMapOf l f = runAccessor# (withIndex l (\i -> accessor# (f i)))-{-# INLINE ifoldMapOf #-}---- |--- Right-associative fold of parts of a structure that are viewed through an 'IndexedFold' or 'Control.Lens.IndexedTraversal.IndexedTraversal' with--- access to the @i@.------ When you don't need access to the index then 'Control.Lens.Fold.foldrOf' is more flexible in what it accepts.------ @'Control.Lens.Fold.foldrOf' l ≡ 'ifoldrOf' l '.' 'const'@------ @--- 'ifoldrOf' :: 'IndexedGetter' i s a          -> (i -> a -> r -> r) -> r -> s -> r--- 'ifoldrOf' :: 'IndexedFold' i s a            -> (i -> a -> r -> r) -> r -> s -> r--- 'ifoldrOf' :: 'Control.Lens.IndexedLens.SimpleIndexedLens' i s a      -> (i -> a -> r -> r) -> r -> s -> r--- 'ifoldrOf' :: 'Control.Lens.IndexedTraversal.SimpleIndexedTraversal' i s a -> (i -> a -> r -> r) -> r -> s -> r--- @-ifoldrOf :: IndexedGetting i (Endo r) s t a b -> (i -> a -> r -> r) -> r -> s -> r-ifoldrOf l f z t = appEndo (ifoldMapOf l (\i -> endo# (f i)) t) z-{-# INLINE ifoldrOf #-}---- |--- Left-associative fold of the parts of a structure that are viewed through an 'IndexedFold' or 'Control.Lens.IndexedTraversal.IndexedTraversal' with--- access to the @i@.------ When you don't need access to the index then 'Control.Lens.Fold.foldlOf' is more flexible in what it accepts.------ @'Control.Lens.Fold.foldlOf' l ≡ 'ifoldlOf' l '.' 'const'@------ @--- 'ifoldlOf' :: 'IndexedGetter' i s a          -> (i -> r -> a -> r) -> r -> s -> r--- 'ifoldlOf' :: 'IndexedFold' i s a            -> (i -> r -> a -> r) -> r -> s -> r--- 'ifoldlOf' :: 'Control.Lens.IndexedLens.SimpleIndexedLens' i s a      -> (i -> r -> a -> r) -> r -> s -> r--- 'ifoldlOf' :: 'Control.Lens.IndexedTraversal.SimpleIndexedTraversal' i s a -> (i -> r -> a -> r) -> r -> s -> r--- @-ifoldlOf :: IndexedGetting i (Dual (Endo r)) s t a b -> (i -> r -> a -> r) -> r -> s -> r-ifoldlOf l f z t = appEndo (getDual (ifoldMapOf l (\i -> dual# (endo# (flip (f i)))) t)) z-{-# INLINE ifoldlOf #-}---- |--- Return whether or not any element viewed through an 'IndexedFold' or 'Control.Lens.IndexedTraversal.IndexedTraversal'--- satisfy a predicate, with access to the @i@.------ When you don't need access to the index then 'Control.Lens.Fold.anyOf' is more flexible in what it accepts.------ @'Control.Lens.Fold.anyOf' l ≡ 'ianyOf' l '.' 'const'@------ @--- 'ianyOf' :: 'IndexedGetter' i s a          -> (i -> a -> 'Bool') -> s -> 'Bool'--- 'ianyOf' :: 'IndexedFold' i s a            -> (i -> a -> 'Bool') -> s -> 'Bool'--- 'ianyOf' :: 'Control.Lens.IndexedLens.SimpleIndexedLens' i s a      -> (i -> a -> 'Bool') -> s -> 'Bool'--- 'ianyOf' :: 'Control.Lens.IndexedTraversal.SimpleIndexedTraversal' i s a -> (i -> a -> 'Bool') -> s -> 'Bool'--- @-ianyOf :: IndexedGetting i Any s t a b -> (i -> a -> Bool) -> s -> Bool-ianyOf l f = getAny# (ifoldMapOf l (\i -> any# (f i)))-{-# INLINE ianyOf #-}---- |--- Return whether or not all elements viewed through an 'IndexedFold' or 'Control.Lens.IndexedTraversal.IndexedTraversal'--- satisfy a predicate, with access to the @i@.------ When you don't need access to the index then 'Control.Lens.Fold.allOf' is more flexible in what it accepts.------ @'Control.Lens.Fold.allOf' l ≡ 'iallOf' l '.' 'const'@------ @--- 'iallOf' :: 'IndexedGetter' i s a          -> (i -> a -> 'Bool') -> s -> 'Bool'--- 'iallOf' :: 'IndexedFold' i s a            -> (i -> a -> 'Bool') -> s -> 'Bool'--- 'iallOf' :: 'Control.Lens.IndexedLens.SimpleIndexedLens' i s a      -> (i -> a -> 'Bool') -> s -> 'Bool'--- 'iallOf' :: 'Control.Lens.IndexedTraversal.SimpleIndexedTraversal' i s a -> (i -> a -> 'Bool') -> s -> 'Bool'--- @-iallOf :: IndexedGetting i All s t a b -> (i -> a -> Bool) -> s -> Bool-iallOf l f = getAll# (ifoldMapOf l (\i -> all# (f i)))-{-# INLINE iallOf #-}---- |--- Traverse the targets of an 'IndexedFold' or 'Control.Lens.IndexedTraversal.IndexedTraversal' with access to the @i@, discarding the results.------ When you don't need access to the index then 'Control.Lens.Fold.traverseOf_' is more flexible in what it accepts.------ @'Control.Lens.Fold.traverseOf_' l ≡ 'itraverseOf' l '.' 'const'@------ @--- 'itraverseOf_' :: 'Functor' f     => 'IndexedGetter' i s a          -> (i -> a -> f r) -> s -> f ()--- 'itraverseOf_' :: 'Applicative' f => 'IndexedFold' i s a            -> (i -> a -> f r) -> s -> f ()--- 'itraverseOf_' :: 'Functor' f     => 'Control.Lens.IndexedLens.SimpleIndexedLens' i s a      -> (i -> a -> f r) -> s -> f ()--- 'itraverseOf_' :: 'Applicative' f => 'Control.Lens.IndexedTraversal.SimpleIndexedTraversal' i s a -> (i -> a -> f r) -> s -> f ()--- @-itraverseOf_ :: Functor f => IndexedGetting i (Traversed f) s t a b -> (i -> a -> f r) -> s -> f ()-itraverseOf_ l f = getTraversed# (ifoldMapOf l (\i -> traversed# (void . f i)))-{-# INLINE itraverseOf_ #-}---- |--- Traverse the targets of an 'IndexedFold' or 'Control.Lens.IndexedTraversal.IndexedTraversal' with access to the index, discarding the results--- (with the arguments flipped).------ @'iforOf_' ≡ 'flip' '.' 'itraverseOf_'@------ When you don't need access to the index then 'Control.Lens.Fold.forOf_' is more flexible in what it accepts.------ @'Control.Lens.Fold.forOf_' l a ≡ 'iforOf_' l a '.' 'const'@------ @--- 'iforOf_' :: 'Functor' f     => 'IndexedGetter' i s a          -> s -> (i -> a -> f r) -> f ()--- 'iforOf_' :: 'Applicative' f => 'IndexedFold' i s a            -> s -> (i -> a -> f r) -> f ()--- 'iforOf_' :: 'Functor' f     => 'Control.Lens.IndexedLens.SimpleIndexedLens' i s a      -> s -> (i -> a -> f r) -> f ()--- 'iforOf_' :: 'Applicative' f => 'Control.Lens.IndexedTraversal.SimpleIndexedTraversal' i s a -> s -> (i -> a -> f r) -> f ()--- @-iforOf_ :: Functor f => IndexedGetting i (Traversed f) s t a b -> s -> (i -> a -> f r) -> f ()-iforOf_ = flip . itraverseOf_-{-# INLINE iforOf_ #-}---- |--- Run monadic actions for each target of an 'IndexedFold' or 'Control.Lens.IndexedTraversal.IndexedTraversal' with access to the index,--- discarding the results.------ When you don't need access to the index then 'Control.Lens.Fold.mapMOf_' is more flexible in what it accepts.------ @'Control.Lens.Fold.mapMOf_' l ≡ 'imapMOf' l '.' 'const'@------ @--- 'imapMOf_' :: 'Monad' m => 'IndexedGetter' i s a          -> (i -> a -> m r) -> s -> m ()--- 'imapMOf_' :: 'Monad' m => 'IndexedFold' i s a            -> (i -> a -> m r) -> s -> m ()--- 'imapMOf_' :: 'Monad' m => 'Control.Lens.IndexedLens.SimpleIndexedLens' i s a      -> (i -> a -> m r) -> s -> m ()--- 'imapMOf_' :: 'Monad' m => 'Control.Lens.IndexedTraversal.SimpleIndexedTraversal' i s a -> (i -> a -> m r) -> s -> m ()--- @-imapMOf_ :: Monad m => IndexedGetting i (Sequenced m) s t a b -> (i -> a -> m r) -> s -> m ()-imapMOf_ l f = getSequenced# (ifoldMapOf l (\i -> sequenced# (liftM skip . f i)))-{-# INLINE imapMOf_ #-}--skip :: a -> ()-skip _ = ()-{-# INLINE skip #-}---- |--- Run monadic actions for each target of an 'IndexedFold' or 'Control.Lens.IndexedTraversal.IndexedTraversal' with access to the index,--- discarding the results (with the arguments flipped).------ @'iforMOf_' ≡ 'flip' '.' 'imapMOf_'@------ When you don't need access to the index then 'Control.Lens.Fold.forMOf_' is more flexible in what it accepts.------ @'Control.Lens.Fold.forMOf_' l a ≡ 'iforMOf' l a '.' 'const'@------ @--- 'iforMOf_' :: 'Monad' m => 'IndexedGetter' i s a          -> s -> (i -> a -> m r) -> m ()--- 'iforMOf_' :: 'Monad' m => 'IndexedFold' i s a            -> s -> (i -> a -> m r) -> m ()--- 'iforMOf_' :: 'Monad' m => 'Control.Lens.IndexedLens.SimpleIndexedLens' i s a      -> s -> (i -> a -> m r) -> m ()--- 'iforMOf_' :: 'Monad' m => 'Control.Lens.IndexedTraversal.SimpleIndexedTraversal' i s a -> s -> (i -> a -> m r) -> m ()--- @-iforMOf_ :: Monad m => IndexedGetting i (Sequenced m) s t a b -> s -> (i -> a -> m r) -> m ()-iforMOf_ = flip . imapMOf_-{-# INLINE iforMOf_ #-}---- |--- Concatenate the results of a function of the elements of an 'IndexedFold' or 'Control.Lens.IndexedTraversal.IndexedTraversal'--- with access to the index.------ When you don't need access to the index then 'Control.Lens.Fold.concatMapOf'  is more flexible in what it accepts.------ @--- 'Control.Lens.Fold.concatMapOf' l ≡ 'iconcatMapOf' l '.' 'const'--- 'iconcatMapOf' ≡ 'ifoldMapOf'--- @------ @--- 'iconcatMapOf' :: 'IndexedGetter' i s a          -> (i -> a -> [r]) -> s -> [r]--- 'iconcatMapOf' :: 'IndexedFold' i s a            -> (i -> a -> [r]) -> s -> [r]--- 'iconcatMapOf' :: 'Control.Lens.IndexedLens.SimpleIndexedLens' i s a      -> (i -> a -> [r]) -> s -> [r]--- 'iconcatMapOf' :: 'Control.Lens.IndexedTraversal.SimpleIndexedTraversal' i s a -> (i -> a -> [r]) -> s -> [r]--- @-iconcatMapOf :: IndexedGetting i [r] s t a b -> (i -> a -> [r]) -> s -> [r]-iconcatMapOf = ifoldMapOf-{-# INLINE iconcatMapOf #-}---- | The 'findOf' function takes an 'IndexedFold' or 'Control.Lens.IndexedTraversal.IndexedTraversal', a predicate that is also--- supplied the index, a structure and returns the left-most element of the structure--- matching the predicate, or 'Nothing' if there is no such element.------ When you don't need access to the index then 'Control.Lens.Fold.findOf' is more flexible in what it accepts.------ @'Control.Lens.Fold.findOf' l ≡ 'ifindOf' l '.' 'const'@------ @--- 'ifindOf' :: 'IndexedGetter' s a          -> (i -> a -> 'Bool') -> s -> 'Maybe' (i, a)--- 'ifindOf' :: 'IndexedFold' s a            -> (i -> a -> 'Bool') -> s -> 'Maybe' (i, a)--- 'ifindOf' :: 'Control.Lens.IndexedLens.SimpleIndexedLens' s a      -> (i -> a -> 'Bool') -> s -> 'Maybe' (i, a)--- 'ifindOf' :: 'Control.Lens.IndexedTraversal.SimpleIndexedTraversal' s a -> (i -> a -> 'Bool') -> s -> 'Maybe' (i, a)--- @-ifindOf :: IndexedGetting i (First (i, a)) s t a b -> (i -> a -> Bool) -> s -> Maybe (i, a)-ifindOf l p = getFirst# (ifoldMapOf l step) where-  step i a-    | p i a     = First $ Just (i, a)-    | otherwise = First Nothing-{-# INLINE ifindOf #-}---- | /Strictly/ fold right over the elements of a structure with an index.------ When you don't need access to the index then 'Control.Lens.Fold.foldrOf'' is more flexible in what it accepts.------ @'Control.Lens.Fold.foldrOf'' l ≡ 'ifoldrOf'' l '.' 'const'@------ @--- 'ifoldrOf'' :: 'IndexedGetter' i s a          -> (i -> a -> r -> r) -> r -> s -> r--- 'ifoldrOf'' :: 'IndexedFold' i s a            -> (i -> a -> r -> r) -> r -> s -> r--- 'ifoldrOf'' :: 'Control.Lens.IndexedLens.SimpleIndexedLens' i s a      -> (i -> a -> r -> r) -> r -> s -> r--- 'ifoldrOf'' :: 'Control.Lens.IndexedTraversal.SimpleIndexedTraversal' i s a -> (i -> a -> r -> r) -> r -> s -> r--- @-ifoldrOf' :: IndexedGetting i (Dual (Endo (r -> r))) s t a b -> (i -> a -> r -> r) -> r -> s -> r-ifoldrOf' l f z0 xs = ifoldlOf l f' id xs z0-  where f' i k x z = k $! f i x z-{-# INLINE ifoldrOf' #-}---- | Fold over the elements of a structure with an index, associating to the left, but /strictly/.------ When you don't need access to the index then 'Control.Lens.Fold.foldlOf'' is more flexible in what it accepts.------ @'Control.Lens.Fold.foldlOf'' l ≡ 'ifoldlOf'' l '.' 'const'@------ @--- 'ifoldlOf'' :: 'IndexedGetter' i s a            -> (i -> r -> a -> r) -> r -> s -> r--- 'ifoldlOf'' :: 'IndexedFold' i s a              -> (i -> r -> a -> r) -> r -> s -> r--- 'ifoldlOf'' :: 'Control.Lens.IndexedLens.SimpleIndexedLens' i s a        -> (i -> r -> a -> r) -> r -> s -> r--- 'ifoldlOf'' :: 'Control.Lens.IndexedTraversal.SimpleIndexedTraversal' i s a   -> (i -> r -> a -> r) -> r -> s -> r--- @-ifoldlOf' :: IndexedGetting i (Endo (r -> r)) s t a b -> (i -> r -> a -> r) -> r -> s -> r-ifoldlOf' l f z0 xs = ifoldrOf l f' id xs z0-  where f' i x k z = k $! f i z x-{-# INLINE ifoldlOf' #-}---- | Monadic fold right over the elements of a structure with an index.------ When you don't need access to the index then 'Control.Lens.Fold.foldrMOf' is more flexible in what it accepts.------ @'Control.Lens.Fold.foldrMOf' l ≡ 'ifoldrMOf' l '.' 'const'@------ @--- 'ifoldrMOf' :: 'Monad' m => 'IndexedGetter' i s a          -> (i -> a -> r -> m r) -> r -> s -> r--- 'ifoldrMOf' :: 'Monad' m => 'IndexedFold' i s a            -> (i -> a -> r -> m r) -> r -> s -> r--- 'ifoldrMOf' :: 'Monad' m => 'Control.Lens.IndexedLens.SimpleIndexedLens' i s a      -> (i -> a -> r -> m r) -> r -> s -> r--- 'ifoldrMOf' :: 'Monad' m => 'Control.Lens.IndexedTraversal.SimpleIndexedTraversal' i s a -> (i -> a -> r -> m r) -> r -> s -> r--- @-ifoldrMOf :: Monad m => IndexedGetting i (Dual (Endo (r -> m r))) s t a b -> (i -> a -> r -> m r) -> r -> s -> m r-ifoldrMOf l f z0 xs = ifoldlOf l f' return xs z0-  where f' i k x z = f i x z >>= k-{-# INLINE ifoldrMOf #-}---- | Monadic fold over the elements of a structure with an index, associating to the left.------ When you don't need access to the index then 'Control.Lens.Fold.foldlMOf' is more flexible in what it accepts.------ @'Control.Lens.Fold.foldlMOf' l ≡ 'ifoldlMOf' l '.' 'const'@------ @--- 'ifoldlOf'' :: 'Monad' m => 'IndexedGetter' i s a            -> (i -> r -> a -> m r) -> r -> s -> r--- 'ifoldlOf'' :: 'Monad' m => 'IndexedFold' i s a              -> (i -> r -> a -> m r) -> r -> s -> r--- 'ifoldlOf'' :: 'Monad' m => 'Control.Lens.IndexedLens.SimpleIndexedLens' i s a        -> (i -> r -> a -> m r) -> r -> s -> r--- 'ifoldlOf'' :: 'Monad' m => 'Control.Lens.IndexedTraversal.SimpleIndexedTraversal' i s a   -> (i -> r -> a -> m r) -> r -> s -> r--- @-ifoldlMOf :: Monad m => IndexedGetting i (Endo (r -> m r)) s t a b -> (i -> r -> a -> m r) -> r -> s -> m r-ifoldlMOf l f z0 xs = ifoldrOf l f' return xs z0-  where f' i x k z = f i z x >>= k-{-# INLINE ifoldlMOf #-}---- | Extract the key-value pairs from a structure.------ When you don't need access to the indices in the result, then 'Control.Lens.Fold.toListOf' is more flexible in what it accepts.------ @'Control.Lens.Fold.toListOf' l ≡ 'map' 'fst' '.' 'itoListOf' l@------ @--- 'itoListOf' :: 'IndexedGetter' i s a          -> s -> [(i,a)]--- 'itoListOf' :: 'IndexedFold' i s a            -> s -> [(i,a)]--- 'itoListOf' :: 'Control.Lens.IndexedLens.SimpleIndexedLens' i s a      -> s -> [(i,a)]--- 'itoListOf' :: 'Control.Lens.IndexedTraversal.SimpleIndexedTraversal' i s a -> s -> [(i,a)]--- @-itoListOf :: IndexedGetting i (Endo [(i,a)]) s t a b -> s -> [(i,a)]-itoListOf l = ifoldrOf l (\i a -> ((i,a):)) []-{-# INLINE itoListOf #-}------------------------------------------------------------------------------------ Converting to Folds------------------------------------------------------------------------------------ | Transform an indexed fold into a fold of both the indices and the values.------ @--- 'withIndicesOf' :: 'IndexedFold' i s a             -> 'Fold' s (i, a)--- 'withIndicesOf' :: 'SimpleIndexedLens' i s a      -> 'Getter' s (i, a)--- 'withIndicesOf' :: 'SimpleIndexedTraversal' i s a -> 'Fold' s (i, a)--- @------ All 'Fold' operations are safe, and comply with the laws. However:------ Passing this an 'IndexedTraversal' will still allow many--- 'Traversal' combinators to type check on the result, but the result--- can only be legally traversed by operations that do not edit the indices.------ @--- 'withIndicesOf' :: 'IndexedTraversal' i s t a b -> 'Traversal' s t (i, a) (j, b)--- @------ Change made to the indices will be discarded.-withIndicesOf :: Functor f => Overloaded (Indexed i) f s t a b -> LensLike f s t (i, a) (j, b)-withIndicesOf l f = withIndex l (\i c -> snd <$> f (i,c))-{-# INLINE withIndicesOf #-}---- | Transform an indexed fold into a fold of the indices.------ @--- 'indicesOf' :: 'IndexedFold' i s a             -> 'Fold' s i--- 'indicesOf' :: 'SimpleIndexedLens' i s a      -> 'Getter' s i--- 'indicesOf' :: 'SimpleIndexedTraversal' i s a -> 'Fold' s i--- @-indicesOf :: Gettable f => Overloaded (Indexed i) f s t a a -> LensLike f s t i j-indicesOf l f = withIndex l (const . coerce . f)-{-# INLINE indicesOf #-}------------------------------------------------------------------------------------ Converting to Folds------------------------------------------------------------------------------------ | Obtain an 'IndexedFold' by filtering an 'Control.Lens.IndexedLens.IndexedLens', 'IndexedGetter', or 'IndexedFold'.------ When passed an 'Control.Lens.IndexedTraversal.IndexedTraversal', sadly the result is /not/ a legal 'Control.Lens.IndexedTraversal.IndexedTraversal'.------ See 'filtered' for a related counter-example.-ifiltering :: (Applicative f, Indexable i k)-           => (i -> a -> Bool)-           -> Indexed i (a -> f a) (s -> f t)-           -> k (a -> f a) (s -> f t)-ifiltering p l = indexed $ \ f ->-  withIndex l $ \ i c -> if p i c then f i c else pure c-{-# INLINE ifiltering #-}---- | Reverse the order of the elements of an 'IndexedFold' or--- 'Control.Lens.IndexedTraversal.IndexedTraversal'.--- This has no effect on an 'Control.Lens.IndexedLens.IndexedLens',--- 'IndexedGetter', or 'Control.Lens.IndexedSetter.IndexedSetter'.-ibackwards :: Indexable i k-           => Indexed i (a -> (Backwards f) b) (s -> (Backwards f) t)-           -> k (a -> f b) (s -> f t)-ibackwards l = indexed $ \ f ->-  fmap forwards . withIndex l $ \ i -> backwards# (f i)-{-# INLINE ibackwards #-}---- | Obtain an 'IndexedFold' by taking elements from another--- 'IndexedFold', 'Control.Lens.IndexedLens.IndexedLens',--- 'IndexedGetter' or 'Control.Lens.IndexedTraversal.IndexedTraversal'--- while a predicate holds.-itakingWhile :: (Gettable f, Applicative f, Indexable i k)-             => (i -> a -> Bool)-             -> IndexedGetting i (Endo (f s)) s s a a-             -> k (a -> f a) (s -> f s)-itakingWhile p l = indexed $ \ f ->-  ifoldrOf l (\i a r -> if p i a then f i a *> r else noEffect) noEffect-{-# INLINE itakingWhile #-}----- | Obtain an 'IndexedFold' by dropping elements from another 'IndexedFold', 'Control.Lens.IndexedLens.IndexedLens', 'IndexedGetter' or 'Control.Lens.IndexedTraversal.IndexedTraversal' while a predicate holds.-idroppingWhile :: (Gettable f, Applicative f, Indexable i k)-              => (i -> a -> Bool)-              -> IndexedGetting i (Endo (f s, f s)) s s a a-              -> k (a -> f a) (s -> f s)-idroppingWhile p l = indexed $ \ f ->-  fst . ifoldrOf l-                 (\i a r -> let s = f i a *> snd r in if p i a then (fst r, s) else (s, s))-                 (noEffect, noEffect)-{-# INLINE idroppingWhile #-}----------------------------------------------------------------------------------- Reifying Indexed Folds----------------------------------------------------------------------------------- | Useful for storage.-newtype ReifiedIndexedFold i s a =-  ReifyIndexedFold { reflectIndexedFold :: IndexedFold i s a }
− src/Control/Lens/IndexedGetter.hs
@@ -1,75 +0,0 @@-{-# LANGUAGE Rank2Types #-}-{-# LANGUAGE MagicHash #-}-{-# LANGUAGE MultiParamTypeClasses #-}--------------------------------------------------------------------------------- |--- Module      :  Control.Lens.IndexedGetter--- Copyright   :  (C) 2012 Edward Kmett--- License     :  BSD-style (see the file LICENSE)--- Maintainer  :  Edward Kmett <ekmett@gmail.com>--- Stability   :  experimental--- Portability :  rank 2 types, MPTCs---------------------------------------------------------------------------------module Control.Lens.IndexedGetter-  (-  -- * Indexed Getters-    IndexedGetter-  , IndexedGetting-  , ReifiedIndexedGetter(..)-  -- * Indexed Getter Combinators-  , iview, iviews-  , iuse, iuses-  ) where--import Control.Lens.Indexed-import Control.Lens.Internal-import Control.Lens.Internal.Combinators-import Control.Lens.Classes-import Control.Monad.Reader-import Control.Monad.State----------------------------------------------------------------------------------- Indexed Getters----------------------------------------------------------------------------------- | Every 'IndexedGetter' is a valid 'Control.Lens.IndexedFold.IndexedFold' and 'Getter'.-type IndexedGetter i s a = forall k f. (Indexable i k, Gettable f) => k (a -> f a) (s -> f s)---- | Used to consume an 'Control.Lens.IndexedFold.IndexedFold'.-type IndexedGetting i m s t a b = Indexed i (a -> Accessor m b) (s -> Accessor m t)---- | Useful for storage.-newtype ReifiedIndexedGetter i s a = ReifyIndexedGetter { reflectIndexedGetter :: IndexedGetter i s a }---- | View the index and value of an 'IndexedGetter' into the current environment as a pair.------ When applied to an 'IndexedFold' the result will most likely be a nonsensical monoidal summary of--- the indices tupled with a monoidal summary of the values and probably not whatever it is you wanted.-iview :: MonadReader s m => IndexedGetting i (i,a) s t a b -> m (i,a)-iview l = asks (runAccessor# (withIndex l (\i -> accessor# ((,) i))))-{-# INLINE iview #-}---- | View a function of the index and value of an 'IndexedGetter' into the current environment------ When applied to an 'IndexedFold' the result will be a monoidal summary instead of a single answer.------ @'iviews' ≡ 'Control.Lens.IndexedFold.ifoldMapOf'@-iviews :: MonadReader s m => IndexedGetting i r s t a b -> (i -> a -> r) -> m r-iviews l f = asks (runAccessor# (withIndex l (\i -> accessor# (f i))))-{-# INLINE iviews #-}---- | Use the index and value of an 'IndexedGetter' into the current state as a pair.------ When applied to an 'IndexedFold' the result will most likely be a nonsensical monoidal summary of--- the indices tupled with a monoidal summary of the values and probably not whatever it is you wanted.-iuse :: MonadState s m => IndexedGetting i (i,a) s t a b -> m (i,a)-iuse l = gets (runAccessor# (withIndex l (\i -> accessor# ((,) i))))-{-# INLINE iuse #-}---- | Use a function of the index and value of an 'IndexedGetter' into the current state.------ When applied to an 'IndexedFold' the result will be a monoidal summary instead of a single answer.-iuses :: MonadState s m => IndexedGetting i r s t a b -> (i -> a -> r) -> m r-iuses l f = gets (runAccessor# (withIndex l (\i -> accessor# (f i))))-{-# INLINE iuses #-}
− src/Control/Lens/IndexedLens.hs
@@ -1,182 +0,0 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE GADTs #-}-{-# LANGUAGE Rank2Types #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE FunctionalDependencies #-}-#ifdef TRUSTWORTHY-{-# LANGUAGE Trustworthy #-}-#endif--#ifndef MIN_VERSION_mtl-#define MIN_VERSION_mtl(x,y,z) 1-#endif---------------------------------------------------------------------------------- |--- Module      :  Control.Lens.IndexedLens--- Copyright   :  (C) 2012 Edward Kmett--- License     :  BSD-style (see the file LICENSE)--- Maintainer  :  Edward Kmett <ekmett@gmail.com>--- Stability   :  provisional--- Portability :  rank 2 types, MPTCs, TFs, flexible---------------------------------------------------------------------------------module Control.Lens.IndexedLens-  (-  -- * Indexed Lenses-    IndexedLens-  -- * Indexed Lens Combinators-  , (%%@~)-  , (<%@~)-  , (%%@=)-  , (<%@=)-  -- * Storing Indexed Lenses-  , ReifiedIndexedLens(..)-  -- * Common Indexed Lenses-  , Contains(..)-  , resultAt-  -- * Simple-  , SimpleIndexedLens-  , SimpleReifiedIndexedLens-  ) where--import Control.Lens.Classes-import Control.Lens.Combinators-import Control.Lens.Internal-import Control.Lens.Type-import Control.Monad.State.Class as State-import Data.Hashable-import Data.HashSet as HashSet-import Data.IntSet as IntSet-import Data.Set as Set----- $setup--- >>> import Control.Lens--infixr 4 %%@~, <%@~-infix  4 %%@=, <%@=---- | Every 'IndexedLens' is a valid 'Lens' and a valid 'Control.Lens.IndexedTraversal.IndexedTraversal'.-type IndexedLens i s t a b = forall f k. (Indexable i k, Functor f) => k (a -> f b) (s -> f t)---- | @type 'SimpleIndexedLens' i = 'Simple' ('IndexedLens' i)@-type SimpleIndexedLens i s a = IndexedLens i s s a a---- | Adjust the target of an 'IndexedLens' returning the intermediate result, or--- adjust all of the targets of an 'Control.Lens.IndexedTraversal.IndexedTraversal' and return a monoidal summary--- along with the answer.------ @l '<%~' f ≡ l '<%@~' 'const' f@------ When you do not need access to the index then ('<%~') is more liberal in what it can accept.------ If you do not need the intermediate result, you can use ('Control.Lens.Type.%@~') or even ('Control.Lens.Type.%~').------ @--- ('<%@~') ::             'IndexedLens' i s t a b -> (i -> a -> b) -> s -> (b, t)--- ('<%@~') :: 'Monoid' b => 'Control.Lens.IndexedTraversal.IndexedTraversal' i s t a b -> (i -> a -> b) -> s -> (b, t)--- @-(<%@~) :: Overloaded (Indexed i) ((,)b) s t a b -> (i -> a -> b) -> s -> (b, t)-l <%@~ f = withIndex l $ \i a -> let b = f i a in (b, b)-{-# INLINE (<%@~) #-}---- | Adjust the target of an 'IndexedLens' returning a supplementary result, or--- adjust all of the targets of an 'Control.Lens.IndexedTraversal.IndexedTraversal' and return a monoidal summary--- of the supplementary results and the answer.------ @('%%@~') ≡ 'withIndex'@------ @--- ('%%@~') :: 'Functor' f => 'IndexedLens' i s t a b      -> (i -> a -> f b) -> s -> f t--- ('%%@~') :: 'Functor' f => 'Control.Lens.IndexedTraversal.IndexedTraversal' i s t a b -> (i -> a -> f b) -> s -> f t--- @------ In particular, it is often useful to think of this function as having one of these even more--- restrictive type signatures------ @--- ('%%@~') ::             'IndexedLens' i s t a b      -> (i -> a -> (r, b)) -> s -> (r, t)--- ('%%@~') :: 'Monoid' r => 'Control.Lens.IndexedTraversal.IndexedTraversal' i s t a b -> (i -> a -> (r, b)) -> s -> (r, t)--- @-(%%@~) :: Overloaded (Indexed i) f s t a b -> (i -> a -> f b) -> s -> f t-(%%@~) = withIndex-{-# INLINE (%%@~) #-}---- | Adjust the target of an 'IndexedLens' returning a supplementary result, or--- adjust all of the targets of an 'Control.Lens.IndexedTraversal.IndexedTraversal' within the current state, and--- return a monoidal summary of the supplementary results.------ @l '%%@=' f ≡ 'state' (l '%%@~' f)@------ @--- ('%%@=') :: 'MonadState' s m                'IndexedLens' i s s a b      -> (i -> a -> (r, b)) -> s -> m r--- ('%%@=') :: ('MonadState' s m, 'Monoid' r) => 'Control.Lens.IndexedTraversal.IndexedTraversal' i s s a b -> (i -> a -> (r, b)) -> s -> m r--- @-(%%@=) :: MonadState s m => Overloaded (Indexed i) ((,)r) s s a b -> (i -> a -> (r, b)) -> m r-#if MIN_VERSION_mtl(2,1,0)-l %%@= f = State.state (l %%@~ f)-#else-l %%@= f = do-  (r, s) <- State.gets (l %%@~ f)-  State.put s-  return r-#endif-{-# INLINE (%%@=) #-}---- | Adjust the target of an 'IndexedLens' returning the intermediate result, or--- adjust all of the targets of an 'Control.Lens.IndexedTraversal.IndexedTraversal' within the current state, and--- return a monoidal summary of the intermediate results.------ @--- ('<%@=') :: 'MonadState' s m                'IndexedLens' i s s a b      -> (i -> a -> b) -> m b--- ('<%@=') :: ('MonadState' s m, 'Monoid' b) => 'Control.Lens.IndexedTraversal.IndexedTraversal' i s s a b -> (i -> a -> b) -> m b--- @-(<%@=) :: MonadState s m => Overloaded (Indexed i) ((,)b) s s a b -> (i -> a -> b) -> m b-l <%@= f = l %%@= \ i a -> let b = f i a in (b, b)-{-# INLINE (<%@=) #-}----------------------------------------------------------------------------------- Reifying Indexed Lenses----------------------------------------------------------------------------------- | Useful for storage.-newtype ReifiedIndexedLens i s t a b = ReifyIndexedLens { reflectIndexedLens :: IndexedLens i s t a b }---- | @type 'SimpleIndexedLens' i = 'Simple' ('ReifiedIndexedLens' i)@-type SimpleReifiedIndexedLens i s a = ReifiedIndexedLens i s s a a---- | Provides an 'IndexedLens' that can be used to read, write or delete a member of a set-like container-class Contains k m | m -> k where-  -- |-  -- >>> contains 3 .~ False $ IntSet.fromList [1,2,3,4]-  -- fromList [1,2,4]-  contains :: k -> SimpleIndexedLens k m Bool--instance Contains Int IntSet where-  contains k = indexed $ \ f s -> f k (IntSet.member k s) <&> \b ->-    if b then IntSet.insert k s else IntSet.delete k s-  {-# INLINE contains #-}--instance Ord k => Contains k (Set k) where-  contains k = indexed $ \ f s -> f k (Set.member k s) <&> \b ->-    if b then Set.insert k s else Set.delete k s-  {-# INLINE contains #-}--instance (Eq k, Hashable k) => Contains k (HashSet k) where-  contains k = indexed $ \ f s -> f k (HashSet.member k s) <&> \b ->-    if b then HashSet.insert k s else HashSet.delete k s-  {-# INLINE contains #-}---- | This lens can be used to change the result of a function but only where--- the arguments match the key given.------ >>> let f = (+1) & resultAt 3 .~ 8 in (f 2, f 3)--- (3,8)-resultAt :: Eq e => e -> SimpleIndexedLens e (e -> a) a-resultAt e = indexed $ \ g f -> g e (f e) <&> \a' e' -> if e == e' then a' else f e'-{-# INLINE resultAt #-}
− src/Control/Lens/IndexedSetter.hs
@@ -1,152 +0,0 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE MagicHash #-}-{-# LANGUAGE Rank2Types #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE FlexibleContexts #-}-#ifdef TRUSTWORTHY-{-# LANGUAGE Trustworthy #-}-#endif--------------------------------------------------------------------------------- |--- Module      :  Control.Lens.IndexedSetter--- Copyright   :  (C) 2012 Edward Kmett--- License     :  BSD-style (see the file LICENSE)--- Maintainer  :  Edward Kmett <ekmett@gmail.com>--- Stability   :  provisional--- Portability :  rank 2 types, MPTCs, TFs, flexible---------------------------------------------------------------------------------module Control.Lens.IndexedSetter-  (-  -- * Indexed Setter-    IndexedSetter-  , imapOf, iover-  , isets-  , (%@~)-  , (%@=)-  -- * Storing Indexed Setters-  , ReifiedIndexedSetter(..)-  -- * Simple-  , SimpleIndexedSetter-  , SimpleReifiedIndexedSetter-  ) where--import Control.Lens.Classes-import Control.Lens.Indexed-import Control.Lens.Internal-import Control.Lens.Internal.Combinators-import Control.Lens.Type-import Control.Monad.State.Class as State--infixr 4 %@~-infix  4 %@=---- | Every 'IndexedSetter' is a valid 'Setter'------ The 'Control.Lens.Setter.Setter' laws are still required to hold.-type IndexedSetter i s t a b = forall f k.-  (Indexable i k, Settable f) => k (a -> f b) (s -> f t)---- |--- @type 'SimpleIndexedSetter' i = 'Simple' ('IndexedSetter' i)@-type SimpleIndexedSetter i s a = IndexedSetter i s s a a---- | Map with index.------ When you do not need access to the index, then 'mapOf' is more liberal in what it can accept.------ @'Control.Lens.Setter.mapOf' l ≡ 'imapOf' l '.' 'const'@------ @--- 'imapOf' :: 'IndexedSetter' i s t a b    -> (i -> a -> b) -> s -> t--- 'imapOf' :: 'Control.Lens.IndexedLens.IndexedLens' i s t a b      -> (i -> a -> b) -> s -> t--- 'imapOf' :: 'Control.Lens.IndexedTraversal.IndexedTraversal' i s t a b -> (i -> a -> b) -> s -> t--- @-imapOf :: Overloaded (Indexed i) Mutator s t a b -> (i -> a -> b) -> s -> t-imapOf l f = runMutator# (withIndex l (\i -> mutator# (f i)))-{-# INLINE imapOf #-}---- | Map with index. This is an alias for 'imapOf'.------ When you do not need access to the index, then 'over' is more liberal in what it can accept.------ @'Control.Lens.Setter.over' l ≡ 'iover' l '.' 'const'@------ @--- 'iover' :: 'IndexedSetter' i s t a b    -> (i -> a -> b) -> s -> t--- 'iover' :: 'Control.Lens.IndexedLens.IndexedLens' i s t a b      -> (i -> a -> b) -> s -> t--- 'iover' :: 'Control.Lens.IndexedTraversal.IndexedTraversal' i s t a b -> (i -> a -> b) -> s -> t--- @-iover :: Overloaded (Indexed i) Mutator s t a b -> (i -> a -> b) -> s -> t-iover l f = runMutator# (withIndex l (\i -> mutator# (f i)))-{-# INLINE iover #-}---- | Build an 'IndexedSetter' from an 'imap'-like function.------ Your supplied function @f@ is required to satisfy:------ @--- f 'id' ≡ 'id'--- f g '.' f h ≡ f (g '.' h)--- @------ Equational reasoning:------ @--- 'isets' '.' 'iover' ≡ 'id'--- 'iover' '.' 'isets' ≡ 'id'--- @------ Another way to view 'sets' is that it takes a \"semantic editor combinator\"--- and transforms it into a 'Setter'.-isets :: ((i -> a -> b) -> s -> t) -> IndexedSetter i s t a b-isets f = indexed $ \ g -> tainted# (f (\i -> untainted# (g i)))-{-# INLINE isets #-}---- | Adjust every target of an 'IndexedSetter', 'Control.Lens.IndexedLens.IndexedLens' or 'Control.Lens.IndexedTraversal.IndexedTraversal'--- with access to the index.------ @('%@~') ≡ 'imapOf'@------ When you do not need access to the index then ('%@~') is more liberal in what it can accept.------ @l 'Control.Lens.Setter.%~' f ≡ l '%@~' 'const' f@------ @--- ('%@~') :: 'IndexedSetter' i s t a b    -> (i -> a -> b) -> s -> t--- ('%@~') :: 'Control.Lens.IndexedLens.IndexedLens' i s t a b      -> (i -> a -> b) -> s -> t--- ('%@~') :: 'Control.Lens.IndexedTraversal.IndexedTraversal' i s t a b -> (i -> a -> b) -> s -> t--- @-(%@~) :: Overloaded (Indexed i) Mutator s t a b -> (i -> a -> b) -> s -> t-l %@~ f = runMutator# (withIndex l (\i -> mutator# (f i)))-{-# INLINE (%@~) #-}---- | Adjust every target in the current state of an 'IndexedSetter', 'Control.Lens.IndexedLens.IndexedLens' or 'Control.Lens.IndexedTraversal.IndexedTraversal'--- with access to the index.------ When you do not need access to the index then ('Control.Lens.Setter.%=') is more liberal in what it can accept.------ @l 'Control.Lens.Setter.%=' f ≡ l '%@=' 'const' f@------ @--- ('%@=') :: 'MonadState' s m => 'IndexedSetter' i s s a b    -> (i -> a -> b) -> m ()--- ('%@=') :: 'MonadState' s m => 'Control.Lens.IndexedLens.IndexedLens' i s s a b      -> (i -> a -> b) -> m ()--- ('%@=') :: 'MonadState' s m => 'Control.Lens.IndexedTraversal.IndexedTraversal' i s t a b -> (i -> a -> b) -> m ()--- @-(%@=) :: MonadState s m => Overloaded (Indexed i) Mutator s s a b -> (i -> a -> b) -> m ()-l %@= f = State.modify (l %@~ f)-{-# INLINE (%@=) #-}----------------------------------------------------------------------------------- Reifying Indexed Setters----------------------------------------------------------------------------------- | Useful for storage.-newtype ReifiedIndexedSetter i s t a b =-  ReifyIndexedSetter { reflectIndexedSetter :: IndexedSetter i s t a b }---- | @type 'SimpleIndexedSetter' i = 'Simple' ('ReifiedIndexedSetter' i)@-type SimpleReifiedIndexedSetter i s a = ReifiedIndexedSetter i s s a a-
− src/Control/Lens/IndexedTraversal.hs
@@ -1,408 +0,0 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE GADTs #-}-{-# LANGUAGE Rank2Types #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE FunctionalDependencies #-}-{-# LANGUAGE ScopedTypeVariables #-}--#ifdef TRUSTWORTHY-{-# LANGUAGE Trustworthy #-}-#endif--#ifndef MIN_VERSION_containers-#define MIN_VERSION_containers(x,y,z) 1-#endif---------------------------------------------------------------------------------- |--- Module      :  Control.Lens.IndexedTraversal--- Copyright   :  (C) 2012 Edward Kmett--- License     :  BSD-style (see the file LICENSE)--- Maintainer  :  Edward Kmett <ekmett@gmail.com>--- Stability   :  provisional--- Portability :  rank 2 types, MPTCs, TFs, flexible---------------------------------------------------------------------------------module Control.Lens.IndexedTraversal-  (-  -- * Indexed Traversals-    IndexedTraversal--  -- * Common Indexed Traversals-  , iwhereOf-  , value-  , ignored-  , At(..)-  , TraverseMin(..)-  , TraverseMax(..)-  , traversed-  , traversed64-  , elementOf-  , element-  , elementsOf-  , elements--  -- * Indexed Traversal Combinators-  , itraverseOf-  , iforOf-  , imapMOf-  , iforMOf-  , imapAccumROf-  , imapAccumLOf--  -- * Storing Indexed Traversals-  , ReifiedIndexedTraversal(..)--  -- * Simple-  , SimpleIndexedTraversal-  , SimpleReifiedIndexedTraversal-  ) where--import Control.Applicative-import Control.Applicative.Backwards-import Control.Lens.Combinators-import Control.Lens.Indexed-import Control.Lens.IndexedLens-import Control.Lens.Internal-import Control.Lens.Type-import Control.Monad.Trans.State.Lazy as Lazy-import Data.Hashable-import Data.HashMap.Lazy as HashMap-import Data.Int-import Data.IntMap as IntMap-import Data.Map as Map-import Data.Traversable---- $setup--- >>> import Control.Lens----------------------------------------------------------------------------------- Indexed Traversals----------------------------------------------------------------------------------- | Every indexed traversal is a valid 'Control.Lens.Traversal.Traversal' or--- 'Control.Lens.IndexedFold.IndexedFold'.------ The 'Indexed' constraint is used to allow an 'IndexedTraversal' to be used--- directly as a 'Control.Lens.Traversal.Traversal'.------ The 'Control.Lens.Traversal.Traversal' laws are still required to hold.-type IndexedTraversal i s t a b = forall f k. (Indexable i k, Applicative f) => k (a -> f b) (s -> f t)---- | @type 'SimpleIndexedTraversal' i = 'Simple' ('IndexedTraversal' i)@-type SimpleIndexedTraversal i s a = IndexedTraversal i s s a a---- | Traversal with an index.------ NB: When you don't need access to the index then you can just apply your 'IndexedTraversal'--- directly as a function!------ @--- 'itraverseOf' ≡ 'withIndex'--- 'Control.Lens.Traversal.traverseOf' l = 'itraverseOf' l '.' 'const' = 'id'--- @------ @--- 'itraverseOf' :: 'Control.Lens.IndexedLens.IndexedLens' i s t a b      -> (i -> a -> f b) -> s -> f t--- 'itraverseOf' :: 'IndexedTraversal' i s t a b -> (i -> a -> f b) -> s -> f t--- @-itraverseOf :: Overloaded (Indexed i) f s t a b -> (i -> a -> f b) -> s -> f t-itraverseOf = withIndex-{-# INLINE itraverseOf #-}---- |--- Traverse with an index (and the arguments flipped)------ @--- 'Control.Lens.Traversal.forOf' l a ≡ 'iforOf' l a '.' 'const'--- 'iforOf' ≡ 'flip' . 'itraverseOf'--- @------ @--- 'iforOf' :: 'Control.Lens.IndexedLens.IndexedLens' i s t a b      -> s -> (i -> a -> f b) -> f t--- 'iforOf' :: 'IndexedTraversal' i s t a b -> s -> (i -> a -> f b) -> f t--- @-iforOf :: Overloaded (Indexed i) f s t a b -> s -> (i -> a -> f b) -> f t-iforOf = flip . withIndex-{-# INLINE iforOf #-}---- | Map each element of a structure targeted by a lens to a monadic action,--- evaluate these actions from left to right, and collect the results, with access--- its position.------ When you don't need access to the index 'mapMOf' is more liberal in what it can accept.------ @'Control.Lens.Traversal.mapMOf' l ≡ 'imapMOf' l '.' 'const'@------ @--- 'imapMOf' :: 'Monad' m => 'Control.Lens.IndexedLens.IndexedLens'      i s t a b -> (i -> a -> m b) -> s -> m t--- 'imapMOf' :: 'Monad' m => 'IndexedTraversal' i s t a b -> (i -> a -> m b) -> s -> m t--- @-imapMOf :: Overloaded (Indexed i) (WrappedMonad m) s t a b -> (i -> a -> m b) -> s -> m t-imapMOf l f = unwrapMonad . withIndex l (\i -> WrapMonad . f i)-{-# INLINE imapMOf #-}---- | Map each element of a structure targeted by a lens to a monadic action,--- evaluate these actions from left to right, and collect the results, with access--- its position (and the arguments flipped).------ @--- 'Control.Lens.Traversal.forMOf' l a ≡ 'iforMOf' l a '.' 'const'--- 'iforMOf' ≡ 'flip' '.' 'imapMOf'--- @------ @--- 'iforMOf' :: 'Monad' m => 'Control.Lens.IndexedLens.IndexedLens' i s t a b      -> s -> (i -> a -> m b) -> m t--- 'iforMOf' :: 'Monad' m => 'IndexedTraversal' i s t a b -> s -> (i -> a -> m b) -> m t--- @-iforMOf :: Overloaded (Indexed i) (WrappedMonad m) s t a b -> s -> (i -> a -> m b) -> m t-iforMOf = flip . imapMOf-{-# INLINE iforMOf #-}---- | Generalizes 'Data.Traversable.mapAccumR' to an arbitrary 'IndexedTraversal' with access to the index.------ 'imapAccumROf' accumulates state from right to left.------ @'Control.Lens.Traversal.mapAccumROf' l ≡ 'imapAccumROf' l '.' 'const'@------ @--- 'imapAccumROf' :: 'Control.Lens.IndexedLens.IndexedLens' i s t a b      -> (i -> s -> a -> (s, b)) -> s -> s -> (s, t)--- 'imapAccumROf' :: 'IndexedTraversal' i s t a b -> (i -> s -> a -> (s, b)) -> s -> s -> (s, t)--- @-imapAccumROf :: Overloaded (Indexed i) (Lazy.State s) s t a b -> (i -> s -> a -> (s, b)) -> s -> s -> (s, t)-imapAccumROf l f s0 a = swap (Lazy.runState (withIndex l (\i c -> Lazy.state (\s -> swap (f i s c))) a) s0)-{-# INLINE imapAccumROf #-}---- | Generalizes 'Data.Traversable.mapAccumL' to an arbitrary 'IndexedTraversal' with access to the index.------ 'imapAccumLOf' accumulates state from left to right.------ @'Control.Lens.Traversal.mapAccumLOf' l ≡ 'imapAccumLOf' l '.' 'const'@------ @--- 'imapAccumLOf' :: 'Control.Lens.IndexedLens.IndexedLens' i s t a b      -> (i -> s -> a -> (s, b)) -> s -> s -> (s, t)--- 'imapAccumLOf' :: 'IndexedTraversal' i s t a b -> (i -> s -> a -> (s, b)) -> s -> s -> (s, t)--- @-imapAccumLOf :: Overloaded (Indexed i) (Backwards (Lazy.State s)) s t a b -> (i -> s -> a -> (s, b)) -> s -> s -> (s, t)-imapAccumLOf l f s0 a = swap (Lazy.runState (forwards (withIndex l (\i c -> Backwards (Lazy.state (\s -> swap (f i s c)))) a)) s0)-{-# INLINE imapAccumLOf #-}--swap :: (a,b) -> (b,a)-swap (a,b) = (b,a)-{-# INLINE swap #-}----------------------------------------------------------------------------------- Common Indexed Traversals----------------------------------------------------------------------------------- | Access the element of an 'IndexedTraversal' where the index matches a predicate.------ >>> over (iwhereOf traversed (>0)) reverse ["He","was","stressed","o_O"]--- ["He","saw","desserts","O_o"]------ @--- 'iwhereOf' :: 'IndexedFold' i s a            -> (i -> 'Bool') -> 'IndexedFold' i s a--- 'iwhereOf' :: 'IndexedGetter' i s a          -> (i -> 'Bool') -> 'IndexedFold' i s a--- 'iwhereOf' :: 'SimpleIndexedLens' i s a      -> (i -> 'Bool') -> 'SimpleIndexedTraversal' i s a--- 'iwhereOf' :: 'SimpleIndexedTraversal' i s a -> (i -> 'Bool') -> 'SimpleIndexedTraversal' i s a--- 'iwhereOf' :: 'SimpleIndexedSetter' i s a    -> (i -> 'Bool') -> 'SimpleIndexedSetter' i s a--- @-iwhereOf :: (Indexable i k, Applicative f) => Overloaded (Indexed i) f s t a a -> (i -> Bool) -> Overloaded k f s t a a-iwhereOf l p = indexed $ \f s -> withIndex l (\i a -> if p i then f i a else pure a) s-{-# INLINE iwhereOf #-}---- | Traverse any 'Traversable' container. This is an 'IndexedTraversal' that is indexed by ordinal position.-traversed :: Traversable f => IndexedTraversal Int (f a) (f b) a b-traversed = indexing traverse-{-# INLINE traversed #-}---- | Traverse any 'Traversable' container. This is an 'IndexedTraversal' that is indexed by ordinal position.-traversed64 :: Traversable f => IndexedTraversal Int64 (f a) (f b) a b-traversed64 = indexing64 traverse-{-# INLINE traversed64 #-}---- | This provides a 'Traversal' that checks a predicate on a key before--- allowing you to traverse into a value.-value :: (k -> Bool) -> SimpleIndexedTraversal k (k, v) v-value p = indexed $ \ f kv@(k,v) -> if p k then (,) k <$> f k v else pure kv-{-# INLINE value #-}---- | This is the trivial empty traversal.------ @'ignored' :: 'IndexedTraversal' i s s a b@------ @'ignored' ≡ 'const' 'pure'@-ignored :: forall k f i s a b. (Indexable i k, Applicative f) => Overloaded k f s s a b-ignored = indexed $ \ (_ :: i -> a -> f b) s -> pure s :: f s-{-# INLINE ignored #-}---- | 'At' provides a lens that can be used to read,--- write or delete the value associated with a key in a map-like--- container on an ad hoc basis.-class At k m | m -> k where-  -- |-  -- >>> Map.fromList [(1,"hello")] ^.at 1-  -- Just "hello"-  ---  -- >>> at 1 ?~ "hello" $ Map.empty-  -- fromList [(1,"hello")]-  ---  -- Note: 'Map'-like containers form a reasonable instance, but not 'Array'-like ones, where-  -- you cannot satisfy the 'Lens' laws.-  at :: k -> SimpleIndexedLens k (m v) (Maybe v)--  -- | This simple indexed traversal lets you 'traverse' the value at a given key in a map.-  ---  -- *NB:* _setting_ the value of this lens will only set the value in the lens-  -- if it is already present.-  ---  -- @'_at' k ≡ 'at' k '<.' 'traverse'@-  _at :: k -> SimpleIndexedTraversal k (m v) v-  _at k = at k <. traverse--instance At Int IntMap where-  at k = indexed $ \f m ->-    let mv = IntMap.lookup k m-        go Nothing   = maybe m (const (IntMap.delete k m)) mv-        go (Just v') = IntMap.insert k v' m-    in go <$> f k mv where-  {-# INLINE at #-}-  _at k = indexed $ \f m -> case IntMap.lookup k m of-     Just v -> f k v <&> \v' -> IntMap.insert k v' m-     Nothing -> pure m-  {-# INLINE _at #-}--instance Ord k => At k (Map k) where-  at k = indexed $ \f m ->-    let mv = Map.lookup k m-        go Nothing   = maybe m (const (Map.delete k m)) mv-        go (Just v') = Map.insert k v' m-    in go <$> f k mv-  {-# INLINE at #-}-  _at k = indexed $ \f m -> case Map.lookup k m of-     Just v  -> f k v <&> \v' -> Map.insert k v' m-     Nothing -> pure m-  {-# INLINE _at #-}--instance (Eq k, Hashable k) => At k (HashMap k) where-  at k = indexed $ \f m ->-    let mv = HashMap.lookup k m-        go Nothing   = maybe m (const (HashMap.delete k m)) mv-        go (Just v') = HashMap.insert k v' m-    in go <$> f k mv-  {-# INLINE at #-}-  _at k = indexed $ \f m -> case HashMap.lookup k m of-     Just v  -> f k v <&> \v' -> HashMap.insert k v' m-     Nothing -> pure m-  {-# INLINE _at #-}---- | Allows 'IndexedTraversal' the value at the smallest index.-class Ord k => TraverseMin k m | m -> k where-  -- | 'IndexedTraversal' of the element with the smallest index.-  traverseMin :: SimpleIndexedTraversal k (m v) v--instance TraverseMin Int IntMap where-  traverseMin = indexed $ \f m -> case IntMap.minViewWithKey m of-#if MIN_VERSION_containers(0,5,0)-    Just ((k,a), _) -> f k a <&> \v -> IntMap.updateMin (const (Just v)) m-#else-    Just ((k,a), _) -> f k a <&> \v -> IntMap.updateMin (const v) m-#endif-    Nothing     -> pure m-  {-# INLINE traverseMin #-}--instance Ord k => TraverseMin k (Map k) where-  traverseMin = indexed $ \f m -> case Map.minViewWithKey m of-    Just ((k, a), _) -> f k a <&> \v -> Map.updateMin (const (Just v)) m-    Nothing          -> pure m-  {-# INLINE traverseMin #-}---- | Allows 'IndexedTraversal' of the value at the largest index.-class Ord k => TraverseMax k m | m -> k where-  -- | 'IndexedTraversal' of the element at the largest index.-  traverseMax :: SimpleIndexedTraversal k (m v) v--instance TraverseMax Int IntMap where-  traverseMax = indexed $ \f m -> case IntMap.maxViewWithKey m of-#if MIN_VERSION_containers(0,5,0)-    Just ((k,a), _) -> f k a <&> \v -> IntMap.updateMax (const (Just v)) m-#else-    Just ((k,a), _) -> f k a <&> \v -> IntMap.updateMax (const v) m-#endif-    Nothing     -> pure m-  {-# INLINE traverseMax #-}--instance Ord k => TraverseMax k (Map k) where-  traverseMax = indexed $ \f m -> case Map.maxViewWithKey m of-    Just ((k, a), _) -> f k a <&> \v -> Map.updateMax (const (Just v)) m-    Nothing          -> pure m-  {-# INLINE traverseMax #-}---- | Traverse the /nth/ element 'elementOf' a 'Traversal', 'Lens' or--- 'Control.Lens.Iso.Iso' if it exists.------ >>> [[1],[3,4]] & elementOf (traverse.traverse) 1 .~ 5--- [[1],[5,4]]------ >>> [[1],[3,4]] ^? elementOf (folded.folded) 1--- Just 3------ >>> [0..] ^?! elementOf folded 5--- 5------ >>> take 10 $ elementOf traverse 3 .~ 16 $ [0..]--- [0,1,2,16,4,5,6,7,8,9]------ @--- 'elementOf' :: 'Simple' 'Traversal' s a -> Int -> 'SimpleIndexedTraversal' 'Int' s a--- 'elementOf' :: 'Fold' s a            -> Int -> 'IndexedFold' 'Int' s a--- @-elementOf :: (Applicative f, Indexable Int k)-          => LensLike (Indexing f) s t a a-          -> Int-          -> Overloaded k f s t a a-elementOf l p = elementsOf l (p ==)-{-# INLINE elementOf #-}---- | Traverse the /nth/ element of a 'Traversable' container.------ @'element' ≡ 'elementOf' 'traverse'@-element :: Traversable t => Int -> SimpleIndexedTraversal Int (t a) a-element = elementOf traverse-{-# INLINE element #-}---- | Traverse (or fold) selected elements of a 'Traversal' (or 'Fold') where their ordinal positions match a predicate.------ @--- 'elementsOf' :: 'Simple' 'Traversal' s a -> ('Int' -> 'Bool') -> 'SimpleIndexedTraversal' 'Int' s a--- 'elementsOf' :: 'Fold' s a            -> ('Int' -> 'Bool') -> 'IndexedFold' 'Int' s a--- @-elementsOf :: (Applicative f, Indexable Int k)-           => LensLike (Indexing f) s t a a-           -> (Int -> Bool)-           -> Overloaded k f s t a a-elementsOf l p = indexed $ \iafb s ->-  case runIndexing (l (\a -> Indexing (\i -> i `seq` (if p i then iafb i a else pure a, i + 1))) s) 0 of-    (r, _) -> r-{-# INLINE elementsOf #-}---- | Traverse elements of a 'Traversable' container where their ordinal positions matches a predicate.------ @'elements' ≡ 'elementsOf' 'traverse'@-elements :: Traversable t => (Int -> Bool) -> SimpleIndexedTraversal Int (t a) a-elements = elementsOf traverse-{-# INLINE elements #-}----------------------------------------------------------------------------------- Reifying Indexed Traversals----------------------------------------------------------------------------------- | Useful for storage.-newtype ReifiedIndexedTraversal i s t a b =-  ReifyIndexedTraversal { reflectIndexedTraversal :: IndexedTraversal i s t a b }---- | @type 'SimpleIndexedTraversal' i = 'Simple' ('ReifiedIndexedTraversal' i)@-type SimpleReifiedIndexedTraversal i s a = ReifiedIndexedTraversal i s s a a
src/Control/Lens/Internal.hs view
@@ -1,570 +1,46 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE GADTs #-}-{-# LANGUAGE Rank2Types #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE KindSignatures #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE UndecidableInstances #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE MagicHash #-}-#ifdef TRUSTWORTHY-{-# LANGUAGE Trustworthy #-}-#endif ----------------------------------------------------------------------------- -- | -- Module      :  Control.Lens.Internal--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com>--- Stability   :  provisional+-- Stability   :  experimental -- Portability :  Rank2Types ----- These are some of the explicit Functor instances that leak into the--- type signatures of Control.Lens. You shouldn't need to import this--- module directly, unless you are coming up with a whole new kind of--- \"Family\" and need to add instances.+-- These are some of the explicit 'Functor' instances that leak into the+-- type signatures of @Control.Lens@. You shouldn't need to import this+-- module directly for most use-cases. -- ---------------------------------------------------------------------------- module Control.Lens.Internal-  (-  -- * Internal Types-    May(..)-  , Folding(..)-  , Effect(..)-  , EffectRWS(..)-  , Accessor(..)-  , Err(..)-  , Traversed(..)-  , Sequenced(..)-  , Focusing(..)-  , FocusingWith(..)-  , FocusingPlus(..)-  , FocusingOn(..)-  , FocusingMay(..)-  , FocusingErr(..)-  , Mutator(..)-  , Bazaar(..), bazaar, duplicateBazaar, sell-  , BazaarT(..), bazaarT, duplicateBazaarT, sellT-  , Context(..)-  , Max(..), getMax-  , Min(..), getMin-  , Indexing(..)-  , Indexing64(..)-  -- * Overloadings-  , Prismoid(..)-  , Isoid(..)-  , Indexed(..)-  , CoA, CoB+  ( module Control.Lens.Internal.Action+  , module Control.Lens.Internal.Bazaar+  , module Control.Lens.Internal.Context+  , module Control.Lens.Internal.Fold+  , module Control.Lens.Internal.Getter+  , module Control.Lens.Internal.Indexed+  , module Control.Lens.Internal.Iso+  , module Control.Lens.Internal.Level+  , module Control.Lens.Internal.Magma+  , module Control.Lens.Internal.Prism+  , module Control.Lens.Internal.Review+  , module Control.Lens.Internal.Setter+  , module Control.Lens.Internal.Zoom   ) where -import Control.Applicative-import Control.Category-import Control.Comonad-import Control.Comonad.Store.Class-import Control.Lens.Classes-import Control.Monad-import Prelude hiding ((.),id)-import Data.Functor.Compose-import Data.Functor.Identity-import Data.Int-import Data.Monoid-#ifndef SAFE-import Unsafe.Coerce-#endif--#ifndef SAFE-#define UNSAFELY(x) unsafeCoerce-#else-#define UNSAFELY(f) (\g -> g `seq` \x -> (f) (g x))-#endif---------------------------------------------------------------------------------- Functors---------------------------------------------------------------------------------- | Used by 'Control.Lens.Type.Zoom' to 'Control.Lens.Type.zoom' into 'Control.Monad.State.StateT'-newtype Focusing m s a = Focusing { unfocusing :: m (s, a) }--instance Monad m => Functor (Focusing m s) where-  fmap f (Focusing m) = Focusing $ do-     (s, a) <- m-     return (s, f a)--instance (Monad m, Monoid s) => Applicative (Focusing m s) where-  pure a = Focusing (return (mempty, a))-  Focusing mf <*> Focusing ma = Focusing $ do-    (s, f) <- mf-    (s', a) <- ma-    return (mappend s s', f a)---- | Used by 'Control.Lens.Type.Zoom' to 'Control.Lens.Type.zoom' into 'Control.Monad.RWS.RWST'-newtype FocusingWith w m s a = FocusingWith { unfocusingWith :: m (s, a, w) }--instance Monad m => Functor (FocusingWith w m s) where-  fmap f (FocusingWith m) = FocusingWith $ do-     (s, a, w) <- m-     return (s, f a, w)--instance (Monad m, Monoid s, Monoid w) => Applicative (FocusingWith w m s) where-  pure a = FocusingWith (return (mempty, a, mempty))-  FocusingWith mf <*> FocusingWith ma = FocusingWith $ do-    (s, f, w) <- mf-    (s', a, w') <- ma-    return (mappend s s', f a, mappend w w')---- | Used by 'Control.Lens.Type.Zoom' to 'Control.Lens.Type.zoom' into 'Control.Monad.Writer.WriterT'.-newtype FocusingPlus w k s a = FocusingPlus { unfocusingPlus :: k (s, w) a }--instance Functor (k (s, w)) => Functor (FocusingPlus w k s) where-  fmap f (FocusingPlus as) = FocusingPlus (fmap f as)--instance (Monoid w, Applicative (k (s, w))) => Applicative (FocusingPlus w k s) where-  pure = FocusingPlus . pure-  FocusingPlus kf <*> FocusingPlus ka = FocusingPlus (kf <*> ka)---- | Used by 'Control.Lens.Type.Zoom' to 'Control.Lens.Type.zoom' into 'Control.Monad.Trans.Maybe.MaybeT' or 'Control.Monad.Trans.List.ListT'-newtype FocusingOn f k s a = FocusingOn { unfocusingOn :: k (f s) a }--instance Functor (k (f s)) => Functor (FocusingOn f k s) where-  fmap f (FocusingOn as) = FocusingOn (fmap f as)--instance Applicative (k (f s)) => Applicative (FocusingOn f k s) where-  pure = FocusingOn . pure-  FocusingOn kf <*> FocusingOn ka = FocusingOn (kf <*> ka)---- | Make a monoid out of 'Maybe' for error handling-newtype May a = May { getMay :: Maybe a }--instance Monoid a => Monoid (May a) where-  mempty = May (Just mempty)-  May Nothing `mappend` _ = May Nothing-  _ `mappend` May Nothing = May Nothing-  May (Just a) `mappend` May (Just b) = May (Just (mappend a b))---- | Used by 'Control.Lens.Type.Zoom' to 'Control.Lens.Type.zoom' into 'Control.Monad.Error.ErrorT'-newtype FocusingMay k s a = FocusingMay { unfocusingMay :: k (May s) a }--instance Functor (k (May s)) => Functor (FocusingMay k s) where-  fmap f (FocusingMay as) = FocusingMay (fmap f as)--instance Applicative (k (May s)) => Applicative (FocusingMay k s) where-  pure = FocusingMay . pure-  FocusingMay kf <*> FocusingMay ka = FocusingMay (kf <*> ka)---- | Make a monoid out of 'Either' for error handling-newtype Err e a = Err { getErr :: Either e a }--instance Monoid a => Monoid (Err e a) where-  mempty = Err (Right mempty)-  Err (Left e) `mappend` _ = Err (Left e)-  _ `mappend` Err (Left e) = Err (Left e)-  Err (Right a) `mappend` Err (Right b) = Err (Right (mappend a b))---- | Used by 'Control.Lens.Type.Zoom' to 'Control.Lens.Type.zoom' into 'Control.Monad.Error.ErrorT'-newtype FocusingErr e k s a = FocusingErr { unfocusingErr :: k (Err e s) a }--instance Functor (k (Err e s)) => Functor (FocusingErr e k s) where-  fmap f (FocusingErr as) = FocusingErr (fmap f as)--instance Applicative (k (Err e s)) => Applicative (FocusingErr e k s) where-  pure = FocusingErr . pure-  FocusingErr kf <*> FocusingErr ka = FocusingErr (kf <*> ka)---- | Applicative composition of @'Control.Monad.Trans.State.Lazy.State' 'Int'@ with a 'Functor', used--- by 'Control.Lens.Indexed.indexed'-newtype Indexing f a = Indexing { runIndexing :: Int -> (f a, Int) }--instance Functor f => Functor (Indexing f) where-  fmap f (Indexing m) = Indexing $ \i -> case m i of-    (x, j) -> (fmap f x, j)--instance Applicative f => Applicative (Indexing f) where-  pure x = Indexing (\i -> (pure x, i))-  Indexing mf <*> Indexing ma = Indexing $ \i -> case mf i of-    (ff, j) -> case ma j of-       ~(fa, k) -> (ff <*> fa, k)--instance Gettable f => Gettable (Indexing f) where-  coerce (Indexing m) = Indexing $ \i -> case m i of-    (ff, j) -> (coerce ff, j)---- | Applicative composition of @'Control.Monad.Trans.State.Lazy.State' 'Int'@ with a 'Functor', used--- by 'Control.Lens.Indexed.indexed'-newtype Indexing64 f a = Indexing64 { runIndexing64 :: Int64 -> (f a, Int64) }--instance Functor f => Functor (Indexing64 f) where-  fmap f (Indexing64 m) = Indexing64 $ \i -> case m i of-    (x, j) -> (fmap f x, j)--instance Applicative f => Applicative (Indexing64 f) where-  pure x = Indexing64 (\i -> (pure x, i))-  Indexing64 mf <*> Indexing64 ma = Indexing64 $ \i -> case mf i of-    (ff, j) -> case ma j of-       ~(fa, k) -> (ff <*> fa, k)--instance Gettable f => Gettable (Indexing64 f) where-  coerce (Indexing64 m) = Indexing64 $ \i -> case m i of-    (ff, j) -> (coerce ff, j)---- | Used internally by 'Control.Lens.Traversal.traverseOf_' and the like.-newtype Traversed f = Traversed { getTraversed :: f () }--instance Applicative f => Monoid (Traversed f) where-  mempty = Traversed (pure ())-  Traversed ma `mappend` Traversed mb = Traversed (ma *> mb)---- | Used internally by 'Control.Lens.Traversal.mapM_' and the like.-newtype Sequenced m = Sequenced { getSequenced :: m () }--instance Monad m => Monoid (Sequenced m) where-  mempty = Sequenced (return ())-  Sequenced ma `mappend` Sequenced mb = Sequenced (ma >> mb)---- | Used for 'Control.Lens.Fold.minimumOf'-data Min a = NoMin | Min a--instance Ord a => Monoid (Min a) where-  mempty = NoMin-  mappend NoMin m = m-  mappend m NoMin = m-  mappend (Min a) (Min b) = Min (min a b)---- | Obtain the minimum.-getMin :: Min a -> Maybe a-getMin NoMin   = Nothing-getMin (Min a) = Just a---- | Used for 'Control.Lens.Fold.maximumOf'-data Max a = NoMax | Max a--instance Ord a => Monoid (Max a) where-  mempty = NoMax-  mappend NoMax m = m-  mappend m NoMax = m-  mappend (Max a) (Max b) = Max (max a b)---- | Obtain the maximum-getMax :: Max a -> Maybe a-getMax NoMax   = Nothing-getMax (Max a) = Just a---- | The indexed store can be used to characterize a 'Control.Lens.Type.Lens'--- and is used by 'Control.Lens.Type.clone'------ @'Context' a b t@ is isomorphic to--- @newtype Context a b t = Context { runContext :: forall f. Functor f => (a -> f b) -> f t }@,--- and to @exists s. (s, 'Control.Lens.Type.Lens' s t a b)@.------ A 'Context' is like a 'Control.Lens.Type.Lens' that has already been applied to a some structure.-data Context a b t = Context (b -> t) a--instance Functor (Context a b) where-  fmap f (Context g t) = Context (f . g) t--instance (a ~ b) => Comonad (Context a b) where-  extract   (Context f a) = f a-  duplicate (Context f a) = Context (Context f) a-  extend g  (Context f a) = Context (g . Context f) a--instance (a ~ b) => ComonadStore a (Context a b) where-  pos (Context _ a) = a-  peek b (Context g _) = g b-  peeks f (Context g a) = g (f a)-  seek a (Context g _) = Context g a-  seeks f (Context g a) = Context g (f a)-  experiment f (Context g a) = g <$> f a---- | This is used to characterize a 'Control.Lens.Traversal.Traversal'.------ a.k.a. indexed Cartesian store comonad, indexed Kleene store comonad, or an indexed 'FunList'.------ <http://twanvl.nl/blog/haskell/non-regular1>------ @'Bazaar' a b t@ is isomorphic to @data Bazaar a b t = Buy t | Trade (Bazaar a b (b -> t)) a@,--- and to @exists s. (s, 'Control.Lens.Traversal.Traversal' s t a b)@.------ A 'Bazaar' is like a 'Control.Lens.Traversal.Traversal' that has already been applied to some structure.------ Where a @'Context' a b t@ holds an @a@ and a function from @b@ to--- @t@, a @'Bazaar' a b t@ holds N @a@s and a function from N--- @b@s to @t@.------ Mnemonically, a 'Bazaar' holds many stores and you can easily add more.------ This is a final encoding of 'Bazaar'.-newtype Bazaar a b t = Bazaar { runBazaar :: forall f. Applicative f => (a -> f b) -> f t }--instance Functor (Bazaar a b) where-  fmap f (Bazaar k) = Bazaar (fmap f . k)--instance Applicative (Bazaar a b) where-  pure a = Bazaar (\_ -> pure a)-  {-# INLINE pure #-}-  Bazaar mf <*> Bazaar ma = Bazaar (\k -> mf k <*> ma k)-  {-# INLINE (<*>) #-}--instance (a ~ b) => Comonad (Bazaar a b) where-  extract (Bazaar m) = runIdentity (m Identity)-  {-# INLINE extract #-}-  duplicate = duplicateBazaar-  {-# INLINE duplicate #-}---- | Given an action to run for each matched pair, traverse a bazaar.------ @'bazaar' :: 'Control.Lens.Traversal.Traversal' ('Bazaar' a b t) t a b@-bazaar :: Applicative f => (a -> f b) -> Bazaar a b t -> f t-bazaar afb (Bazaar m) = m afb-{-# INLINE bazaar #-}---- | 'Bazaar' is an indexed 'Comonad'.-duplicateBazaar :: Bazaar a c t -> Bazaar a b (Bazaar b c t)-duplicateBazaar (Bazaar m) = getCompose (m (Compose . fmap sell . sell))-{-# INLINE duplicateBazaar #-}---- | A trivial 'Bazaar'.-sell :: a -> Bazaar a b b-sell i = Bazaar (\k -> k i)-{-# INLINE sell #-}--instance (a ~ b) => ComonadApply (Bazaar a b) where-  (<@>) = (<*>)---- | Wrap a monadic effect with a phantom type argument.-newtype Effect m r a = Effect { getEffect :: m r }--instance Functor (Effect m r) where-  fmap _ (Effect m) = Effect m--instance (Monad m, Monoid r) => Monoid (Effect m r a) where-  mempty = Effect (return mempty)-  Effect ma `mappend` Effect mb = Effect (liftM2 mappend ma mb)--instance (Monad m, Monoid r) => Applicative (Effect m r) where-  pure _ = Effect (return mempty)-  Effect ma <*> Effect mb = Effect (liftM2 mappend ma mb)--instance Gettable (Effect m r) where-  coerce (Effect m) = Effect m--instance Monad m => Effective m r (Effect m r) where-  effective = Effect-  {-# INLINE effective #-}-  ineffective = getEffect-  {-# INLINE ineffective #-}---- | Wrap a monadic effect with a phantom type argument. Used when magnifying RWST.-newtype EffectRWS w st m s a = EffectRWS { getEffectRWS :: st -> m (s,st,w) }--instance Functor (EffectRWS w st m s) where-  fmap _ (EffectRWS m) = EffectRWS m--instance Gettable (EffectRWS w st m s) where-  coerce (EffectRWS m) = EffectRWS m---- Effective EffectRWS--instance (Monoid s, Monoid w, Monad m) => Applicative (EffectRWS w st m s) where-  pure _ = EffectRWS $ \st -> return (mempty, st, mempty)-  EffectRWS m <*> EffectRWS n = EffectRWS $ \st -> m st >>= \ (s,t,w) -> n t >>= \ (s',u,w') -> return (mappend s s', u, mappend w w')--{---- | Wrap a monadic effect with a phantom type argument. Used when magnifying StateT.-newtype EffectS st k s a = EffectS { runEffect :: st -> k (s, st) a }--instance Functor (k (s, st)) => Functor (EffectS st m s) where-  fmap f (EffectS m) = EffectS (fmap f . m)--instance (Monoid s, Monad m) => Applicative (EffectS st m s) where-  pure _ = EffectS $ \st -> return (mempty, st)-  EffectS m <*> EffectS n = EffectS $ \st -> m st >>= \ (s,t) -> n st >>= \ (s', u) -> return (mappend s s', u)--}------------------------------------------------------------------------------------ Accessors------------------------------------------------------------------------------------instance Gettable (EffectS st m s) where---  coerce (EffectS m) = EffectS m---- | Used instead of 'Const' to report------ @No instance of ('Control.Lens.Setter.Settable' 'Accessor')@------ when the user attempts to misuse a 'Control.Lens.Setter.Setter' as a--- 'Control.Lens.Getter.Getter', rather than a monolithic unification error.-newtype Accessor r a = Accessor { runAccessor :: r }--instance Functor (Accessor r) where-  fmap _ (Accessor m) = Accessor m--instance Monoid r => Applicative (Accessor r) where-  pure _ = Accessor mempty-  Accessor a <*> Accessor b = Accessor (mappend a b)--instance Gettable (Accessor r) where-  coerce (Accessor m) = Accessor m--instance Effective Identity r (Accessor r) where-  effective = Accessor . runIdentity-  {-# INLINE effective #-}-  ineffective = Identity . runAccessor-  {-# INLINE ineffective #-}---- | A 'Monoid' for a 'Gettable' 'Applicative'.-newtype Folding f a = Folding { getFolding :: f a }--instance (Gettable f, Applicative f) => Monoid (Folding f a) where-  mempty = Folding noEffect-  {-# INLINE mempty #-}-  Folding fr `mappend` Folding fs = Folding (fr *> fs)-  {-# INLINE mappend #-}---------------------------------------------------------------------------------- Mutators---------------------------------------------------------------------------------- | 'Mutator' is just a renamed 'Identity' functor to give better error--- messages when someone attempts to use a getter as a setter.------ Most user code will never need to see this type.-newtype Mutator a = Mutator { runMutator :: a }--instance Functor Mutator where-  fmap f (Mutator a) = Mutator (f a)-  {-# INLINE fmap #-}--instance Applicative Mutator where-  pure = Mutator-  {-# INLINE pure #-}-  Mutator f <*> Mutator a = Mutator (f a)-  {-# INLINE (<*>) #-}--instance Settable Mutator where-  untainted = runMutator-  untainted# = UNSAFELY(runMutator)-  {-# INLINE untainted #-}-  tainted# = UNSAFELY(Mutator)-  {-# INLINE tainted# #-}---- | 'BazaarT' is like 'Bazaar', except that it provides a questionable 'Gettable' instance--- To protect this instance it relies on the soundness of another 'Gettable' type, and usage conventions.------ For example. This lets us write a suitably polymorphic and lazy 'Control.Lens.Traversal.taking', but there--- must be a better way!----newtype BazaarT a b (g :: * -> *) t = BazaarT { runBazaarT :: forall f. Applicative f => (a -> f b) -> f t }--instance Functor (BazaarT a b g) where-  fmap f (BazaarT k) = BazaarT (fmap f . k)-  {-# INLINE fmap #-}--instance Applicative (BazaarT a b g) where-  pure a = BazaarT (\_ -> pure a)-  {-# INLINE pure #-}-  BazaarT mf <*> BazaarT ma = BazaarT (\k -> mf k <*> ma k)-  {-# INLINE (<*>) #-}--instance (a ~ b) => Comonad (BazaarT a b g) where-  extract (BazaarT m) = runIdentity (m Identity)-  {-# INLINE extract #-}-  duplicate = duplicateBazaarT-  {-# INLINE duplicate #-}--instance Gettable g => Gettable (BazaarT a b g) where-  coerce = (<$) (error "coerced BazaarT")-  {-# INLINE coerce #-}---- | Extract from a 'BazaarT'.------ @'bazaarT' = 'flip' 'runBazaarT'@-bazaarT :: Applicative f => (a -> f b) -> BazaarT a b g t -> f t-bazaarT afb (BazaarT m) = m afb-{-# INLINE bazaarT #-}---- | 'BazaarT' is an indexed 'Comonad'.-duplicateBazaarT :: BazaarT a c f t -> BazaarT a b f (BazaarT b c f t)-duplicateBazaarT (BazaarT m) = getCompose (m (Compose . fmap sellT . sellT))-{-# INLINE duplicateBazaarT #-}---- | A trivial 'BazaarT'.-sellT :: a -> BazaarT a b f b-sellT i = BazaarT (\k -> k i)-{-# INLINE sellT #-}----------------------------------------------------------------------------------- Prism Internals---------------------------------------------------------------------------------type family ArgOf (f_b :: *) :: *-type instance ArgOf (f b) = b---- | Extract @a@ from the type @a -> f b@-type family CoA x :: *---- | Extract @b@ from the type @a -> f b@-type family CoB x :: *-type instance CoA (a -> f_b) = a-type instance CoB (a -> f_b) = ArgOf f_b---- | This data type is used to capture all of the information provided by the--- 'Prismatic' class, so you can turn a 'Prism' around into a 'Getter' or--- otherwise muck around with its internals.------ If you see a function that expects a 'Prismoid' or 'APrism', it is probably--- just expecting a 'Prism'.-data Prismoid ab st where-  Prismoid :: Prismoid x x-  Prism :: (CoB x -> CoB y) -> (CoA y -> Either (CoB y) (CoA x)) -> Prismoid x y--instance Category Prismoid where-  id = Prismoid-  x . Prismoid = x-  Prismoid . x = x-  Prism ty xeys . Prism bt seta = Prism (ty.bt) $ \x ->-    case xeys x of-      Left y  -> Left y-      Right s -> case seta s of-        Left t  -> Left (ty t)-        Right a -> Right a--instance Isomorphic Prismoid where-  iso sa bt = Prism bt (Right . sa)-  {-# INLINE iso #-}--instance Prismatic Prismoid where-  prism    = Prism-  {-# INLINE prism #-}----------------------------------------------------------------------------------- Isomorphism Internals----------------------------------------------------------------------------------- | Reify all of the information given to you by being 'Isomorphic'.-data Isoid ab st where-  Isoid :: Isoid ab ab-  Iso   :: (CoA y -> CoA x) -> (CoB x -> CoB y) -> Isoid x y--instance Category Isoid where-  id = Isoid-  Isoid . x = x-  x . Isoid = x-  Iso xs ty . Iso sa bt = Iso (sa.xs) (ty.bt)--instance Isomorphic Isoid where-  iso   = Iso-  {-# INLINE iso #-}----------------------------------------------------------------------------------- Indexed Internals----------------------------------------------------------------------------------- | A function with access to a index. This constructor may be useful when you need to store--- a 'Indexable' in a container to avoid @ImpredicativeTypes@.-newtype Indexed i a b = Indexed { withIndex :: (i -> a) -> b }+import Control.Lens.Internal.Action+import Control.Lens.Internal.Bazaar+import Control.Lens.Internal.Context+import Control.Lens.Internal.Fold+import Control.Lens.Internal.Getter+import Control.Lens.Internal.Indexed+import Control.Lens.Internal.Instances ()+import Control.Lens.Internal.Iso+import Control.Lens.Internal.Level+import Control.Lens.Internal.Magma+import Control.Lens.Internal.Prism+import Control.Lens.Internal.Review+import Control.Lens.Internal.Setter+import Control.Lens.Internal.Zoom --- | Using an equality witness to avoid potential overlapping instances--- and aid dispatch.-instance i ~ j => Indexable i (Indexed j) where-  indexed = Indexed-  {-# INLINE indexed #-}+{-# ANN module "HLint: ignore Use import/export shortcut" #-}
+ src/Control/Lens/Internal/Action.hs view
@@ -0,0 +1,99 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE UndecidableInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FunctionalDependencies #-}+#ifdef TRUSTWORTHY+{-# LANGUAGE Trustworthy #-}+#endif+-----------------------------------------------------------------------------+-- |+-- Module      :  Control.Lens.Internal.Action+-- Copyright   :  (C) 2012-2013 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  provisional+-- Portability :  non-portable+--+----------------------------------------------------------------------------+module Control.Lens.Internal.Action+  (+  -- ** Actions+    Effective(..)+  , Effect(..)+  ) where++import Control.Applicative+import Control.Applicative.Backwards+import Control.Lens.Internal.Getter+import Control.Monad+import Data.Functor.Bind+import Data.Functor.Identity+import Data.Profunctor.Unsafe+import Data.Semigroup++-------------------------------------------------------------------------------+-- Programming with Effects+-------------------------------------------------------------------------------++-- | An 'Effective' 'Functor' ignores its argument and is isomorphic to a 'Monad' wrapped around a value.+--+-- That said, the 'Monad' is possibly rather unrelated to any 'Applicative' structure.+class (Monad m, Gettable f) => Effective m r f | f -> m r where+  effective :: m r -> f a+  ineffective :: f a -> m r++instance Effective m r f => Effective m (Dual r) (Backwards f) where+  effective = Backwards . effective . liftM getDual+  {-# INLINE effective #-}+  ineffective = liftM Dual . ineffective . forwards+  {-# INLINE ineffective #-}++instance Effective Identity r (Accessor r) where+  effective = Accessor #. runIdentity+  {-# INLINE effective #-}+  ineffective = Identity #. runAccessor+  {-# INLINE ineffective #-}++------------------------------------------------------------------------------+-- Effect+------------------------------------------------------------------------------++-- | Wrap a monadic effect with a phantom type argument.+newtype Effect m r a = Effect { getEffect :: m r }++instance Functor (Effect m r) where+  fmap _ (Effect m) = Effect m+  {-# INLINE fmap #-}++instance Gettable (Effect m r) where+  coerce (Effect m) = Effect m+  {-# INLINE coerce #-}++instance Monad m => Effective m r (Effect m r) where+  effective = Effect+  {-# INLINE effective #-}+  ineffective = getEffect+  {-# INLINE ineffective #-}++instance (Apply m, Semigroup r) => Semigroup (Effect m r a) where+  Effect ma <> Effect mb = Effect (liftF2 (<>) ma mb)+  {-# INLINE (<>) #-}++instance (Monad m, Monoid r) => Monoid (Effect m r a) where+  mempty = Effect (return mempty)+  {-# INLINE mempty #-}+  Effect ma `mappend` Effect mb = Effect (liftM2 mappend ma mb)+  {-# INLINE mappend #-}++instance (Apply m, Semigroup r) => Apply (Effect m r) where+  Effect ma <.> Effect mb = Effect (liftF2 (<>) ma mb)+  {-# INLINE (<.>) #-}++instance (Monad m, Monoid r) => Applicative (Effect m r) where+  pure _ = Effect (return mempty)+  {-# INLINE pure #-}+  Effect ma <*> Effect mb = Effect (liftM2 mappend ma mb)+  {-# INLINE (<*>) #-}
+ src/Control/Lens/Internal/Bazaar.hs view
@@ -0,0 +1,182 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE Rank2Types #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FunctionalDependencies #-}+#ifdef TRUSTWORTHY+{-# LANGUAGE Trustworthy #-}+#endif+-----------------------------------------------------------------------------+-- |+-- Module      :  Control.Lens.Internal.Bazaar+-- Copyright   :  (C) 2012-2013 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  experimental+-- Portability :  non-portable+--+----------------------------------------------------------------------------+module Control.Lens.Internal.Bazaar+  ( Bizarre(..)+  , Bazaar(..), Bazaar'+  , BazaarT(..), BazaarT'+  ) where++import Control.Applicative+import Control.Arrow as Arrow+import Control.Category+import Control.Comonad+import Control.Lens.Internal.Context+import Control.Lens.Internal.Getter+import Control.Lens.Internal.Indexed+import Data.Functor.Apply+import Data.Functor.Compose+import Data.Functor.Identity+import Data.Profunctor+import Data.Profunctor.Rep+import Data.Profunctor.Unsafe+import Prelude hiding ((.),id)++------------------------------------------------------------------------------+-- Bizarre+------------------------------------------------------------------------------++-- | This class is used to run the various 'Bazaar' variants used in this+-- library.+class Profunctor p => Bizarre p w | w -> p where+  bazaar :: Applicative f => p a (f b) -> w a b t -> f t++------------------------------------------------------------------------------+-- Bazaar+------------------------------------------------------------------------------++-- | This is used to characterize a 'Control.Lens.Traversal.Traversal'.+--+-- a.k.a. indexed Cartesian store comonad, indexed Kleene store comonad, or an indexed 'FunList'.+--+-- <http://twanvl.nl/blog/haskell/non-regular1>+--+-- A 'Bazaar' is like a 'Control.Lens.Traversal.Traversal' that has already been applied to some structure.+--+-- Where a @'Context' a b t@ holds an @a@ and a function from @b@ to+-- @t@, a @'Bazaar' a b t@ holds @N@ @a@s and a function from @N@+-- @b@s to @t@, (where @N@ might be infinite).+--+-- Mnemonically, a 'Bazaar' holds many stores and you can easily add more.+--+-- This is a final encoding of 'Bazaar'.+newtype Bazaar p a b t = Bazaar { runBazaar :: forall f. Applicative f => p a (f b) -> f t }++-- | This alias is helpful when it comes to reducing repetition in type signatures.+--+-- @+-- type 'Bazaar'' p a t = 'Bazaar' p a a t+-- @+type Bazaar' p a = Bazaar p a a++instance IndexedFunctor (Bazaar p) where+  ifmap f (Bazaar k) = Bazaar (fmap f . k)+  {-# INLINE ifmap #-}++instance Conjoined p => IndexedComonad (Bazaar p) where+  iextract (Bazaar m) = runIdentity $ m (arr Identity)+  {-# INLINE iextract #-}+  iduplicate (Bazaar m) = getCompose $ m (Compose #. distrib sell . sell)+  {-# INLINE iduplicate #-}++instance Corepresentable p => Sellable p (Bazaar p) where+  sell = cotabulate $ \ w -> Bazaar $ tabulate $ \k -> pure (corep k w)+  {-# INLINE sell #-}++instance Profunctor p => Bizarre p (Bazaar p) where+  bazaar g (Bazaar f) = f g+  {-# INLINE bazaar #-}++instance Functor (Bazaar p a b) where+  fmap = ifmap+  {-# INLINE fmap #-}++instance Apply (Bazaar p a b) where+  Bazaar mf <.> Bazaar ma = Bazaar $ \ pafb -> mf pafb <*> ma pafb+  {-# INLINE (<.>) #-}++instance Applicative (Bazaar p a b) where+  pure a = Bazaar $ \_ -> pure a+  {-# INLINE pure #-}+  Bazaar mf <*> Bazaar ma = Bazaar $ \ pafb -> mf pafb <*> ma pafb+  {-# INLINE (<*>) #-}++instance (a ~ b, Conjoined p) => Comonad (Bazaar p a b) where+  extract = iextract+  {-# INLINE extract #-}+  duplicate = iduplicate+  {-# INLINE duplicate #-}++instance (a ~ b, Conjoined p) => ComonadApply (Bazaar p a b) where+  (<@>) = (<*>)+  {-# INLINE (<@>) #-}++------------------------------------------------------------------------------+-- BazaarT+------------------------------------------------------------------------------++-- | 'BazaarT' is like 'Bazaar', except that it provides a questionable 'Gettable' instance+-- To protect this instance it relies on the soundness of another 'Gettable' type, and usage conventions.+--+-- For example. This lets us write a suitably polymorphic and lazy 'Control.Lens.Traversal.taking', but there+-- must be a better way!+newtype BazaarT p (g :: * -> *) a b t = BazaarT { runBazaarT :: forall f. Applicative f => p a (f b) -> f t }++-- | This alias is helpful when it comes to reducing repetition in type signatures.+--+-- @+-- type 'BazaarT'' p g a t = 'BazaarT' p g a a t+-- @+type BazaarT' p g a = BazaarT p g a a++instance IndexedFunctor (BazaarT p g) where+  ifmap f (BazaarT k) = BazaarT (fmap f . k)+  {-# INLINE ifmap #-}++instance Conjoined p => IndexedComonad (BazaarT p g) where+  iextract (BazaarT m) = runIdentity $ m (arr Identity)+  {-# INLINE iextract #-}+  iduplicate (BazaarT m) = getCompose $ m (Compose #. distrib sell . sell)+  {-# INLINE iduplicate #-}++instance Corepresentable p => Sellable p (BazaarT p g) where+  sell = cotabulate $ \ w -> BazaarT (`corep` w)+  {-# INLINE sell #-}++instance Profunctor p => Bizarre p (BazaarT p g) where+  bazaar g (BazaarT f) = f g+  {-# INLINE bazaar #-}++instance Functor (BazaarT p g a b) where+  fmap = ifmap+  {-# INLINE fmap #-}++instance Apply (BazaarT p g a b) where+  BazaarT mf <.> BazaarT ma = BazaarT $ \ pafb -> mf pafb <*> ma pafb+  {-# INLINE (<.>) #-}++instance Applicative (BazaarT p g a b) where+  pure a = BazaarT $ tabulate $ \_ -> pure (pure a)+  {-# INLINE pure #-}+  BazaarT mf <*> BazaarT ma = BazaarT $ \ pafb -> mf pafb <*> ma pafb+  {-# INLINE (<*>) #-}++instance (a ~ b, Conjoined p) => Comonad (BazaarT p g a b) where+  extract = iextract+  {-# INLINE extract #-}+  duplicate = iduplicate+  {-# INLINE duplicate #-}++instance (a ~ b, Conjoined p) => ComonadApply (BazaarT p g a b) where+  (<@>) = (<*>)+  {-# INLINE (<@>) #-}++instance (Profunctor p, Gettable g) => Gettable (BazaarT p g a b) where+  coerce = (<$) (error "coerced BazaarT")+  {-# INLINE coerce #-}
+ src/Control/Lens/Internal/ByteString.hs view
@@ -0,0 +1,216 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE Rank2Types #-}+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE PatternGuards #-}+{-# LANGUAGE FlexibleContexts #-}+-----------------------------------------------------------------------------+-- |+-- Module      :  Data.ByteString.Strict.Lens+-- Copyright   :  (C) 2012-2013 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  experimental+-- Portability :  non-portable+--+-- This module spends a lot of time fiddling around with 'Data.ByteString' internals+-- to work around <http://hackage.haskell.org/trac/ghc/ticket/7556> on older+-- Haskell Platforms and to improve constant and asymptotic factors in our performance.+----------------------------------------------------------------------------+module Control.Lens.Internal.ByteString+  ( unpackStrict, traversedStrict, traversedStrictTree+  , unpackStrict8, traversedStrict8, traversedStrictTree8+  , unpackLazy, traversedLazy+  , unpackLazy8, traversedLazy8+  ) where++import Control.Applicative+import Control.Lens+import qualified Data.ByteString               as B+import qualified Data.ByteString.Lazy          as BL+import qualified Data.ByteString.Lazy.Internal as BLI+import qualified Data.ByteString.Lazy.Char8    as BL8+import qualified Data.ByteString.Internal      as BI+import Data.Bits+import Data.Char+import Data.Int (Int64)+import Data.Word (Word8)+import Foreign.Ptr+import Foreign.Storable+import Foreign.ForeignPtr.Safe+import Foreign.ForeignPtr.Unsafe+import GHC.Base (unsafeChr)+import GHC.ForeignPtr (mallocPlainForeignPtrBytes)+import GHC.IO (unsafeDupablePerformIO)++-- | Traverse a strict 'B.ByteString' from left to right in a biased fashion.+traversedStrict :: Int -> IndexedTraversal' Int B.ByteString Word8+traversedStrict i0 pafb (BI.PS fp off len) =+  let p = unsafeForeignPtrToPtr fp+   in fmap (rebuild len) (go i0 (p `plusPtr` off) (p `plusPtr` (off+len)))+ where+   rebuild n = \xs -> unsafeCreate n $ \p -> go2 p xs+   go2 !p (x:xs) = poke p x >> go2 (p `plusPtr` 1) xs+   go2 _  []     = return ()+   -- TODO: use a balanced tree (up to some grain size)+   go !i !p !q+     | p == q = pure []+     | otherwise = let !x = BI.inlinePerformIO $ do+                              x' <- peek p+                              touchForeignPtr fp+                              return x'+                   in (:) <$> indexed pafb (i :: Int) x <*> go (i + 1) (p `plusPtr` 1) q+{-# INLINE traversedStrict #-}++-- | Traverse a strict 'B.ByteString' from left to right in a biased fashion+-- pretending the bytes are characters.+traversedStrict8 :: Int -> IndexedTraversal' Int B.ByteString Char+traversedStrict8 i0 pafb (BI.PS fp off len) =+  let p = unsafeForeignPtrToPtr fp+   in fmap (rebuild len) (go i0 (p `plusPtr` off) (p `plusPtr` (off+len)))+ where+   rebuild n = \xs -> unsafeCreate n $ \p -> go2 p xs+   go2 !p (x:xs) = poke p (c2w x) >> go2 (p `plusPtr` 1) xs+   go2 _  []     = return ()+   -- TODO: use a balanced tree (up to some grain size)+   go !i !p !q+     | p == q = pure []+     | otherwise = let !x = BI.inlinePerformIO $ do+                              x' <- peek p+                              touchForeignPtr fp+                              return x'+                   in (:) <$> indexed pafb (i :: Int) (w2c x) <*> go (i + 1) (p `plusPtr` 1) q+{-# INLINE traversedStrict8 #-}++grain :: Int+grain = 32+{-# INLINE grain #-}++-- | Traverse a strict 'B.ByteString' in a relatively balanced fashion, as a balanced tree with biased runs of+-- elements at the leaves.+traversedStrictTree :: Int -> IndexedTraversal' Int B.ByteString Word8+traversedStrictTree i0 pafb (BI.PS fp off len) = rebuild len <$> go i0 (i0 + len)+ where+   p = unsafeForeignPtrToPtr fp `plusPtr` (off - i0)+   rebuild n f = unsafeCreate n $ \q -> f (q `plusPtr` (off - i0))+   go !i !j+     | i + grain < j, k <- i + shiftR (j - i) 1 = (\l r q -> l q >> r q) <$> go i k <*> go k j+     | otherwise = run i j+   run !i !j+     | i == j    = pure (\_ -> return ())+     | otherwise = let !x = BI.inlinePerformIO $ do+                          x' <- peekByteOff p i+                          touchForeignPtr fp+                          return x'+                   in (\y ys q -> poke (q `plusPtr` i) y >> ys q) <$> indexed pafb (i :: Int) x <*> run (i + 1) j+{-# INLINE traversedStrictTree #-}++-- | Traverse a strict 'B.ByteString' in a relatively balanced fashion, as a balanced tree with biased runs of+-- elements at the leaves, pretending the bytes are chars.+traversedStrictTree8 :: Int -> IndexedTraversal' Int B.ByteString Char+traversedStrictTree8 i0 pafb (BI.PS fp off len) = rebuild len <$> go i0 (i0 + len)+ where+   p = unsafeForeignPtrToPtr fp `plusPtr` (off - i0)+   rebuild n f = unsafeCreate n $ \q -> f (q `plusPtr` (off - i0))+   go !i !j+     | i + grain < j, k <- i + shiftR (j - i) 1 = (\l r q -> l q >> r q) <$> go i k <*> go k j+     | otherwise = run i j+   run !i !j+     | i == j    = pure (\_ -> return ())+     | otherwise = let !x = BI.inlinePerformIO $ do+                          x' <- peekByteOff p i+                          touchForeignPtr fp+                          return x'+                   in (\y ys q -> poke (q `plusPtr` i) (c2w y) >> ys q) <$> indexed pafb (i :: Int) (w2c x) <*> run (i + 1) j+{-# INLINE traversedStrictTree8 #-}++-- | Unpack a lazy 'Bytestring'+unpackLazy :: BL.ByteString -> [Word8]+unpackLazy = BL.unpack+{-# INLINE unpackLazy #-}++-- | An 'IndexedTraversal' of the individual bytes in a lazy 'BL.ByteString'+traversedLazy :: IndexedTraversal' Int64 BL.ByteString Word8+traversedLazy pafb = go 0 where+  go _ BLI.Empty        = pure BLI.Empty+  go i (BLI.Chunk b bs) = BLI.Chunk <$> reindexed (fromIntegral :: Int -> Int64) (traversedStrictTree (fromIntegral i)) pafb b <*> go i' bs+    where !i' = i + B.length b+{-# INLINE traversedLazy #-}+++-- | Unpack a lazy 'BL.ByteString' pretending the bytes are chars.+unpackLazy8 :: BL.ByteString -> String+unpackLazy8 = BL8.unpack+{-# INLINE unpackLazy8 #-}++-- | An 'IndexedTraversal' of the individual bytes in a lazy 'BL.ByteString' pretending the bytes are chars.+traversedLazy8 :: IndexedTraversal' Int64 BL.ByteString Char+traversedLazy8 pafb = go 0 where+  go _ BLI.Empty = pure BLI.Empty+  go i (BLI.Chunk b bs) = BLI.Chunk <$> reindexed (fromIntegral :: Int -> Int64) (traversedStrictTree8 (fromIntegral i)) pafb b <*> go i' bs+    where !i' = i + B.length b+{-# INLINE traversedLazy8 #-}++------------------------------------------------------------------------------+-- ByteString guts+------------------------------------------------------------------------------++-- | Conversion between 'Word8' and 'Char'. Should compile to a no-op.+w2c :: Word8 -> Char+w2c = unsafeChr . fromIntegral+{-# INLINE w2c #-}++-- | Unsafe conversion between 'Char' and 'Word8'. This is a no-op and+-- silently truncates to 8 bits Chars > '\255'. It is provided as+-- convenience for ByteString construction.+c2w :: Char -> Word8+c2w = fromIntegral . ord+{-# INLINE c2w #-}++-- TODO: Should this create the list in chunks, like unpackBytes does in 0.10?++-- | Unpack a strict 'B.Bytestring'+unpackStrict :: B.ByteString -> [Word8]+unpackStrict (BI.PS fp off len) =+      let p = unsafeForeignPtrToPtr fp+       in go (p `plusPtr` off) (p `plusPtr` (off+len))+    where+      go !p !q | p == q    = []+               | otherwise = let !x = BI.inlinePerformIO $ do+                                        x' <- peek p+                                        touchForeignPtr fp+                                        return x'+                             in x : go (p `plusPtr` 1) q+{-# INLINE unpackStrict #-}++-- TODO: Should this create the list in chunks, like unpackBytes does in 0.10?++-- | Unpack a strict 'B.Bytestring', pretending the bytes are chars.+unpackStrict8 :: B.ByteString -> String+unpackStrict8 (BI.PS fp off len) =+      let p = unsafeForeignPtrToPtr fp+       in go (p `plusPtr` off) (p `plusPtr` (off+len))+    where+      go !p !q | p == q    = []+               | otherwise = let !x = BI.inlinePerformIO $ do+                                        x' <- peek p+                                        touchForeignPtr fp+                                        return x'+                             in w2c x : go (p `plusPtr` 1) q+{-# INLINE unpackStrict8 #-}+++-- | A way of creating ByteStrings outside the IO monad. The @Int@+-- argument gives the final size of the ByteString. Unlike+-- 'createAndTrim' the ByteString is not reallocated if the final size+-- is less than the estimated size.+unsafeCreate :: Int -> (Ptr Word8 -> IO ()) -> B.ByteString+unsafeCreate l f = unsafeDupablePerformIO (create l f)+{-# INLINE unsafeCreate #-}++-- | Create ByteString of size @l@ and use action @f@ to fill it's contents.+create :: Int -> (Ptr Word8 -> IO ()) -> IO B.ByteString+create l f = do+    fp <- mallocPlainForeignPtrBytes l+    withForeignPtr fp $ \p -> f p+    return $! BI.PS fp 0 l+{-# INLINE create #-}
− src/Control/Lens/Internal/Combinators.hs
@@ -1,231 +0,0 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE MagicHash #-}-#if defined(TRUSTWORTHY) && !defined(SAFE)-{-# LANGUAGE Trustworthy #-}-#endif--------------------------------------------------------------------------------- |--- Module      :  Control.Lens.Internal.Combinators--- Copyright   :  (C) 2012 Edward Kmett, Shachaf Ben-Kiki--- License     :  BSD-style (see the file LICENSE)--- Maintainer  :  Edward Kmett <ekmett@gmail.com>--- Stability   :  provisional--- Portability :  Rank2Types, KindSignatures------ This module is not exported from this package.------ These combinators are used to reduce eta-expansion in the resulting code--- which could otherwise cause both a constant and asymptotic slowdown to--- code execution.------ Many micro-benchmarks are improved up to 50%, and larger benchmarks can--- win asymptotically.---------------------------------------------------------------------------------module Control.Lens.Internal.Combinators-  (-  -- * Safe "Unsafe" Coercions-    const#, getConst#-  , zipList#, getZipList#-  , wrapMonad#, unwrapMonad#-  , last#, getLast#-  , first#, getFirst#-  , product#, getProduct#-  , sum#, getSum#-  , any#, getAny#-  , all#, getAll#-  , dual#, getDual#-  , endo#, appEndo#-  , may#, getMay#-  , folding#, getFolding#-  , effect#, getEffect#-  , effectRWS#, getEffectRWS#-  , accessor#, runAccessor#-  , err#, getErr#-  , traversed#, getTraversed#-  , sequenced#, getSequenced#-  , focusing#, unfocusing#-  , focusingWith#, unfocusingWith#-  , focusingPlus#, unfocusingPlus#-  , focusingOn#, unfocusingOn#-  , focusingMay#, unfocusingMay#-  , focusingErr#, unfocusingErr#-  , mutator#, runMutator#-  , backwards#, forwards#-  ) where--import Control.Applicative-import Control.Applicative.Backwards-import Control.Lens.Internal-import Data.Monoid-#ifndef SAFE-import Unsafe.Coerce-#endif--#ifndef SAFE-#define UNSAFELY(x) unsafeCoerce-#else-#define UNSAFELY(f) (\g -> g `seq` \x -> (f) (g x))-#endif--const# :: (a -> b) -> a -> Const b r-const# = UNSAFELY(Const)--getConst# :: (a -> Const b r) -> a -> b-getConst# = UNSAFELY(getConst)--zipList# :: (a -> [b]) -> a -> ZipList b-zipList# = UNSAFELY(ZipList)--getZipList# :: (a -> ZipList b) -> a -> [b]-getZipList# = UNSAFELY(getZipList)--wrapMonad# :: (a -> m b) -> a -> WrappedMonad m b-wrapMonad# = UNSAFELY(WrapMonad)--unwrapMonad# :: (a -> WrappedMonad m b) -> a -> m b-unwrapMonad# = UNSAFELY(unwrapMonad)--last# :: (a -> Maybe b) -> a -> Last b-last# = UNSAFELY(Last)--getLast# :: (a -> Last b) -> a -> Maybe b-getLast# = UNSAFELY(getLast)--first# :: (a -> Maybe b) -> a -> First b-first# = UNSAFELY(First)--getFirst# :: (a -> First b) -> a -> Maybe b-getFirst# = UNSAFELY(getFirst)--product# :: (a -> b) -> a -> Product b-product# = UNSAFELY(Product)--getProduct# :: (a -> Product b) -> a -> b-getProduct# = UNSAFELY(getProduct)--sum# :: (a -> b) -> a -> Sum b-sum# = UNSAFELY(Sum)--getSum# :: (a -> Sum b) -> a -> b-getSum# = UNSAFELY(getSum)--any# :: (a -> Bool) -> a -> Any-any# = UNSAFELY(Any)--getAny# :: (a -> Any) -> a -> Bool-getAny# = UNSAFELY(getAny)--all# :: (a -> Bool) -> a -> All-all# = UNSAFELY(All)--getAll# :: (a -> All) -> a -> Bool-getAll# = UNSAFELY(getAll)--dual# :: (a -> b) -> a -> Dual b-dual# = UNSAFELY(Dual)--getDual# :: (a -> Dual b) -> a -> b-getDual# = UNSAFELY(getDual)--endo# :: (a -> b -> b) -> a -> Endo b-endo# = UNSAFELY(Endo)--appEndo# :: (a -> Endo b) -> a -> b -> b-appEndo# = UNSAFELY(appEndo)--may# :: (a -> Maybe b) -> a -> May b-may# = UNSAFELY(May)--getMay# :: (a -> May b) -> a -> Maybe b-getMay# = UNSAFELY(getMay)--folding# :: (a -> f b) -> a -> Folding f b-folding# = UNSAFELY(Folding)--getFolding# :: (a -> Folding f b) -> a -> f b-getFolding# = UNSAFELY(getFolding)--effect# :: (a -> m r) -> a -> Effect m r b-effect# = UNSAFELY(Effect)--getEffect# :: (a -> Effect m r b) -> a -> m r-getEffect# = UNSAFELY(getEffect)--effectRWS# :: (a -> st -> m (s, st, w)) -> a -> EffectRWS w st m s b-effectRWS# = UNSAFELY(EffectRWS)--getEffectRWS# :: (a -> EffectRWS w st m s b) -> a -> st -> m (s, st, w)-getEffectRWS# = UNSAFELY(getEffectRWS)--accessor# :: (a -> r) -> a -> Accessor r b-accessor# = UNSAFELY(Accessor)--runAccessor# :: (a -> Accessor r b) -> a -> r-runAccessor# = UNSAFELY(runAccessor)--err# :: (a -> Either e b) -> a -> Err e b-err# = UNSAFELY(Err)--getErr# :: (a -> Err e b) -> a -> Either e b-getErr# = UNSAFELY(getErr)--traversed# :: (a -> f ()) -> a -> Traversed f-traversed# = UNSAFELY(Traversed)--getTraversed# :: (a -> Traversed f) -> a -> f ()-getTraversed# = UNSAFELY(getTraversed)--sequenced# :: (a -> f ()) -> a -> Sequenced f-sequenced# = UNSAFELY(Sequenced)--getSequenced# :: (a -> Sequenced f) -> a -> f ()-getSequenced# = UNSAFELY(getSequenced)--focusing# :: (a -> m (s, b)) -> a -> Focusing m s b-focusing# = UNSAFELY(Focusing)--unfocusing# :: (a -> Focusing m s b) -> a -> m (s, b)-unfocusing# = UNSAFELY(unfocusing)--focusingWith# :: (a -> m (s, b, w)) -> a -> FocusingWith w m s b-focusingWith# = UNSAFELY(FocusingWith)--unfocusingWith# :: (a -> FocusingWith w m s b) -> a -> m (s, b, w)-unfocusingWith# = UNSAFELY(unfocusingWith)--focusingPlus# :: (a -> k (s, w) b) -> a -> FocusingPlus w k s b-focusingPlus# = UNSAFELY(FocusingPlus)--unfocusingPlus# :: (a -> FocusingPlus w k s b) -> a -> k (s, w) b-unfocusingPlus# = UNSAFELY(unfocusingPlus)--focusingOn# :: (a -> k (f s) b) -> a -> FocusingOn f k s b-focusingOn# = UNSAFELY(FocusingOn)--unfocusingOn# :: (a -> FocusingOn f k s b) -> a -> k (f s) b-unfocusingOn# = UNSAFELY(unfocusingOn)--focusingMay# :: (a -> k (May s) b) -> a -> FocusingMay k s b-focusingMay# = UNSAFELY(FocusingMay)--unfocusingMay# :: (a -> FocusingMay k s b) -> a -> k (May s) b-unfocusingMay# = UNSAFELY(unfocusingMay)--focusingErr# :: (a -> k (Err e s) b) -> a -> FocusingErr e k s b-focusingErr# = UNSAFELY(FocusingErr)--unfocusingErr# :: (a -> FocusingErr e k s b) -> a -> k (Err e s) b-unfocusingErr# = UNSAFELY(unfocusingErr)--mutator# :: (a -> b) -> a -> Mutator b-mutator# = UNSAFELY(Mutator)--runMutator# :: (a -> Mutator b) -> a -> b-runMutator# = UNSAFELY(runMutator)--backwards# :: (a -> f b) -> a -> Backwards f b-backwards# = UNSAFELY(Backwards)--forwards# :: (a -> Backwards f b) -> a -> f b-forwards# = UNSAFELY(forwards)
+ src/Control/Lens/Internal/Context.hs view
@@ -0,0 +1,353 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE Rank2Types #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE KindSignatures #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FunctionalDependencies #-}+#ifdef TRUSTWORTHY+{-# LANGUAGE Trustworthy #-}+#endif+-----------------------------------------------------------------------------+-- |+-- Module      :  Control.Lens.Internal.Context+-- Copyright   :  (C) 2012-2013 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  experimental+-- Portability :  non-portable+--+----------------------------------------------------------------------------+module Control.Lens.Internal.Context+  ( IndexedFunctor(..)+  , IndexedComonad(..)+  , IndexedComonadStore(..)+  , Sellable(..)+  , Context(..), Context'+  , Pretext(..), Pretext'+  , PretextT(..), PretextT'+  ) where++import Control.Applicative+import Control.Arrow+import Control.Category+import Control.Comonad+import Control.Comonad.Store.Class+import Control.Lens.Internal.Getter+import Control.Lens.Internal.Indexed+import Data.Functor.Compose+import Data.Functor.Identity+import Data.Profunctor+import Data.Profunctor.Rep+import Data.Profunctor.Unsafe+import Prelude hiding ((.),id)++------------------------------------------------------------------------------+-- IndexedFunctor+------------------------------------------------------------------------------++-- | This is a Bob Atkey -style 2-argument indexed functor.+--+-- It exists as a superclass for 'IndexedComonad' and expresses the functoriality+-- of an 'IndexedComonad' in its third argument.+class IndexedFunctor w where+  ifmap :: (s -> t) -> w a b s -> w a b t++------------------------------------------------------------------------------+-- IndexedComonad+------------------------------------------------------------------------------++-- | This is a Bob Atkey -style 2-argument indexed comonad.+--+-- It exists as a superclass for 'IndexedComonad' and expresses the functoriality+-- of an 'IndexedComonad' in its third argument.+--+-- The notion of indexed monads is covered in more depth in Bob Atkey's+-- "Parameterized Notions of Computation" <http://bentnib.org/paramnotions-jfp.pdf>+-- and that construction is dualized here.+class IndexedFunctor w => IndexedComonad w where+  -- | extract from an indexed comonadic value when the indices match.+  iextract :: w a a t -> t++  -- | duplicate an indexed comonadic value splitting the index.+  iduplicate :: w a c t -> w a b (w b c t)+  iduplicate = iextend id+  {-# INLINE iduplicate #-}++  -- | extend a indexed comonadic computation splitting the index.+  iextend :: (w b c t -> r) -> w a c t -> w a b r+  iextend f = ifmap f . iduplicate+  {-# INLINE iextend #-}++------------------------------------------------------------------------------+-- IndexedComonadStore+------------------------------------------------------------------------------++-- | This is an indexed analogue to 'ComonadStore' for when you are working with an +-- 'IndexedComonad'.+class IndexedComonad w => IndexedComonadStore w where+  -- | This is the generalization of 'pos' to an indexed comonad store.+  ipos :: w a c t -> a++  -- | This is the generalization of 'peek' to an indexed comonad store.+  ipeek :: c  -> w a c t -> t+  ipeek c = iextract . iseek c+  {-# INLINE ipeek #-}++  -- | This is the generalization of 'peeks' to an indexed comonad store.+  ipeeks :: (a -> c) -> w a c t -> t+  ipeeks f = iextract . iseeks f+  {-# INLINE ipeeks #-}++  -- | This is the generalization of 'seek' to an indexed comonad store.+  iseek :: b  -> w a c t -> w b c t++  -- | This is the generalization of 'seeks' to an indexed comonad store.+  iseeks :: (a -> b) -> w a c t -> w b c t++  -- | This is the generalization of 'experiment' to an indexed comonad store.+  iexperiment :: Functor f => (b -> f c) -> w b c t -> f t+  iexperiment bfc wbct = (`ipeek` wbct) <$> bfc (ipos wbct)+  {-# INLINE iexperiment #-}++  -- | We can always forget the rest of the structure of 'w' and obtain a simpler+  -- indexed comonad store model called 'Context'.+  context :: w a b t -> Context a b t+  context wabt = Context (`ipeek` wabt) (ipos wabt)+  {-# INLINE context #-}++------------------------------------------------------------------------------+-- Sellable+------------------------------------------------------------------------------++-- | This is used internally to construct a 'Control.Lens.Internal.Bazaar.Bazaar', 'Context' or 'Pretext'+-- from a singleton value.+class Corepresentable p => Sellable p w | w -> p where+  sell :: p a (w a b b)++------------------------------------------------------------------------------+-- Context+------------------------------------------------------------------------------++-- | The indexed store can be used to characterize a 'Control.Lens.Lens.Lens'+-- and is used by 'Control.Lens.Lens.clone'.+--+-- @'Context' a b t@ is isomorphic to+-- @newtype 'Context' a b t = 'Context' { runContext :: forall f. 'Functor' f => (a -> f b) -> f t }@,+-- and to @exists s. (s, 'Control.Lens.Lens.Lens' s t a b)@.+--+-- A 'Context' is like a 'Control.Lens.Lens.Lens' that has already been applied to a some structure.+data Context a b t = Context (b -> t) a++instance IndexedFunctor Context where+  ifmap f (Context g t) = Context (f . g) t+  {-# INLINE ifmap #-}++instance IndexedComonad Context where+  iextract   (Context f a) = f a+  {-# INLINE iextract #-}+  iduplicate (Context f a) = Context (Context f) a+  {-# INLINE iduplicate #-}+  iextend g  (Context f a) = Context (g . Context f) a+  {-# INLINE iextend #-}++instance IndexedComonadStore Context where+  ipos (Context _ a) = a+  {-# INLINE ipos #-}+  ipeek b (Context g _) = g b+  {-# INLINE ipeek #-}+  ipeeks f (Context g a) = g (f a)+  {-# INLINE ipeeks #-}+  iseek a (Context g _) = Context g a+  {-# INLINE iseek #-}+  iseeks f (Context g a) = Context g (f a)+  {-# INLINE iseeks #-}+  iexperiment f (Context g a) = g <$> f a+  {-# INLINE iexperiment #-}+  context = id+  {-# INLINE context #-}++instance Functor (Context a b) where+  fmap f (Context g t) = Context (f . g) t+  {-# INLINE fmap #-}++instance a ~ b => Comonad (Context a b) where+  extract   (Context f a) = f a+  {-# INLINE extract #-}+  duplicate (Context f a) = Context (Context f) a+  {-# INLINE duplicate #-}+  extend g  (Context f a) = Context (g . Context f) a+  {-# INLINE extend #-}++instance a ~ b => ComonadStore a (Context a b) where+  pos = ipos+  {-# INLINE pos #-}+  peek = ipeek+  {-# INLINE peek #-}+  peeks = ipeeks+  {-# INLINE peeks #-}+  seek = iseek+  {-# INLINE seek #-}+  seeks = iseeks+  {-# INLINE seeks #-}+  experiment = iexperiment+  {-# INLINE experiment #-}++instance Sellable (->) Context where+  sell = Context id+  {-# INLINE sell #-}++-- | @type 'Context'' a s = 'Context' a a s@+type Context' a = Context a a++------------------------------------------------------------------------------+-- Pretext+------------------------------------------------------------------------------++-- | This is a generalized form of 'Context' that can be repeatedly cloned with less+-- impact on its performance, and which permits the use of an arbitrary 'Conjoined'+-- 'Profunctor'+newtype Pretext p a b t = Pretext { runPretext :: forall f. Functor f => p a (f b) -> f t }++-- | @type 'Pretext'' p a s = 'Pretext' p a a s@+type Pretext' p a = Pretext p a a++instance IndexedFunctor (Pretext p) where+  ifmap f (Pretext k) = Pretext (fmap f . k)+  {-# INLINE ifmap #-}++instance Functor (Pretext p a b) where+  fmap = ifmap+  {-# INLINE fmap #-}++instance Conjoined p => IndexedComonad (Pretext p) where+  iextract (Pretext m) = runIdentity $ m (arr Identity)+  {-# INLINE iextract #-}+  iduplicate (Pretext m) = getCompose $ m (Compose #. distrib sell . sell)+  {-# INLINE iduplicate #-}++instance (a ~ b, Conjoined p) => Comonad (Pretext p a b) where+  extract = iextract+  {-# INLINE extract #-}+  duplicate = iduplicate+  {-# INLINE duplicate #-}++instance Conjoined p => IndexedComonadStore (Pretext p) where+  ipos (Pretext m) = getConst $ coarr m $ arr Const+  {-# INLINE ipos #-}+  ipeek a (Pretext m) = runIdentity $ coarr m $ arr (\_ -> Identity a)+  {-# INLINE ipeek #-}+  ipeeks f (Pretext m) = runIdentity $ coarr m $ arr (Identity . f)+  {-# INLINE ipeeks #-}+  iseek a (Pretext m) = Pretext (lmap (lmap (const a)) m)+  {-# INLINE iseek #-}+  iseeks f (Pretext m) = Pretext (lmap (lmap f) m)+  {-# INLINE iseeks #-}+  iexperiment f (Pretext m) = coarr m (arr f)+  {-# INLINE iexperiment #-}+  context (Pretext m) = coarr m (arr sell)+  {-# INLINE context #-}++instance (a ~ b, Conjoined p) => ComonadStore a (Pretext p a b) where+  pos = ipos+  {-# INLINE pos #-}+  peek = ipeek+  {-# INLINE peek #-}+  peeks = ipeeks+  {-# INLINE peeks #-}+  seek = iseek+  {-# INLINE seek #-}+  seeks = iseeks+  {-# INLINE seeks #-}+  experiment = iexperiment+  {-# INLINE experiment #-}++instance Corepresentable p => Sellable p (Pretext p) where+  sell = cotabulate $ \ w -> Pretext (`corep` w)+  {-# INLINE sell #-}++------------------------------------------------------------------------------+-- PretextT+------------------------------------------------------------------------------++-- | This is a generalized form of 'Context' that can be repeatedly cloned with less+-- impact on its performance, and which permits the use of an arbitrary 'Conjoined'+-- 'Profunctor'.+--+-- The extra phantom 'Functor' is used to let us lie and claim a 'Gettable' instance under+-- limited circumstances. This is used internally to permit a number of combinators to+-- gracefully degrade when applied to a 'Control.Lens.Fold.Fold', 'Control.Lens.Getter.Getter'+-- or 'Control.Lens.Action.Action'.+newtype PretextT p (g :: * -> *) a b t = PretextT { runPretextT :: forall f. Functor f => p a (f b) -> f t }++-- | @type 'PretextT'' p g a s = 'PretextT' p g a a s@+type PretextT' p g a = PretextT p g a a++instance IndexedFunctor (PretextT p g) where+  ifmap f (PretextT k) = PretextT (fmap f . k)+  {-# INLINE ifmap #-}++instance Functor (PretextT p g a b) where+  fmap = ifmap+  {-# INLINE fmap #-}++instance Conjoined p => IndexedComonad (PretextT p g) where+  iextract (PretextT m) = runIdentity $ m (arr Identity)+  {-# INLINE iextract #-}+  iduplicate (PretextT m) = getCompose $ m (Compose #. distrib sell . sell)+  {-# INLINE iduplicate #-}++instance (a ~ b, Conjoined p) => Comonad (PretextT p g a b) where+  extract = iextract+  {-# INLINE extract #-}+  duplicate = iduplicate+  {-# INLINE duplicate #-}++instance Conjoined p => IndexedComonadStore (PretextT p g) where+  ipos (PretextT m) = getConst $ coarr m $ arr Const+  {-# INLINE ipos #-}+  ipeek a (PretextT m) = runIdentity $ coarr m $ arr (\_ -> Identity a)+  {-# INLINE ipeek #-}+  ipeeks f (PretextT m) = runIdentity $ coarr m $ arr (Identity . f)+  {-# INLINE ipeeks #-}+  iseek a (PretextT m) = PretextT (lmap (lmap (const a)) m)+  {-# INLINE iseek #-}+  iseeks f (PretextT m) = PretextT (lmap (lmap f) m)+  {-# INLINE iseeks #-}+  iexperiment f (PretextT m) = coarr m (arr f)+  {-# INLINE iexperiment #-}+  context (PretextT m) = coarr m (arr sell)+  {-# INLINE context #-}++instance (a ~ b, Conjoined p) => ComonadStore a (PretextT p g a b) where+  pos = ipos+  {-# INLINE pos #-}+  peek = ipeek+  {-# INLINE peek #-}+  peeks = ipeeks+  {-# INLINE peeks #-}+  seek = iseek+  {-# INLINE seek #-}+  seeks = iseeks+  {-# INLINE seeks #-}+  experiment = iexperiment+  {-# INLINE experiment #-}++instance Corepresentable p => Sellable p (PretextT p g) where+  sell = cotabulate $ \ w -> PretextT (`corep` w)+  {-# INLINE sell #-}++instance (Profunctor p, Gettable g) => Gettable (PretextT p g a b) where+  coerce = (<$) (error "coerced PretextT")+  {-# INLINE coerce #-}++------------------------------------------------------------------------------+-- Utilities+------------------------------------------------------------------------------++-- | We can convert any 'Conjoined' 'Profunctor' to a function,+-- possibly losing information about an index in the process.+coarr :: (Representable q, Comonad (Rep q)) => q a b -> a -> b+coarr qab = extract . rep qab+{-# INLINE coarr #-}
+ src/Control/Lens/Internal/Deque.hs view
@@ -0,0 +1,200 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE PatternGuards #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+#ifdef TRUSTWORTHY+{-# LANGUAGE Trustworthy #-}+#endif+-----------------------------------------------------------------------------+-- |+-- Module      :  Control.Lens.Internal.Deque+-- Copyright   :  (C) 2012-13 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  experimental+-- Portability :  non-portable+--+-- This module is designed to be imported qualified.+-----------------------------------------------------------------------------+module Control.Lens.Internal.Deque+  ( Deque(..)+  , size+  , fromList+  , null+  , singleton+  ) where++import Control.Applicative+import Control.Lens.Combinators+import Control.Lens.Cons+import Control.Lens.Fold+import Control.Lens.Indexed hiding ((<.>))+import Control.Lens.Prism+import Control.Monad+import Data.Foldable as Foldable+import Data.Function+import Data.Functor.Bind+import Data.Functor.Plus+import Data.Functor.Reverse+import Data.Traversable as Traversable+import Data.Semigroup+import Data.Profunctor.Unsafe+import Prelude hiding (null)++-- | A Banker's deque based on Chris Okasaki's \"Purely Functional Data Structures\"+data Deque a = BD !Int [a] !Int [a]+  deriving Show++-- | /O(1)/. Determine of a 'Deque' is 'empty'.+--+-- >>> null empty+-- True+--+-- >>> null (singleton 1)+-- False+null :: Deque a -> Bool+null (BD lf _ lr _) = lf + lr == 0+{-# INLINE null #-}++-- | /O(1)/. Generate a singleton 'Deque'+--+-- >>> singleton 1+-- BD 1 [1] 0 []+singleton :: a -> Deque a+singleton a = BD 1 [a] 0 []+{-# INLINE singleton #-}++-- | /O(1)/. Calculate the size of a 'Deque'+--+-- >>> size (fromList [1,4,6])+-- 3+size :: Deque a -> Int+size (BD lf _ lr _) = lf + lr+{-# INLINE size #-}++-- | /O(n)/ amortized. Construct a 'Deque' from a list of values.+--+-- >>> fromList [1,2]+-- BD 1 [1] 1 [2]+fromList :: [a] -> Deque a+fromList = Prelude.foldr cons empty+{-# INLINE fromList #-}++instance Eq a => Eq (Deque a) where+  (==) = (==) `on` toList+  {-# INLINE (==) #-}++instance Ord a => Ord (Deque a) where+  compare = compare `on` toList+  {-# INLINE compare #-}++instance Functor Deque where+  fmap h (BD lf f lr r) = BD lf (fmap h f) lr (fmap h r)+  {-# INLINE fmap #-}++instance FunctorWithIndex Int Deque where+  imap h (BD lf f lr r) = BD lf (imap h f) lr (imap (\j -> h (n - j)) r)+    where !n = lf + lr++instance Apply Deque where+  fs <.> as = fromList (toList fs <.> toList as)+  {-# INLINE (<.>) #-}++instance Applicative Deque where+  pure a = BD 1 [a] 0 []+  {-# INLINE pure #-}+  fs <*> as = fromList (toList fs <*> toList as)+  {-# INLINE (<*>) #-}++instance Alt Deque where+  xs <!> ys+    | size xs < size ys = Foldable.foldr cons ys xs+    | otherwise         = Foldable.foldl snoc xs ys+  {-# INLINE (<!>) #-}++instance Plus Deque where+  zero = BD 0 [] 0 []+  {-# INLINE zero #-}++instance Alternative Deque where+  empty = BD 0 [] 0 []+  {-# INLINE empty #-}+  xs <|> ys+    | size xs < size ys = Foldable.foldr cons ys xs+    | otherwise         = Foldable.foldl snoc xs ys+  {-# INLINE (<|>) #-}++instance Bind Deque where+  ma >>- k = fromList (toList ma >>= toList . k)+  {-# INLINE (>>-) #-}++instance Monad Deque where+  return a = BD 1 [a] 0 []+  {-# INLINE return #-}+  ma >>= k = fromList (toList ma >>= toList . k)+  {-# INLINE (>>=) #-}++instance MonadPlus Deque where+  mzero = empty+  {-# INLINE mzero #-}+  mplus = (<|>)+  {-# INLINE mplus #-}++instance Foldable Deque where+  foldMap h (BD _ f _ r) = foldMap h f `mappend` getDual (foldMap (Dual #. h) r)+  {-# INLINE foldMap #-}++instance FoldableWithIndex Int Deque where+  ifoldMap h (BD lf f lr r) = ifoldMap h f `mappend` getDual (ifoldMap (\j -> Dual #. h (n - j)) r)+    where !n = lf + lr+  {-# INLINE ifoldMap #-}++instance Traversable Deque where+  traverse h (BD lf f lr r) = (BD lf ?? lr) <$> traverse h f <*> backwards traverse h r+  {-# INLINE traverse #-}++instance TraversableWithIndex Int Deque where+  itraverse h (BD lf f lr r) = (\f' r' -> BD lr f' lr (getReverse r')) <$> itraverse h f <*> itraverse (\j -> h (n - j)) (Reverse r)+    where !n = lf + lr+  {-# INLINE itraverse #-}++instance Semigroup (Deque a) where+  xs <> ys+    | size xs < size ys = Foldable.foldr cons ys xs+    | otherwise         = Foldable.foldl snoc xs ys+  {-# INLINE (<>) #-}++instance Monoid (Deque a) where+  mempty = BD 0 [] 0 []+  {-# INLINE mempty #-}+  mappend xs ys+    | size xs < size ys = Foldable.foldr cons ys xs+    | otherwise         = Foldable.foldl snoc xs ys+  {-# INLINE mappend #-}++-- | Check that a 'Deque' satisfies the balance invariants and rebalance if not.+check :: Int -> [a] -> Int -> [a] -> Deque a+check lf f lr r+  | lf > 3*lr + 1, i <- div (lf + lr) 2, (f',f'') <- splitAt i f = BD i f' (lf + lr - i) (r ++ reverse f'')+  | lr > 3*lf + 1, j <- div (lf + lr) 2, (r',r'') <- splitAt j r = BD (lf + lr - j) (f ++ reverse r'') j r'+  | otherwise = BD lf f lr r+{-# INLINE check #-}++instance (Choice p, Applicative f) => Cons p f (Deque a) (Deque b) a b where+  _Cons = prism (\(x,BD lf f lr r) -> check (lf + 1) (x : f) lr r) $ \ (BD lf f lr r) ->+    if lf + lr == 0+    then Left empty+    else Right $ case f of+      []     -> (head r, empty)+      (x:xs) -> (x, check (lf - 1) xs lr r)+  {-# INLINE _Cons #-}++instance (Choice p, Applicative f) => Snoc p f (Deque a) (Deque b) a b where+  _Snoc = prism (\(BD lf f lr r,x) -> check lf f (lr + 1) (x : r)) $ \ (BD lf f lr r) ->+    if lf + lr == 0+    then Left empty+    else Right $ case r of+      []     -> (empty, head f)+      (x:xs) -> (check lf f (lr - 1) xs, x)+  {-# INLINE _Snoc #-}
+ src/Control/Lens/Internal/Fold.hs view
@@ -0,0 +1,203 @@+{-# LANGUAGE CPP #-}+#ifdef TRUSTWORTHY+{-# LANGUAGE Trustworthy #-}+#endif+-----------------------------------------------------------------------------+-- |+-- Module      :  Control.Lens.Internal.Fold+-- Copyright   :  (C) 2012-2013 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  experimental+-- Portability :  non-portable+--+----------------------------------------------------------------------------+module Control.Lens.Internal.Fold+  (+  -- * Monoids for folding+    Folding(..)+  , Traversed(..)+  , Sequenced(..)+  , Max(..), getMax+  , Min(..), getMin+  , Leftmost(..), getLeftmost+  , Rightmost(..), getRightmost+  ) where++import Control.Applicative+import Control.Lens.Internal.Getter+import Data.Maybe+import Data.Functor.Bind+import Data.Semigroup hiding (Min, getMin, Max, getMax)++------------------------------------------------------------------------------+-- Folding+------------------------------------------------------------------------------++-- | A 'Monoid' for a 'Gettable' 'Applicative'.+newtype Folding f a = Folding { getFolding :: f a }++instance (Gettable f, Apply f) => Semigroup (Folding f a) where+  Folding fr <> Folding fs = Folding (fr .> fs)+  {-# INLINE (<>) #-}++instance (Gettable f, Applicative f) => Monoid (Folding f a) where+  mempty = Folding noEffect+  {-# INLINE mempty #-}+  Folding fr `mappend` Folding fs = Folding (fr *> fs)+  {-# INLINE mappend #-}+++------------------------------------------------------------------------------+-- Traversed+------------------------------------------------------------------------------++-- | Used internally by 'Control.Lens.Traversal.traverseOf_' and the like.+--+-- The argument 'a' of the result should not be used!+newtype Traversed a f = Traversed { getTraversed :: f a }++instance Apply f => Semigroup (Traversed a f) where+  Traversed ma <> Traversed mb = Traversed (ma .> mb)+  {-# INLINE (<>) #-}++instance Applicative f => Monoid (Traversed a f) where+  mempty = Traversed (pure (error "Traversed: value used"))+  {-# INLINE mempty #-}+  Traversed ma `mappend` Traversed mb = Traversed (ma *> mb)+  {-# INLINE mappend #-}++------------------------------------------------------------------------------+-- Sequenced+------------------------------------------------------------------------------++-- | Used internally by 'Control.Lens.Traversal.mapM_' and the like.+--+-- The argument 'a' of the result should not be used!+newtype Sequenced a m = Sequenced { getSequenced :: m a }++instance Apply m => Semigroup (Sequenced a m) where+  Sequenced ma <> Sequenced mb = Sequenced (ma .> mb)+  {-# INLINE (<>) #-}++instance Monad m => Monoid (Sequenced a m) where+  mempty = Sequenced (return (error "Sequenced: value used"))+  {-# INLINE mempty #-}+  Sequenced ma `mappend` Sequenced mb = Sequenced (ma >> mb)+  {-# INLINE mappend #-}++------------------------------------------------------------------------------+-- Min+------------------------------------------------------------------------------++-- | Used for 'Control.Lens.Fold.minimumOf'.+data Min a = NoMin | Min a++instance Ord a => Semigroup (Min a) where+  NoMin <> m     = m+  m <> NoMin     = m+  Min a <> Min b = Min (min a b)+  {-# INLINE (<>) #-}++instance Ord a => Monoid (Min a) where+  mempty = NoMin+  {-# INLINE mempty #-}+  mappend NoMin m = m+  mappend m NoMin = m+  mappend (Min a) (Min b) = Min (min a b)+  {-# INLINE mappend #-}++-- | Obtain the minimum.+getMin :: Min a -> Maybe a+getMin NoMin   = Nothing+getMin (Min a) = Just a+{-# INLINE getMin #-}++------------------------------------------------------------------------------+-- Max+------------------------------------------------------------------------------++-- | Used for 'Control.Lens.Fold.maximumOf'.+data Max a = NoMax | Max a++instance Ord a => Semigroup (Max a) where+  NoMax <> m = m+  m <> NoMax = m+  Max a <> Max b = Max (max a b)+  {-# INLINE (<>) #-}++instance Ord a => Monoid (Max a) where+  mempty = NoMax+  {-# INLINE mempty #-}+  mappend NoMax m = m+  mappend m NoMax = m+  mappend (Max a) (Max b) = Max (max a b)+  {-# INLINE mappend #-}++-- | Obtain the maximum.+getMax :: Max a -> Maybe a+getMax NoMax   = Nothing+getMax (Max a) = Just a+{-# INLINE getMax #-}++------------------------------------------------------------------------------+-- Leftmost and Rightmost+------------------------------------------------------------------------------++-- | Used for 'Control.Lens.Fold.preview'.+data Leftmost a = LPure | LLeaf a | LStep (Leftmost a)++instance Semigroup (Leftmost a) where+  (<>) = mappend+  {-# INLINE (<>) #-}++instance Monoid (Leftmost a) where+  mempty = LPure+  {-# INLINE mempty #-}+  mappend x y = LStep $ case x of+    LPure    -> y+    LLeaf _  -> x+    LStep x' -> case y of+      -- The last two cases make firstOf produce a Just as soon as any element+      -- is encountered, and possibly serve as a micro-optimisation; this+      -- behaviour can be disabled by replacing them with _ -> mappend x y'.+      -- Note that this means that firstOf (backwards folded) [1..] is Just _|_.+      LPure    -> x'+      LLeaf a  -> LLeaf $ fromMaybe a (getLeftmost x')+      LStep y' -> mappend x' y'++-- | Extract the 'Leftmost' element. This will fairly eagerly determine that it can return 'Just'+-- the moment it sees any element at all.+getLeftmost :: Leftmost a -> Maybe a+getLeftmost LPure = Nothing+getLeftmost (LLeaf a) = Just a+getLeftmost (LStep x) = getLeftmost x++-- | Used for 'Control.Lens.Fold.lastOf'.+data Rightmost a = RPure | RLeaf a | RStep (Rightmost a)++instance Semigroup (Rightmost a) where+  (<>) = mappend+  {-# INLINE (<>) #-}++instance Monoid (Rightmost a) where+  mempty = RPure+  {-# INLINE mempty #-}+  mappend x y = RStep $ case y of+    RPure    -> x+    RLeaf _  -> y+    RStep y' -> case x of+      -- The last two cases make lastOf produce a Just as soon as any element+      -- is encountered, and possibly serve as a micro-optimisation; this+      -- behaviour can be disabled by replacing them with _ -> mappend x y'.+      -- Note that this means that lastOf folded [1..] is Just _|_.+      RPure    -> y'+      RLeaf a  -> RLeaf $ fromMaybe a (getRightmost y')+      RStep x' -> mappend x' y'++-- | Extract the 'Rightmost' element. This will fairly eagerly determine that it can return 'Just'+-- the moment it sees any element at all.+getRightmost :: Rightmost a -> Maybe a+getRightmost RPure = Nothing+getRightmost (RLeaf a) = Just a+getRightmost (RStep x) = getRightmost x
+ src/Control/Lens/Internal/Getter.hs view
@@ -0,0 +1,97 @@+{-# LANGUAGE CPP #-}+#ifdef TRUSTWORTHY+{-# LANGUAGE Trustworthy #-}+#endif+-----------------------------------------------------------------------------+-- |+-- Module      :  Control.Lens.Internal.Getter+-- Copyright   :  (C) 2012-2013 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  provisional+-- Portability :  non-portable+--+----------------------------------------------------------------------------+module Control.Lens.Internal.Getter+  (+  -- * Internal Classes+  -- ** Getters+    Gettable(..)+  , noEffect+  , Accessor(..)+  ) where++import Control.Applicative+import Control.Applicative.Backwards+import Data.Functor.Apply+import Data.Functor.Compose+import Data.Profunctor.Unsafe+import Data.Semigroup++-------------------------------------------------------------------------------+-- Gettables & Accessors+-------------------------------------------------------------------------------++-- | Generalizing 'Const' so we can apply simple 'Applicative'+-- transformations to it and so we can get nicer error messages.+--+-- A 'Gettable' 'Functor' ignores its argument, which it carries solely as a+-- phantom type parameter.+--+-- To ensure this, an instance of 'Gettable' is required to satisfy:+--+-- @'id' = 'fmap' f = 'coerce'@+--+-- Which is equivalent to making a @'Gettable' f@ an \"anyvariant\"+-- 'Functor'.++class Functor f => Gettable f where+  -- | Replace the phantom type argument.+  coerce :: f a -> f b++instance Gettable (Const r) where+  coerce (Const m) = Const m+  {-# INLINE coerce #-}++instance Gettable f => Gettable (Backwards f) where+  coerce = Backwards #. coerce .# forwards+  {-# INLINE coerce #-}++instance (Functor f, Gettable g) => Gettable (Compose f g) where+  coerce = Compose #. fmap coerce .# getCompose+  {-# INLINE coerce #-}++-- | The 'mempty' equivalent for a 'Gettable' 'Applicative' 'Functor'.+noEffect :: (Applicative f, Gettable f) => f a+noEffect = coerce $ pure ()+{-# INLINE noEffect #-}++-------------------------------------------------------------------------------+-- Accessors+-------------------------------------------------------------------------------++-- | Used instead of 'Const' to report+--+-- @No instance for ('Control.Lens.Setter.Internal.Settable' 'Accessor')@+--+-- when the user attempts to misuse a 'Control.Lens.Setter.Setter' as a+-- 'Control.Lens.Getter.Getter', rather than a monolithic unification error.+newtype Accessor r a = Accessor { runAccessor :: r }++instance Functor (Accessor r) where+  fmap _ (Accessor m) = Accessor m+  {-# INLINE fmap #-}++instance Semigroup r => Apply (Accessor r) where+  Accessor a <.> Accessor b = Accessor (a <> b)+  {-# INLINE (<.>) #-}++instance Monoid r => Applicative (Accessor r) where+  pure _ = Accessor mempty+  {-# INLINE pure #-}+  Accessor a <*> Accessor b = Accessor (mappend a b)+  {-# INLINE (<*>) #-}++instance Gettable (Accessor r) where+  coerce (Accessor m) = Accessor m+  {-# INLINE coerce #-}
+ src/Control/Lens/Internal/Indexed.hs view
@@ -0,0 +1,319 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE Rank2Types #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+#ifdef TRUSTWORTHY+{-# LANGUAGE Trustworthy #-}+#endif+-----------------------------------------------------------------------------+-- |+-- Module      :  Control.Lens.Internal.Indexed+-- Copyright   :  (C) 2012-2013 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  experimental+-- Portability :  non-portable+--+-- Internal implementation details for 'Indexed' lens-likes+----------------------------------------------------------------------------+module Control.Lens.Internal.Indexed+  (+  -- * An Indexed Profunctor+    Indexed(..)+  -- * Classes+  , Conjoined(..)+  , Indexable(..)+  -- * Indexing+  , Indexing(..)+  , indexing+  -- * 64-bit Indexing+  , Indexing64(..)+  , indexing64+  ) where++import Control.Applicative+import Control.Arrow as Arrow+import Control.Category+import Control.Comonad+import Control.Lens.Internal.Getter+import Control.Lens.Internal.Instances ()+import Control.Monad+import Control.Monad.Fix+import Data.Distributive+import Data.Functor.Bind+import Data.Int+import Data.Profunctor+import Data.Profunctor.Rep+import Data.Profunctor.Unsafe+import Data.Traversable+import Prelude hiding ((.),id)+#ifndef SAFE+import Unsafe.Coerce+#endif++------------------------------------------------------------------------------+-- Conjoined+------------------------------------------------------------------------------++-- | This is a 'Profunctor' that is both 'Corepresentable' by @f@ and 'Representable' by @g@ such+-- that @f@ is left adjoint to @g@. From this you can derive a lot of structure due+-- to the preservation of limits and colimits.+class+  ( Profunctor p, Choice p, Strong p+  , Corepresentable p, Comonad (Corep p), Traversable (Corep p)+  , Representable p, Monad (Rep p), MonadFix (Rep p), Distributive (Rep p)+  , ArrowLoop p, ArrowApply p, ArrowChoice p+  ) => Conjoined p where++  -- | 'Conjoined' is strong enough to let us distribute every 'Conjoined'+  -- 'Profunctor' over every Haskell 'Functor'. This is effectively a+  -- generalization of 'fmap'.+  distrib :: Functor f => p a b -> p (f a) (f b)+  distrib = tabulate . collect . rep+  {-# INLINE distrib #-}++  -- | This permits us to make a decision at an outermost point about whether or not we use an index.+  --+  -- Ideally any use of this function should be done in such a way so that you compute the same answer,+  -- but this cannot be enforced at the type level.+  conjoined :: ((p ~ (->)) => q (a -> b) r) -> q (p a b) r -> q (p a b) r+  conjoined _ r = r+  {-# INLINE conjoined #-}++instance Conjoined (->) where+  distrib = fmap+  {-# INLINE distrib #-}+  conjoined l _ = l+  {-# INLINE conjoined #-}++----------------------------------------------------------------------------+-- Indexable+----------------------------------------------------------------------------++-- | This class permits overloading of function application for things that+-- also admit a notion of a key or index.+class Conjoined p => Indexable i p where+  -- | Build a function from an 'indexed' function.+  indexed :: p a b -> i -> a -> b++instance Indexable i (->) where+  indexed = const+  {-# INLINE indexed #-}++-----------------------------------------------------------------------------+-- Indexed Internals+-----------------------------------------------------------------------------++-- | A function with access to a index. This constructor may be useful when you need to store+-- an 'Indexable' in a container to avoid @ImpredicativeTypes@.+--+-- @index :: Indexed i a b -> i -> a -> b@+newtype Indexed i a b = Indexed { runIndexed :: i -> a -> b }++instance Functor (Indexed i a) where+  fmap g (Indexed f) = Indexed $ \i a -> g (f i a)+  {-# INLINE fmap #-}++instance Apply (Indexed i a) where+  Indexed f <.> Indexed g = Indexed $ \i a -> f i a (g i a)+  {-# INLINE (<.>) #-}++instance Applicative (Indexed i a) where+  pure b = Indexed $ \_ _ -> b+  {-# INLINE pure #-}+  Indexed f <*> Indexed g = Indexed $ \i a -> f i a (g i a)+  {-# INLINE (<*>) #-}++instance Bind (Indexed i a) where+  Indexed f >>- k = Indexed $ \i a -> runIndexed (k (f i a)) i a+  {-# INLINE (>>-) #-}++instance Monad (Indexed i a) where+  return b = Indexed $ \_ _ -> b+  {-# INLINE return #-}+  Indexed f >>= k = Indexed $ \i a -> runIndexed (k (f i a)) i a+  {-# INLINE (>>=) #-}++instance MonadFix (Indexed i a) where+  mfix f = Indexed $ \ i a -> let o = runIndexed (f o) i a in o+  {-# INLINE mfix #-}++instance Profunctor (Indexed i) where+  dimap ab cd ibc = Indexed $ \i -> cd . runIndexed ibc i . ab+  {-# INLINE dimap #-}+  lmap ab ibc = Indexed $ \i -> runIndexed ibc i . ab+  {-# INLINE lmap #-}+  rmap bc iab = Indexed $ \i -> bc . runIndexed iab i+  {-# INLINE rmap #-}+  ( .# ) ibc _ = unsafeCoerce ibc+  {-# INLINE ( .# ) #-}+  ( #. ) _ = unsafeCoerce+  {-# INLINE ( #. ) #-}++instance Corepresentable (Indexed i) where+  type Corep (Indexed i) = (,) i+  cotabulate = Indexed . curry+  {-# INLINE cotabulate #-}+  corep = uncurry . runIndexed+  {-# INLINE corep #-}++instance Representable (Indexed i) where+  type Rep (Indexed i) = (->) i+  tabulate = Indexed . flip+  {-# INLINE tabulate #-}+  rep = flip . runIndexed+  {-# INLINE rep #-}++instance Choice (Indexed i) where+  right' = right+  {-# INLINE right' #-}++instance Strong (Indexed i) where+  second' = second+  {-# INLINE second' #-}++instance Category (Indexed i) where+  id = Indexed (const id)+  {-# INLINE id #-}+  Indexed f . Indexed g = Indexed $ \i -> f i . g i+  {-# INLINE (.) #-}++instance Arrow (Indexed i) where+  arr f = Indexed (\_ -> f)+  {-# INLINE arr #-}+  first f = Indexed (Arrow.first . runIndexed f)+  {-# INLINE first #-}+  second f = Indexed (Arrow.second . runIndexed f)+  {-# INLINE second #-}+  Indexed f *** Indexed g = Indexed $ \i -> f i *** g i+  {-# INLINE (***) #-}+  Indexed f &&& Indexed g = Indexed $ \i -> f i &&& g i+  {-# INLINE (&&&) #-}++instance ArrowChoice (Indexed i) where+  left f = Indexed (left . runIndexed f)+  {-# INLINE left #-}+  right f = Indexed (right . runIndexed f)+  {-# INLINE right #-}+  Indexed f +++ Indexed g = Indexed $ \i -> f i +++ g i+  {-# INLINE (+++)  #-}+  Indexed f ||| Indexed g = Indexed $ \i -> f i ||| g i+  {-# INLINE (|||) #-}++instance ArrowApply (Indexed i) where+  app = Indexed $ \ i (f, b) -> runIndexed f i b+  {-# INLINE app #-}++instance ArrowLoop (Indexed i) where+  loop (Indexed f) = Indexed $ \i b -> let (c,d) = f i (b, d) in c+  {-# INLINE loop #-}++instance Conjoined (Indexed i) where+  distrib (Indexed iab) = Indexed $ \i fa -> iab i <$> fa+  {-# INLINE distrib #-}++instance i ~ j => Indexable i (Indexed j) where+  indexed = runIndexed+  {-# INLINE indexed #-}++------------------------------------------------------------------------------+-- Indexing+------------------------------------------------------------------------------++-- | 'Applicative' composition of @'Control.Monad.Trans.State.Lazy.State' 'Int'@ with a 'Functor', used+-- by 'Control.Lens.Indexed.indexed'.+newtype Indexing f a = Indexing { runIndexing :: Int -> (Int, f a) }++instance Functor f => Functor (Indexing f) where+  fmap f (Indexing m) = Indexing $ \i -> case m i of+    (j, x) -> (j, fmap f x)+  {-# INLINE fmap #-}++instance Apply f => Apply (Indexing f) where+  Indexing mf <.> Indexing ma = Indexing $ \i -> case mf i of+    (j, ff) -> case ma j of+       ~(k, fa) -> (k, ff <.> fa)+  {-# INLINE (<.>) #-}++instance Applicative f => Applicative (Indexing f) where+  pure x = Indexing $ \i -> (i, pure x)+  {-# INLINE pure #-}+  Indexing mf <*> Indexing ma = Indexing $ \i -> case mf i of+    (j, ff) -> case ma j of+       ~(k, fa) -> (k, ff <*> fa)+  {-# INLINE (<*>) #-}++instance Gettable f => Gettable (Indexing f) where+  coerce (Indexing m) = Indexing $ \i -> case m i of+    (j, ff) -> (j, coerce ff)+  {-# INLINE coerce #-}++-- | Transform a 'Control.Lens.Traversal.Traversal' into an 'Control.Lens.Traversal.IndexedTraversal' or+-- a 'Control.Lens.Fold.Fold' into an 'Control.Lens.Fold.IndexedFold', etc.+--+-- @+-- 'indexing' :: 'Control.Lens.Type.Traversal' s t a b -> 'Control.Lens.Type.IndexedTraversal' 'Int' s t a b+-- 'indexing' :: 'Control.Lens.Type.Prism' s t a b     -> 'Control.Lens.Type.IndexedTraversal' 'Int' s t a b+-- 'indexing' :: 'Control.Lens.Type.Lens' s t a b      -> 'Control.Lens.Type.IndexedLens' 'Int'  s t a b+-- 'indexing' :: 'Control.Lens.Type.Iso' s t a b       -> 'Control.Lens.Type.IndexedLens' 'Int' s t a b+-- 'indexing' :: 'Control.Lens.Type.Fold' s a          -> 'Control.Lens.Type.IndexedFold' 'Int' s a+-- 'indexing' :: 'Control.Lens.Type.Getter' s a        -> 'Control.Lens.Type.IndexedGetter' 'Int' s a+-- @+--+-- @'indexing' :: 'Indexable' 'Int' p => 'Control.Lens.Type.LensLike' ('Indexing' f) s t a b -> 'Control.Lens.Type.Overloading' p (->) f s t a b@+indexing :: Indexable Int p => ((a -> Indexing f b) -> s -> Indexing f t) -> p a (f b) -> s -> f t+indexing l iafb s = snd $ runIndexing (l (\a -> Indexing (\i -> i `seq` (i + 1, indexed iafb i a))) s) 0+{-# INLINE indexing #-}++------------------------------------------------------------------------------+-- Indexing64+------------------------------------------------------------------------------++-- | 'Applicative' composition of @'Control.Monad.Trans.State.Lazy.State' 'Int64'@ with a 'Functor', used+-- by 'Control.Lens.Indexed.indexed64'.+newtype Indexing64 f a = Indexing64 { runIndexing64 :: Int64 -> (Int64, f a) }++instance Functor f => Functor (Indexing64 f) where+  fmap f (Indexing64 m) = Indexing64 $ \i -> case m i of+    (j, x) -> (j, fmap f x)+  {-# INLINE fmap #-}++instance Apply f => Apply (Indexing64 f) where+  Indexing64 mf <.> Indexing64 ma = Indexing64 $ \i -> case mf i of+    (j, ff) -> case ma j of+       ~(k, fa) -> (k, ff <.> fa)+  {-# INLINE (<.>) #-}++instance Applicative f => Applicative (Indexing64 f) where+  pure x = Indexing64 $ \i -> (i, pure x)+  {-# INLINE pure #-}+  Indexing64 mf <*> Indexing64 ma = Indexing64 $ \i -> case mf i of+    (j, ff) -> case ma j of+       ~(k, fa) -> (k, ff <*> fa)+  {-# INLINE (<*>) #-}++instance Gettable f => Gettable (Indexing64 f) where+  coerce (Indexing64 m) = Indexing64 $ \i -> case m i of+    (j, ff) -> (j, coerce ff)+  {-# INLINE coerce #-}++-- | Transform a 'Control.Lens.Traversal.Traversal' into an 'Control.Lens.Traversal.IndexedTraversal' or+-- a 'Control.Lens.Fold.Fold' into an 'Control.Lens.Fold.IndexedFold', etc.+--+-- This combinator is like 'indexing' except that it handles large traversals and folds gracefully.+--+-- @+-- 'indexing64' :: 'Control.Lens.Type.Traversal' s t a b -> 'Control.Lens.Type.IndexedTraversal' 'Int64' s t a b+-- 'indexing64' :: 'Control.Lens.Type.Prism' s t a b     -> 'Control.Lens.Type.IndexedTraversal' 'Int64' s t a b+-- 'indexing64' :: 'Control.Lens.Type.Lens' s t a b      -> 'Control.Lens.Type.IndexedLens' 'Int64' s t a b+-- 'indexing64' :: 'Control.Lens.Type.Iso' s t a b       -> 'Control.Lens.Type.IndexedLens' 'Int64' s t a b+-- 'indexing64' :: 'Control.Lens.Type.Fold' s a          -> 'Control.Lens.Type.IndexedFold' 'Int64' s a+-- 'indexing64' :: 'Control.Lens.Type.Getter' s a        -> 'Control.Lens.Type.IndexedGetter' 'Int64' s a+-- @+--+-- @'indexing64' :: 'Indexable' 'Int64' p => 'Control.Lens.Type.LensLike' ('Indexing64' f) s t a b -> 'Control.Lens.Type.Overloading' p (->) f s t a b@+indexing64 :: Indexable Int64 p => ((a -> Indexing64 f b) -> s -> Indexing64 f t) -> p a (f b) -> s -> f t+indexing64 l iafb s = snd $ runIndexing64 (l (\a -> Indexing64 (\i -> i `seq` (i + 1, indexed iafb i a))) s) 0+{-# INLINE indexing64 #-}
+ src/Control/Lens/Internal/Instances.hs view
@@ -0,0 +1,51 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}+-----------------------------------------------------------------------------+-- |+-- Module      :  Control.Lens.Internal.Instances+-- Copyright   :  (C) 2012-2013 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  experimental+-- Portability :  non-portable+--+-- This module includes orphan instances for @(,)@, 'Either' and 'Const' that+-- should be supplied by base.+----------------------------------------------------------------------------+module Control.Lens.Internal.Instances () where++import Control.Applicative+import Data.Foldable+import Data.Monoid+import Data.Semigroup.Foldable+import Data.Semigroup.Traversable+import Data.Traversable++-------------------------------------------------------------------------------+-- Orphan Instances+-------------------------------------------------------------------------------++instance Foldable ((,) b) where+  foldMap f (_, a) = f a++instance Foldable1 ((,) b) where+  foldMap1 f (_, a) = f a++instance Traversable ((,) b) where+  traverse f (b, a) = (,) b <$> f a++instance Traversable1 ((,) b) where+  traverse1 f (b, a) = (,) b <$> f a++instance Foldable (Either a) where+  foldMap _ (Left _) = mempty+  foldMap f (Right a) = f a++instance Traversable (Either a) where+  traverse _ (Left b) = pure (Left b)+  traverse f (Right a) = Right <$> f a++instance Foldable (Const m) where+  foldMap _ _ = mempty++instance Traversable (Const m) where+  traverse _ (Const m) = pure $ Const m
+ src/Control/Lens/Internal/Iso.hs view
@@ -0,0 +1,47 @@+{-# LANGUAGE CPP #-}+#ifdef TRUSTWORTHY+{-# LANGUAGE Trustworthy #-}+#endif+-----------------------------------------------------------------------------+-- |+-- Module      :  Control.Lens.Internal.Iso+-- Copyright   :  (C) 2012-2013 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  experimental+-- Portability :  non-portable+--+----------------------------------------------------------------------------+module Control.Lens.Internal.Iso+  ( Exchange(..)+  ) where++import Data.Profunctor+import Data.Profunctor.Unsafe+#ifndef SAFE+import Unsafe.Coerce+#endif++------------------------------------------------------------------------------+-- Isomorphism: Exchange+------------------------------------------------------------------------------++-- | This is used internally by the 'Control.Lens.Iso.Iso' code to provide+-- efficient access to the two functions that make up an isomorphism.+data Exchange a b s t = Exchange (s -> a) (b -> t)++instance Functor (Exchange a b s) where+  fmap f (Exchange sa bt) = Exchange sa (f . bt)+  {-# INLINE fmap #-}++instance Profunctor (Exchange a b) where+  dimap f g (Exchange sa bt) = Exchange (sa . f) (g . bt)+  {-# INLINE dimap #-}+  lmap f (Exchange sa bt) = Exchange (sa . f) bt+  {-# INLINE lmap #-}+  rmap f (Exchange sa bt) = Exchange sa (f . bt)+  {-# INLINE rmap #-}+  ( #. ) _ = unsafeCoerce+  {-# INLINE ( #. ) #-}+  ( .# ) p _ = unsafeCoerce p+  {-# INLINE ( .# ) #-}
+ src/Control/Lens/Internal/Level.hs view
@@ -0,0 +1,167 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE GADTs #-}+{-# LANGUAGE Rank2Types #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE UndecidableInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FunctionalDependencies #-}+#ifdef TRUSTWORTHY+{-# LANGUAGE Trustworthy #-}+#endif+-----------------------------------------------------------------------------+-- |+-- Module      :  Control.Lens.Internal.Level+-- Copyright   :  (C) 2012-2013 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  experimental+-- Portability :  non-portable+--+-- This module provides implementation details of the combinators in+-- "Control.Lens.Level", which provides for the breadth-first 'Control.Lens.Traversal.Traversal' of+-- an arbitrary 'Control.Lens.Traversal.Traversal'.+----------------------------------------------------------------------------+module Control.Lens.Internal.Level+  (+  -- * Levels+    Level(..)+  , Deepening(..), deepening+  , Flows(..)+  ) where++import Control.Applicative+import Control.Category+import Control.Comonad+import Data.Foldable+import Data.Functor.Apply+import Data.Int+import Data.Semigroup+import Data.Traversable+import Data.Word+import Prelude hiding ((.),id)++------------------------------------------------------------------------------+-- Levels+------------------------------------------------------------------------------++-- | This data type represents a path-compressed copy of one level of a source+-- data structure. We can safely use path-compression because we know the depth+-- of the tree.+--+-- Path compression is performed by viewing a 'Level' as a PATRICIA trie of the+-- paths into the structure to leaves at a given depth, similar in many ways+-- to a 'Data.IntMap.IntMap', but unlike a regular PATRICIA trie we do not need+-- to store the mask bits merely the depth of the fork.+--+-- One invariant of this structure is that underneath a 'Two' node you will not+-- find any 'Zero' nodes, so 'Zero' can only occur at the root.+data Level i a+  = Two {-# UNPACK #-} !Word !(Level i a) !(Level i a)+  | One i a+  | Zero+  deriving (Eq,Ord,Show,Read)++-- | Append a pair of 'Level' values to get a new 'Level' with path compression.+--+-- As the 'Level' type is user-visible, we do not expose this as an illegal+-- 'Semigroup' instance, and just use it directly in 'Deepening' as needed.+lappend :: Level i a -> Level i a -> Level i a+lappend Zero        Zero        = Zero+lappend Zero        r@One{}     = r+lappend l@One{}     Zero        = l+lappend Zero        (Two n l r) = Two (n + 1) l r+lappend (Two n l r) Zero        = Two (n + 1) l r+lappend l           r           = Two 0 l r+{-# INLINE lappend #-}++instance Functor (Level i) where+  fmap f = go where+    go (Two n l r) = Two n (go l) (go r)+    go (One i a)   = One i (f a)+    go Zero        = Zero+  {-# INLINE fmap #-}++instance Foldable (Level i) where+  foldMap f = go where+    go (Two _ l r) = go l `mappend` go r+    go (One _ a) = f a+    go Zero = mempty+  {-# INLINE foldMap #-}++instance Traversable (Level i) where+  traverse f = go where+    go (Two n l r) = Two n <$> go l <*> go r+    go (One i a) = One i <$> f a+    go Zero = pure Zero+  {-# INLINE traverse #-}++------------------------------------------------------------------------------+-- Generating Levels+------------------------------------------------------------------------------++-- | This is an illegal 'Monoid' used to construct a single 'Level'.+newtype Deepening i a = Deepening { runDeepening :: forall r. Int -> (Level i a -> Bool -> r) -> r }++instance Semigroup (Deepening i a) where+  Deepening l <> Deepening r = Deepening $ \ n k -> case n of+    0 -> k Zero True+    _ -> let n' = n - 1 in l n' $ \x a -> r n' $ \y b -> k (lappend x y) (a || b)+  {-# INLINE (<>) #-}++-- | This is an illegal 'Monoid'.+instance Monoid (Deepening i a) where+  mempty = Deepening $ \ _ k -> k Zero False+  {-# INLINE mempty #-}+  mappend (Deepening l) (Deepening r) = Deepening $ \ n k -> case n of+    0 -> k Zero True+    _ -> let n' = n - 1 in l n' $ \x a -> r n' $ \y b -> k (lappend x y) (a || b)+  {-# INLINE mappend #-}++-- | Generate the leaf of a given 'Deepening' based on whether or not we're at the correct depth.+deepening :: i -> a -> Deepening i a+deepening i a = Deepening $ \n k -> k (if n == 0 then One i a else Zero) False+{-# INLINE deepening #-}++------------------------------------------------------------------------------+-- Reassembling Levels+------------------------------------------------------------------------------++-- | This is an illegal 'Applicative' used to replace the contents of a list of consecutive 'Level' values+-- representing each layer of a structure into the original shape that they were derived from.+--+-- Attempting to 'Flow' something back into a shape other than the one it was taken from will fail.+newtype Flows i b a = Flows { runFlows :: [Level i b] -> a }++instance Functor (Flows i b) where+  fmap f (Flows g) = Flows (f . g)+  {-# INLINE fmap #-}++-- | Walk down one constructor in a 'Level', veering left.+triml :: Level i b -> Level i b+triml (Two 0 l _) = l+triml (Two n l r) = Two (n - 1) l r+triml x           = x+{-# INLINE triml #-}++-- | Walk down one constructor in a 'Level', veering right.+trimr :: Level i b -> Level i b+trimr (Two 0 _ r) = r+trimr (Two n l r) = Two (n - 1) l r+trimr x           = x+{-# INLINE trimr #-}++instance Apply (Flows i b) where+  Flows mf <.> Flows ma = Flows $ \ xss -> case xss of+    []             -> mf [] (ma [])+    (_:xs)         -> mf (triml <$> xs) $ ma (trimr <$> xs)+  {-# INLINE (<.>) #-}++-- | This is an illegal 'Applicative'.+instance Applicative (Flows i b) where+  pure a = Flows (const a)+  {-# INLINE pure #-}+  Flows mf <*> Flows ma = Flows $ \ xss -> case xss of+    []             -> mf [] (ma [])+    (_:xs)         -> mf (triml <$> xs) $ ma (trimr <$> xs)+  {-# INLINE (<*>) #-}
+ src/Control/Lens/Internal/Magma.hs view
@@ -0,0 +1,247 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE GADTs #-}+{-# LANGUAGE Rank2Types #-}+{-# LANGUAGE KindSignatures #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE UndecidableInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FunctionalDependencies #-}+#ifdef TRUSTWORTHY+{-# LANGUAGE Trustworthy #-}+#endif+-----------------------------------------------------------------------------+-- |+-- Module      :  Control.Lens.Internal.Magma+-- Copyright   :  (C) 2012-2013 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  experimental+-- Portability :  non-portable+--+----------------------------------------------------------------------------+module Control.Lens.Internal.Magma+  (+  -- * Magma+    Magma(..)+  , runMagma+  -- * Molten+  , Molten(..)+  -- * Mafic+  , Mafic(..)+  , runMafic+  -- * TakingWhile+  , TakingWhile(..)+  , runTakingWhile+  ) where++import Control.Applicative+import Control.Category+import Control.Comonad+import Control.Lens.Internal.Bazaar+import Control.Lens.Internal.Context+import Control.Lens.Internal.Getter+import Control.Lens.Internal.Indexed+import Data.Foldable+import Data.Functor.Apply+import Data.Monoid+import Data.Profunctor.Rep+import Data.Profunctor.Unsafe+import Data.Traversable+import Prelude hiding ((.),id)++------------------------------------------------------------------------------+-- Magma+------------------------------------------------------------------------------++-- | This provides a way to peek at the internal structure of a+-- 'Control.Lens.Traversal.Traversal' or 'Control.Lens.Traversal.IndexedTraversal'+data Magma i t b a where+  MagmaAp   :: Magma i (x -> y) b a -> Magma i x b a -> Magma i y b a+  MagmaPure :: x -> Magma i x b a+  MagmaFmap :: (x -> y) -> Magma i x b a -> Magma i y b a+  Magma :: i -> a -> Magma i b b a++instance Functor (Magma i t b) where+  fmap f (MagmaAp x y)    = MagmaAp (fmap f x) (fmap f y)+  fmap _ (MagmaPure x)    = MagmaPure x+  fmap f (MagmaFmap xy x) = MagmaFmap xy (fmap f x)+  fmap f (Magma i a)  = Magma i (f a)++instance Foldable (Magma i t b) where+  foldMap f (MagmaAp x y)   = foldMap f x `mappend` foldMap f y+  foldMap _ MagmaPure{}     = mempty+  foldMap f (MagmaFmap _ x) = foldMap f x+  foldMap f (Magma _ a) = f a++instance Traversable (Magma i t b) where+  traverse f (MagmaAp x y)    = MagmaAp <$> traverse f x <*> traverse f y+  traverse _ (MagmaPure x)    = pure (MagmaPure x)+  traverse f (MagmaFmap xy x) = MagmaFmap xy <$> traverse f x+  traverse f (Magma i a)  = Magma i <$> f a++instance (Show i, Show a) => Show (Magma i t b a) where+  showsPrec d (MagmaAp x y) = showParen (d > 4) $+    showsPrec 4 x . showString " <*> " . showsPrec 5 y+  showsPrec d (MagmaPure _) = showParen (d > 10) $+    showString "pure .."+  showsPrec d (MagmaFmap _ x) = showParen (d > 4) $+    showString ".. <$> " . showsPrec 5 x+  showsPrec d (Magma i a) = showParen (d > 10) $+    showString "Magma " . showsPrec 11 i . showChar ' ' . showsPrec 11 a++-- | Run a 'Magma' where all the individual leaves have been converted to the+-- expected type+runMagma :: Magma i t a a -> t+runMagma (MagmaAp l r)   = runMagma l (runMagma r)+runMagma (MagmaFmap f r) = f (runMagma r)+runMagma (MagmaPure x)   = x+runMagma (Magma _ a) = a++------------------------------------------------------------------------------+-- Molten+------------------------------------------------------------------------------++-- | This is a a non-reassociating initially encoded version of 'Bazaar'.+newtype Molten i a b t = Molten { runMolten :: Magma i t b a }++instance Functor (Molten i a b) where+  fmap f (Molten xs) = Molten (MagmaFmap f xs)+  {-# INLINE fmap #-}++instance Apply (Molten i a b) where+  (<.>) = (<*>)+  {-# INLINE (<.>) #-}++instance Applicative (Molten i a b) where+  pure  = Molten #. MagmaPure+  {-# INLINE pure #-}+  Molten xs <*> Molten ys = Molten (MagmaAp xs ys)+  {-# INLINE (<*>) #-}++instance Sellable (Indexed i) (Molten i) where+  sell = Indexed (\i -> Molten #. Magma i)+  {-# INLINE sell #-}++instance Bizarre (Indexed i) (Molten i) where+  bazaar f (Molten (MagmaAp x y))   = bazaar f (Molten x) <*> bazaar f (Molten y)+  bazaar f (Molten (MagmaFmap g x)) = g <$> bazaar f (Molten x)+  bazaar _ (Molten (MagmaPure x))   = pure x+  bazaar f (Molten (Magma i a)) = indexed f i a++instance IndexedFunctor (Molten i) where+  ifmap f (Molten xs) = Molten (MagmaFmap f xs)+  {-# INLINE ifmap #-}++instance IndexedComonad (Molten i) where+  iextract (Molten (MagmaAp x y))   = iextract (Molten x) (iextract (Molten y))+  iextract (Molten (MagmaFmap f y)) = f (iextract (Molten y))+  iextract (Molten (MagmaPure x))   = x+  iextract (Molten (Magma _ a)) = a++  iduplicate (Molten (Magma i a)) = Molten #. Magma i <$> Molten (Magma i a)+  iduplicate (Molten (MagmaPure x))   = pure (pure x)+  iduplicate (Molten (MagmaFmap f y)) = iextend (fmap f) (Molten y)+  iduplicate (Molten (MagmaAp x y))   = iextend (<*>) (Molten x) <*> iduplicate (Molten y)++  iextend k (Molten (Magma i a)) = (k .# Molten) . Magma i <$> Molten (Magma i a)+  iextend k (Molten (MagmaPure x))   = pure (k (pure x))+  iextend k (Molten (MagmaFmap f y)) = iextend (k . fmap f) (Molten y)+  iextend k (Molten (MagmaAp x y))   = iextend (\x' y' -> k $ x' <*> y') (Molten x) <*> iduplicate (Molten y)++instance a ~ b => Comonad (Molten i a b) where+  extract   = iextract+  {-# INLINE extract #-}+  extend    = iextend+  {-# INLINE extend #-}+  duplicate = iduplicate+  {-# INLINE duplicate #-}++------------------------------------------------------------------------------+-- Mafic+------------------------------------------------------------------------------++-- | This is used to generate an indexed magma from an unindexed source+--+-- By constructing it this way we avoid infinite reassociations in sums where possible.+data Mafic a b t = Mafic Int (Int -> Magma Int t b a)++-- | Generate a 'Magma' using from a prefix sum.+runMafic :: Mafic a b t -> Magma Int t b a+runMafic (Mafic _ k) = k 0++instance Functor (Mafic a b) where+  fmap f (Mafic w k) = Mafic w (MagmaFmap f . k)+  {-# INLINE fmap #-}++instance Apply (Mafic a b) where+  Mafic wf mf <.> ~(Mafic wa ma) = Mafic (wf + wa) $ \o -> MagmaAp (mf o) (ma (o + wf))+  {-# INLINE (<.>) #-}++instance Applicative (Mafic a b) where+  pure a = Mafic 0 $ \_ -> MagmaPure a+  {-# INLINE pure #-}+  Mafic wf mf <*> ~(Mafic wa ma) = Mafic (wf + wa) $ \o -> MagmaAp (mf o) (ma (o + wf))+  {-# INLINE (<*>) #-}++instance Sellable (->) Mafic where+  sell a = Mafic 1 $ \ i -> Magma i a+  {-# INLINE sell #-}++instance Bizarre (Indexed Int) Mafic where+  bazaar (pafb :: Indexed Int a (f b)) (Mafic _ k) = go (k 0) where+    go :: Applicative f => Magma Int t b a -> f t+    go (MagmaAp x y)   = go x <*> go y+    go (MagmaFmap f x) = f <$> go x+    go (MagmaPure x)   = pure x+    go (Magma i a) = indexed pafb (i :: Int) a+  {-# INLINE bazaar #-}++instance IndexedFunctor Mafic where+  ifmap f (Mafic w k) = Mafic w (MagmaFmap f . k)+  {-# INLINE ifmap #-}++------------------------------------------------------------------------------+-- TakingWhile+------------------------------------------------------------------------------++-- | This is used to generate an indexed magma from an unindexed source+--+-- By constructing it this way we avoid infinite reassociations where possible.+data TakingWhile p (g :: * -> *) a b t = TakingWhile Bool t (Bool -> Magma () t b (Corep p a))++-- | Generate a 'Magma' with leaves only while the predicate holds from left to right.+runTakingWhile :: Corepresentable p => TakingWhile p f a b t -> Magma () t b (Corep p a)+runTakingWhile (TakingWhile _ _ k) = k True++instance Functor (TakingWhile p f a b) where+  fmap f (TakingWhile w t k) = let ft = f t in TakingWhile w ft $ \b -> if b then MagmaFmap f (k b) else MagmaPure ft+  {-# INLINE fmap #-}++instance Apply (TakingWhile p f a b) where+  TakingWhile wf tf mf <.> ~(TakingWhile wa ta ma) = TakingWhile (wf && wa) (tf ta) $ \o ->+    if o then MagmaAp (mf True) (ma wf) else MagmaPure (tf ta)+  {-# INLINE (<.>) #-}++instance Applicative (TakingWhile p f a b) where+  pure a = TakingWhile True a $ \_ -> MagmaPure a+  {-# INLINE pure #-}+  TakingWhile wf tf mf <*> ~(TakingWhile wa ta ma) = TakingWhile (wf && wa) (tf ta) $ \o ->+    if o then MagmaAp (mf True) (ma wf) else MagmaPure (tf ta)+  {-# INLINE (<*>) #-}++instance Corepresentable p => Bizarre p (TakingWhile p g) where+  bazaar (pafb :: p a (f b)) ~(TakingWhile _ _ k) = go (k True) where+    go :: Applicative f => Magma () t b (Corep p a) -> f t+    go (MagmaAp x y)  = go x <*> go y+    go (MagmaFmap f x)  = f <$> go x+    go (MagmaPure x)    = pure x+    go (Magma _ wa) = corep pafb wa+  {-# INLINE bazaar #-}++instance Gettable f => Gettable (TakingWhile p f a b) where+  coerce = (<$) (error "coerced TakingWhile")++instance IndexedFunctor (TakingWhile p f) where+  ifmap = fmap+  {-# INLINE ifmap #-}
+ src/Control/Lens/Internal/Prism.hs view
@@ -0,0 +1,65 @@+{-# LANGUAGE CPP #-}+#ifdef TRUSTWORTHY+{-# LANGUAGE Trustworthy #-}+#endif+-----------------------------------------------------------------------------+-- |+-- Module      :  Control.Lens.Internal.Prism+-- Copyright   :  (C) 2012-2013 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  experimental+-- Portability :  non-portable+--+----------------------------------------------------------------------------+module Control.Lens.Internal.Prism+  ( Market(..)+  , Market'+  ) where++import Data.Profunctor+import Data.Profunctor.Unsafe+#ifndef SAFE+import Unsafe.Coerce+#endif++------------------------------------------------------------------------------+-- Prism: Market+------------------------------------------------------------------------------++-- | This type is used internally by the 'Control.Lens.Prism.Prism' code to+-- provide efficient access to the two parts of a 'Prism'.+data Market a b s t = Market (b -> t) (s -> Either t a)++-- | @type 'Market'' a s t = 'Market' a a s t@+type Market' a = Market a a++instance Functor (Market a b s) where+  fmap f (Market bt seta) = Market (f . bt) (either (Left . f) Right . seta)+  {-# INLINE fmap #-}++instance Profunctor (Market a b) where+  dimap f g (Market bt seta) = Market (g . bt) (either (Left . g) Right . seta . f)+  {-# INLINE dimap #-}+  lmap f (Market bt seta) = Market bt (seta . f)+  {-# INLINE lmap #-}+  rmap f (Market bt seta) = Market (f . bt) (either (Left . f) Right . seta)+  {-# INLINE rmap #-}+  ( #. ) _ = unsafeCoerce+  {-# INLINE ( #. ) #-}+  ( .# ) p _ = unsafeCoerce p+  {-# INLINE ( .# ) #-}++instance Choice (Market a b) where+  left' (Market bt seta) = Market (Left . bt) $ \sc -> case sc of+    Left s -> case seta s of+      Left t -> Left (Left t)+      Right a -> Right a+    Right c -> Left (Right c)+  {-# INLINE left' #-}+  right' (Market bt seta) = Market (Right . bt) $ \cs -> case cs of+    Left c -> Left (Left c)+    Right s -> case seta s of+      Left t -> Left (Right t)+      Right a -> Right a+  {-# INLINE right' #-}
+ src/Control/Lens/Internal/Review.hs view
@@ -0,0 +1,176 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE UndecidableInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FunctionalDependencies #-}+#ifdef TRUSTWORTHY+{-# LANGUAGE Trustworthy #-}+#endif+-----------------------------------------------------------------------------+-- |+-- Module      :  Control.Lens.Internal.Review+-- Copyright   :  (C) 2012-2013 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  provisional+-- Portability :  non-portable+--+----------------------------------------------------------------------------+module Control.Lens.Internal.Review+  (+  -- ** Reviewing+    Reviewable(..)+  , Reviewed(..)+  ) where++import Control.Applicative+import Control.Comonad+import Control.Monad.Fix+import Data.Bifoldable+import Data.Bifunctor+import Data.Bitraversable+import Data.Distributive+import Data.Foldable+import Data.Functor.Bind+import Data.Profunctor+import Data.Profunctor.Rep+import Data.Profunctor.Unsafe+import Data.Proxy+import Data.Tagged+import Data.Traversable+#ifndef SAFE+import Unsafe.Coerce+#endif++-----------------------------------------------------------------------------+-- Reviewable+----------------------------------------------------------------------------++-- | This provides a dual notion to that of 'Control.Lens.Getter.Gettable'.+class Profunctor p => Reviewable p where+  retagged :: p a b -> p s b+  -- retaggedDot, dotRetagged?++instance Reviewable Tagged where+  retagged = retag+  {-# INLINE retagged #-}++------------------------------------------------------------------------------+-- Review: Reviewed+------------------------------------------------------------------------------++-- | This is a profunctor used internally to implement "Review"+--+-- It plays a role similar to that of 'Control.Lens.Internal.Getter.Accessor'+-- or 'Const' do for "Control.Lens.Getter"+newtype Reviewed a b = Reviewed { runReviewed :: b }++instance Reviewable Reviewed where+  retagged (Reviewed b) = Reviewed b+  {-# INLINE retagged #-}++instance Functor (Reviewed a) where+  fmap bc (Reviewed b) = Reviewed (bc b)+  {-# INLINE fmap #-}++instance Apply (Reviewed a) where+  (<.>) a = Reviewed #. runReviewed a .# runReviewed+  {-# INLINE (<.>) #-}+  a <. _ = a+  {-# INLINE (<.) #-}+  _ .> b = b+  {-# INLINE (.>) #-}++instance Applicative (Reviewed a) where+  pure = Reviewed+  (<*>) a = Reviewed #. runReviewed a .# runReviewed+  {-# INLINE (<*>) #-}+  a <* _ = a+  {-# INLINE (<*) #-}+  _ *> b = b+  {-# INLINE (*>) #-}++instance Comonad (Reviewed a) where+  extract = runReviewed+  {-# INLINE extract #-}+  duplicate = Reviewed+  {-# INLINE duplicate #-}+  extend = ( #. ) Reviewed+  {-# INLINE extend #-}++instance ComonadApply (Reviewed a) where+  (<@>) a = Reviewed #. runReviewed a .# runReviewed+  {-# INLINE (<@>) #-}+  a <@ _ = a+  {-# INLINE (<@) #-}+  _ @> b = b+  {-# INLINE (@>) #-}++instance Bind (Reviewed a) where+  Reviewed a >>- f = f a+  {-# INLINE (>>-) #-}++instance Monad (Reviewed a) where+  return = Reviewed+  {-# INLINE return #-}+  Reviewed a >>= f = f a+  {-# INLINE (>>=) #-}+  _ >> a = a+  {-# INLINE (>>) #-}++instance MonadFix (Reviewed a) where+  mfix f = a where a = f (runReviewed a)+  {-# INLINE mfix #-}++instance Foldable (Reviewed a) where+  foldMap f (Reviewed b) = f b+  {-# INLINE foldMap #-}++instance Traversable (Reviewed a) where+  traverse f (Reviewed b) = Reviewed <$> f b+  {-# INLINE traverse #-}++instance Bifunctor Reviewed where+  bimap _ g (Reviewed b) = Reviewed (g b)+  {-# INLINE bimap #-}++instance Bifoldable Reviewed where+  bifoldMap _ g (Reviewed b) = g b+  {-# INLINE bifoldMap #-}++instance Bitraversable Reviewed where+  bitraverse _ g (Reviewed b) = Reviewed <$> g b+  {-# INLINE bitraverse #-}++instance Distributive (Reviewed a) where+  distribute = Reviewed . fmap runReviewed+  {-# INLINE distribute #-}++instance Profunctor Reviewed where+  dimap _ f (Reviewed c) = Reviewed (f c)+  {-# INLINE dimap #-}+  lmap _ (Reviewed c) = Reviewed c+  {-# INLINE lmap #-}+  rmap = fmap+  {-# INLINE rmap #-}+  Reviewed b .# _ = Reviewed b+  {-# INLINE ( .# ) #-}+#ifndef SAFE+  ( #. ) _ = unsafeCoerce+  {-# INLINE ( #. ) #-}+#endif++instance Choice Reviewed where+  left' (Reviewed b) = Reviewed (Left b)+  {-# INLINE left' #-}+  right' (Reviewed b) = Reviewed (Right b)+  {-# INLINE right' #-}++instance Corepresentable Reviewed where+  type Corep Reviewed = Proxy+  cotabulate f = Reviewed (f Proxy)+  {-# INLINE cotabulate #-}+  corep (Reviewed b) Proxy = b+  {-# INLINE corep #-}
+ src/Control/Lens/Internal/Setter.hs view
@@ -0,0 +1,132 @@+{-# LANGUAGE CPP #-}+#ifdef TRUSTWORTHY+{-# LANGUAGE Trustworthy #-}+#endif+-----------------------------------------------------------------------------+-- |+-- Module      :  Control.Lens.Internal.Setter+-- Copyright   :  (C) 2012-2013 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  provisional+-- Portability :  non-portable+--+----------------------------------------------------------------------------+module Control.Lens.Internal.Setter+  (+  -- ** Setters+    Settable(..)+  , Mutator(..)+  ) where++import Control.Applicative+import Control.Applicative.Backwards+import Control.Comonad+import Data.Distributive+import Data.Foldable+import Data.Functor.Bind+import Data.Functor.Compose+import Data.Functor.Identity+import Data.Profunctor+import Data.Profunctor.Unsafe+import Data.Traversable++-----------------------------------------------------------------------------+-- Settable+-----------------------------------------------------------------------------++-- | Anything 'Settable' must be isomorphic to the 'Identity' 'Functor'.+class (Applicative f, Distributive f, Traversable f) => Settable f where+  untainted :: f a -> a++  untaintedDot :: Profunctor p => p a (f b) -> p a b+  untaintedDot g = g `seq` rmap untainted g+  {-# INLINE untaintedDot #-}++  taintedDot :: Profunctor p => p a b -> p a (f b)+  taintedDot g = g `seq` rmap pure g+  {-# INLINE taintedDot #-}++-- | So you can pass our 'Control.Lens.Setter.Setter' into combinators from other lens libraries.+instance Settable Identity where+  untainted = runIdentity+  {-# INLINE untainted #-}+  untaintedDot = (runIdentity #.)+  {-# INLINE untaintedDot #-}+  taintedDot = (Identity #.)+  {-# INLINE taintedDot #-}++-- | 'Control.Lens.Fold.backwards'+instance Settable f => Settable (Backwards f) where+  untainted = untaintedDot forwards+  {-# INLINE untainted #-}++instance (Settable f, Settable g) => Settable (Compose f g) where+  untainted = untaintedDot (untaintedDot getCompose)+  {-# INLINE untainted #-}++-----------------------------------------------------------------------------+-- Mutator+-----------------------------------------------------------------------------++-- | 'Mutator' is just a renamed 'Identity' 'Functor' to give better error+-- messages when someone attempts to use a 'Control.Lens.Getter.Getter' as a 'Control.Lens.Setter.Setter'.+--+-- Most user code will never need to see this type.+newtype Mutator a = Mutator { runMutator :: a }++instance Functor Mutator where+  fmap f (Mutator a) = Mutator (f a)+  {-# INLINE fmap #-}++instance Apply Mutator where+  Mutator f <.> Mutator a = Mutator (f a)+  {-# INLINE (<.>) #-}++instance Applicative Mutator where+  pure = Mutator+  {-# INLINE pure #-}+  Mutator f <*> Mutator a = Mutator (f a)+  {-# INLINE (<*>) #-}++instance Bind Mutator where+  Mutator x >>- f = f x+  {-# INLINE (>>-) #-}++instance Monad Mutator where+  return = Mutator+  {-# INLINE return #-}+  Mutator x >>= f = f x+  {-# INLINE (>>=) #-}++instance Comonad Mutator where+  extract = runMutator+  {-# INLINE extract #-}+  extend f w = Mutator (f w)+  {-# INLINE extend #-}+  duplicate = Mutator+  {-# INLINE duplicate #-}++instance ComonadApply Mutator where+  (<@>) = (<*>)+  {-# INLINE (<@>) #-}++instance Distributive Mutator where+  distribute = Mutator . fmap runMutator+  {-# INLINE distribute #-}++instance Foldable Mutator where+  foldMap f (Mutator a) = f a+  {-# INLINE foldMap #-}++instance Traversable Mutator where+  traverse f (Mutator a) = Mutator <$> f a+  {-# INLINE traverse #-}++instance Settable Mutator where+  untainted = runMutator+  {-# INLINE untainted #-}+  untaintedDot = (runMutator #.)+  {-# INLINE untaintedDot #-}+  taintedDot = (Mutator #.)+  {-# INLINE taintedDot #-}
src/Control/Lens/Internal/Zipper.hs view
@@ -1,11 +1,16 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE GADTs #-}+{-# LANGUAGE Rank2Types #-} {-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE PatternGuards #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE EmptyDataDecls #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE ExistentialQuantification #-} #ifdef TRUSTWORTHY {-# LANGUAGE Trustworthy #-} #endif@@ -13,7 +18,7 @@ ----------------------------------------------------------------------------- -- | -- Module      :  Control.Lens.Internal.Zipper--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-2013 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  experimental@@ -27,22 +32,263 @@ module Control.Lens.Internal.Zipper where  import Control.Applicative-import Control.Category+import Control.Category ((>>>)) import Control.Monad-import Control.Lens.Classes import Control.Lens.Getter-import Control.Lens.IndexedLens-import Control.Lens.Internal+import Control.Lens.Indexed+import Control.Lens.Internal.Context+import Control.Lens.Internal.Indexed+import Control.Lens.Lens import Control.Lens.Setter import Control.Lens.Traversal import Control.Lens.Type+import Data.Foldable+import Data.Functor.Apply import Data.Maybe-import Prelude hiding ((.),id)+import Data.Monoid+import Data.Profunctor.Unsafe  -- $setup -- >>> import Control.Lens -- >>> import Data.Char +{-# ANN module "HLint: ignore Use foldl" #-}++------------------------------------------------------------------------------+-- * Jacket+------------------------------------------------------------------------------++-- | A 'Jacket' is used to store the contents of a 'Traversal' in a way+-- that we do not have to re-asocciate the elements. This enables us to+-- more gracefully deal with infinite traversals.+data Jacket i a+  = Ap Int         -- size+       Bool        -- left-to-right null check+       Bool        -- right-to-left null check+       (Last i)+       (Jacket i a) -- left+       (Jacket i a) -- right+  | Leaf i a+  | Pure+  deriving Show++-- | Return the number of children in a jacket+size :: Jacket i a -> Int+size (Ap s _ _ _ _ _) = s+size Leaf{}           = 1+size Pure             = 0+{-# INLINE size #-}++-- | This is an internal function used to check from left-to-right if a 'Jacket' has any 'Leaf' nots or not.+nullLeft :: Jacket i a -> Bool+nullLeft (Ap _ nl _ _ _ _) = nl+nullLeft (Leaf _ _)        = False+nullLeft Pure              = True+{-# INLINE nullLeft #-}++-- | This is an internal function used to check from right-to-left if a 'Jacket' has any 'Leaf' nots or not.+nullRight :: Jacket i a -> Bool+nullRight (Ap _ _ nr _ _ _) = nr+nullRight (Leaf _ _)        = False+nullRight Pure              = True+{-# INLINE nullRight #-}++-- | This is used to extract the maximal key from a 'Jacket'. This is used by 'moveTo' and 'moveToward' to+-- seek specific keys, borrowing the asympotic guarantees of the original structure in many cases!+maximal :: Jacket i a -> Last i+maximal (Ap _ _ _ li _ _) = li+maximal (Leaf i _)        = Last (Just i)+maximal Pure              = Last Nothing+{-# INLINE maximal #-}++instance Functor (Jacket i) where+  fmap f (Ap m nl nr li l r) = Ap m nl nr li (fmap f l) (fmap f r)+  fmap f (Leaf i a)          = Leaf i (f a)+  fmap _ Pure                = Pure+  {-# INLINE fmap #-}++instance Foldable (Jacket i) where+  foldMap f (Ap _ _ _ _ l r) = foldMap f l `mappend` foldMap f r+  foldMap f (Leaf _ a)       = f a+  foldMap _ Pure             = mempty+  {-# INLINE foldMap #-}++instance Traversable (Jacket i) where+  traverse f (Ap m nl nr li l r) = Ap m nl nr li <$> traverse f l <*> traverse f r+  traverse f (Leaf i a)          = Leaf i <$> f a+  traverse _ Pure                = pure Pure+  {-# INLINE traverse #-}++instance FunctorWithIndex i (Jacket i) where+  imap f = go where+    go (Ap m nl nr li l r) = Ap m nl nr li (go l) (go r)+    go (Leaf i a)          = Leaf i (f i a)+    go Pure                = Pure+  {-# INLINE imap #-}++instance FoldableWithIndex i (Jacket i) where+  ifoldMap f = go where+    go (Ap _ _ _ _ l r) = go l `mappend` go r+    go (Leaf i a)       = f i a+    go Pure             = mempty+  {-# INLINE ifoldMap #-}++instance TraversableWithIndex i (Jacket i) where+  itraverse f = go where+    go (Ap m nl nr li l r) = Ap m nl nr li <$> go l <*> go r+    go (Leaf i a)          = Leaf i <$> f i a+    go Pure                = pure Pure+  {-# INLINE itraverse #-}++-- | This is an illegal 'Monoid'.+instance Monoid (Jacket i a) where+  mempty = Pure+  {-# INLINE mempty #-}++  mappend l r = Ap (size l + size r) (nullLeft l && nullLeft r) (nullRight r && nullRight l) (maximal l <> maximal r) l r+  {-# INLINE mappend #-}++-- | Construct a 'Jacket' from a 'Bazaar'+jacketIns :: Bazaar (Indexed i) a b t -> Jacket i a+jacketIns (Bazaar bz) = runAccessor $ bz $ Indexed (\i -> Accessor #. Leaf i)+{-# INLINE jacketIns #-}++------------------------------------------------------------------------------+-- * Flow+------------------------------------------------------------------------------++-- | Once we've updated a 'Zipper' we need to put the values back into the original+-- shape. 'Flow' is an illegal 'Applicative' that is used to put the values back.+newtype Flow i b a = Flow { runFlow :: Jacket i b -> a }++instance Functor (Flow i b) where+  fmap f (Flow g) = Flow (f . g)+  {-# INLINE fmap #-}++instance Apply (Flow i b) where+  (<.>) = (<*>)+  {- INLINE (<.>) #-}++-- | This is an illegal 'Applicative'.+instance Applicative (Flow i b) where+  pure a = Flow (const a)+  {-# INLINE pure #-}+  Flow mf <*> Flow ma = Flow $ \ s -> case s of+    Ap _ _ _ _ l r -> mf l (ma r)+    _              -> mf s (ma s)+  {-# INLINE (<*>) #-}++-- | Given a 'Bazaar' and a 'Jacket' build from that 'Bazaar' with 'jacketIns',+-- refill the 'Bazaar' with its new contents.+jacketOuts :: Bazaar (Indexed i) a b t -> Jacket j b -> t+jacketOuts bz = runFlow $ runBazaar bz $ Indexed $ \ _ _ -> Flow $ \ t -> case t of+  Leaf _ a -> a+  _        -> error "jacketOuts: wrong shape"+{-# INLINE jacketOuts #-}++-- | This is only a valid 'Lens' if you don't change the shape of the 'Jacket'!+jacket :: AnIndexedTraversal i s t a b -> Lens s t (Jacket i a) (Jacket j b)+jacket l f s = jacketOuts bz <$> f (jacketIns bz) where+  bz = l sell s+{-# INLINE jacket #-}++------------------------------------------------------------------------------+-- * Paths+------------------------------------------------------------------------------++-- | A 'Path' into a 'Jacket' that ends at a 'Leaf'.+data Path i a+  = ApL Int Bool Bool (Last i) !(Path i a) !(Jacket i a)+  | ApR Int Bool Bool (Last i) !(Jacket i a) !(Path i a)+  | Start+  deriving Show++instance Functor (Path i) where+  fmap f (ApL m nl nr li p q) = ApL m nl nr li (fmap f p) (fmap f q)+  fmap f (ApR m nl nr li p q) = ApR m nl nr li (fmap f p) (fmap f q)+  fmap _ Start = Start+  {-# INLINE fmap #-}++-- | Calculate the absolute position of the 'Leaf' targeted by a 'Path'.+--+-- This can be quite expensive for right-biased traversals such as you+-- receive from a list.+offset :: Path i a -> Int+offset Start           = 0+offset (ApL _ _ _ _ q _) = offset q+offset (ApR _ _ _ _ l q) = size l + offset q+{-# INLINE offset #-}++-- | Return the total number of children in the 'Jacket' by walking the+-- 'Path' to the root.+pathsize :: Path i a -> Int+pathsize = go 1 where+  go n Start = n+  go _ (ApL n _ _ _ p _) = go n p+  go _ (ApR n _ _ _ _ p) = go n p+{-# INLINE pathsize #-}++-- * Recursion+--+-- For several operations, we unroll the first step of the recursion (or part+-- of it) so GHC can inline better. There are two specific cases that we care+-- about: The "lens case", where the entire tree is just (Leaf (Identity x)), and the+-- "list case", where the traversal tree is right-biased, as in (Ap (Leaf (Identity x))+-- (Ap (Leaf (Identity y)) ...)). It should be safe to delete any of these cases.++-- | Reconstruct a 'Jacket' from a 'Path'.+recompress :: Path i a -> i -> a -> Jacket i a+recompress Start i a = Leaf i a -- Unrolled: The lens case.+recompress (ApL m _ _ li Start r) i a = Ap m False False li (Leaf i a) r -- Unrolled: The list case. In particular, a right-biased tree that we haven't moved rightward in.+recompress p i a = go p (Leaf i a) where+  go Start              q = q+  go (ApL m _ _ li q r) l = go q (Ap m False False li l r)+  go (ApR m _ _ li l q) r = go q (Ap m False False li l r)+{-# INLINE recompress #-}++-- | Walk down the tree to the leftmost child.+startl :: Path i a -> Jacket i a -> r -> (Path i a -> i -> a -> r) -> r+startl p0 (Leaf i a) _ kp = kp p0 i a -- Unrolled: The lens case.+startl p0 (Ap m nl nr li (Leaf i a) r) _ kp = kp (ApL m nl nr li p0 r) i a -- Unrolled: The list case. (Is this one a good idea?)+startl p0 c0 kn kp = go p0 c0 where+  go p (Ap m nl nr li l r)+    | nullLeft l  = go (ApR m nl nr li Pure p) r+    | otherwise   = go (ApL m nl nr li p r) l+  go p (Leaf i a) = kp p i a+  go _ Pure       = kn+{-# INLINE startl #-}++-- | Walk down the tree to the rightmost child.+startr :: Path i a -> Jacket i a -> r -> (Path i a -> i -> a -> r) -> r+startr p0 (Leaf i a) _ kp = kp p0 i a -- Unrolled: The lens case.+startr p0 c0 kn kp = go p0 c0 where+  go p (Ap m nl nr li l r)+     | nullRight r = go (ApL m nl nr li p Pure) l+     | otherwise   = go (ApR m nl nr li l p) r+  go p (Leaf i a)  = kp p i a+  go _ Pure        = kn+{-# INLINE startr #-}++-- | Move left one 'Leaf'.+movel :: Path i a -> Jacket i a -> r -> (Path i a -> i -> a -> r) -> r+movel p0 c0 kn kp = go p0 c0 where+  go Start _ = kn+  go (ApR m _ _ li l q) r+    | nullRight l = go q (Ap m False False li l Pure)+    | otherwise   = startr (ApL m False False li q r) l kn kp+  go (ApL m _ _ li p r) l = go p (Ap m False False li l r)+{-# INLINE movel #-}++-- | Move right one 'Leaf'.+mover :: Path i a -> Jacket i a -> r -> (Path i a -> i -> a -> r) -> r+mover p0 c0 kn kp = go p0 c0 where+  go Start _ = kn+  go (ApL m _ _ li q r) l+    | nullLeft r  = go q (Ap m False False li Pure r)+    | otherwise   = startl (ApR m False False li l q) r kn kp+  go (ApR m _ _ li l p) r = go p (Ap m False False li l r)+{-# INLINE mover #-}+ ----------------------------------------------------------------------------- -- * Zippers -----------------------------------------------------------------------------@@ -51,94 +297,109 @@ -- -- Every 'Zipper' starts with 'Top'. ----- /e.g./ @'Top' ':>' a@ is the type of the trivial 'Zipper'.+-- /e.g./ @'Top' ':>>' a@ is the type of the trivial 'Zipper'. data Top -infixl 9 :>- -- | This is the type of a 'Zipper'. It visually resembles a \"breadcrumb trail\" as -- used in website navigation. Each breadcrumb in the trail represents a level you -- can move up to. -- -- This type operator associates to the left, so you can use a type like ----- @'Top' ':>' ('String','Double') ':>' 'String' ':>' 'Char'@+-- @'Top' ':>>' ('String','Double') ':>>' 'String' ':>>' 'Char'@ ----- to represent a zipper from @('String','Double')@ down to 'Char' that has an intermediate+-- to represent a 'Zipper' from @('String','Double')@ down to 'Char' that has an intermediate -- crumb for the 'String' containing the 'Char'. ----- You can construct a zipper into *any* data structure with 'zipper'.+-- You can construct a 'Zipper' into *any* data structure with 'zipper'. ----- You can repackage up the contents of a zipper with 'rezip'.+-- You can repackage up the contents of a 'Zipper' with 'rezip'. -- -- >>> rezip $ zipper 42 -- 42 ----- The combinators in this module provide lot of things you can do to the zipper while you--- have it open.+-- The combinators in this module provide lot of things you can do to the+-- 'Zipper' while you have it open. -- -- Note that a value of type @h ':>' s ':>' a@ doesn't actually contain a value -- of type @h ':>' s@ -- as we descend into a level, the previous level is -- unpacked and stored in 'Coil' form. Only one value of type @_ ':>' _@ exists -- at any particular time for any particular 'Zipper'.-data h :> a = Zipper (Coil h a) -- The 'Coil' storing the previous levels of the 'Zipper'.-      {-# UNPACK #-} !Int       -- Number of items to the left.-                     [a]        -- Items to the left (stored reversed).-                     a          -- Focused item.-                     [a]        -- Items to the right. --- | This is an alias for '(:>)'. Provided mostly for convenience-type Zipper = (:>)+data Zipper h i a = Ord i => Zipper !(Coil h i a) Int !Int !(Path i a) i a +-- Top :>> Map String Int :> Int :@ String :>> Bool++infixr 9 :@+-- | An empty data type, used to represent the pairing of a position in+-- a 'Zipper' with an index. See ':>'.+data (:@) a i++infixl 8 :>+-- | This type family represents a 'Zipper' with the @p@ variable+-- abstracting over the position and the index, in terms of ':@'. You+-- can visually see it in type signatures as:+--+-- @+-- h ':>' (a ':@' i) = 'Zipper' h i a+-- @+--+type family (:>) h p+type instance h :> (a :@ i) = Zipper h i a++infixl 8 :>>+-- | Many zippers are indexed by Int keys. This type alias is convenient for reducing syntactic noise for talking about these boring indices.+type h :>> a = Zipper h Int a+ -- | This represents the type a 'Zipper' will have when it is fully 'Zipped' back up. type family Zipped h a-type instance Zipped Top a      = a-type instance Zipped (h :> s) a = Zipped h s+type instance Zipped Top a            = a+type instance Zipped (Zipper h i a) s = Zipped h a  -- | A 'Coil' is a linked list of the levels above the current one. The length -- of a 'Coil' is known at compile time. ----- This is part of the internal structure of a zipper. You shouldn't need to manipulate this directly.-data Coil :: * -> * -> * where-  Coil :: Coil Top a-  Snoc :: Coil h s                           -- Previous 'Coil'.-       -> SimpleLensLike (Bazaar a a) s a    -- The 'Traversal' used to descend into this level (used to build a 'Tape').-       -- The Zipper above us, unpacked:-       -> {-# UNPACK #-} !Int                -- Number of items to the left.-       -> [s]                                -- Previous level's items to the left (stored reverse).-       -> ([a] -> s)                         -- Function to rebuild the previous level's focused item from the entire current level.-                                             --   (Since the current level always has a focus, the list must be nonempty.)-       -> [s]                                -- Previous level's items to the right.-       -> Coil (h :> s) a+-- This is part of the internal structure of a 'Zipper'. You shouldn't need to manipulate this directly.+#ifndef HLINT+data Coil t i a where+  Coil :: Coil Top Int a+  Snoc :: Ord i => !(Coil h j s) -> AnIndexedTraversal' i s a -> Int -> !Int -> !(Path j s) -> j -> (Jacket i a -> s) -> Coil (Zipper h j s) i a+#endif  -- | This 'Lens' views the current target of the 'Zipper'.------ A 'Tape' that can be used to get to the current location is available as the index of this 'Lens'.-focus :: SimpleIndexedLens (Tape (h :> a)) (h :> a) a-focus = indexed $ \f (Zipper h n l a r) -> (\a' -> Zipper h n l a' r) <$> f (Tape (peel h) n) a+focus :: IndexedLens' i (Zipper h i a) a+focus f (Zipper h t o p i a) = Zipper h t o p i <$> indexed f i a {-# INLINE focus #-} --- | Construct a 'Zipper' that can explore anything, and start it at the top.-zipper :: a -> Top :> a-zipper a = Zipper Coil 0 [] a []+-- | Construct a 'Zipper' that can explore anything, and start it at the 'Top'.+zipper :: a -> Top :>> a+zipper = Zipper Coil 0 0 Start 0 {-# INLINE zipper #-} +-- | Return the index of the focus.+focalPoint :: Zipper h i a -> i+focalPoint (Zipper _ _ _ _ i _) = i+{-# INLINE focalPoint #-}+ -- | Return the index into the current 'Traversal' within the current level of the 'Zipper'. ----- @'jerkTo' ('tooth' l) l = Just'@+-- @'jerkTo' ('tooth' l) l = 'Just'@ -- -- Mnemonically, zippers have a number of 'teeth' within each level. This is which 'tooth' you are currently at.-tooth :: (h :> a) -> Int-tooth (Zipper _ n _ _ _) = n+--+-- This is based on ordinal position regardless of the underlying index type. It may be excessively expensive for a list.+--+-- 'focalPoint' may be much cheaper if you have a 'Traversal' indexed by ordinal position!+tooth :: Zipper h i a -> Int+tooth (Zipper _ t o _ _ _) = t + o {-# INLINE tooth #-}  -- | Move the 'Zipper' 'upward', closing the current level and focusing on the parent element. -- -- NB: Attempts to move upward from the 'Top' of the 'Zipper' will fail to typecheck. ---upward :: (h :> s :> a) -> h :> s-upward (Zipper (Snoc h _ un uls k urs) _ ls x rs) = Zipper h un uls ux urs-  where ux = k (reverseList ls ++ x : rs)+upward :: Ord j => h :> s:@j :> a:@i -> h :> s:@j+upward (Zipper (Snoc h _ t o p j k) _ _ q i x) = Zipper h t o p j $ k $ recompress q i x {-# INLINE upward #-}  -- | Jerk the 'Zipper' one 'tooth' to the 'rightward' within the current 'Lens' or 'Traversal'.@@ -157,12 +418,11 @@ -- -- >>> rezip $ zipper (1,2) & fromWithin both & tug rightward & focus .~ 3 -- (1,3)-rightward :: MonadPlus m => (h :> a) -> m (h :> a)-rightward (Zipper _ _ _  _ []    ) = mzero-rightward (Zipper h n ls a (r:rs)) = return (Zipper h (n + 1) (a:ls) r rs)+rightward :: MonadPlus m => h :> a:@i -> m (h :> a:@i)+rightward (Zipper h t o p i a) = mover p (Leaf i a) mzero $ \q j b -> return $ Zipper h t (o + 1) q j b where {-# INLINE rightward #-} --- | Jerk the 'zipper' 'leftward' one 'tooth' within the current 'Lens' or 'Traversal'.+-- | Jerk the 'Zipper' 'leftward' one 'tooth' within the current 'Lens' or 'Traversal'. -- -- Attempts to move past the end of the current 'Traversal' (or trivially, the current 'Lens') -- will return 'Nothing'.@@ -178,19 +438,19 @@ -- -- >>> zipper "hello" & fromWithin traverse & tug rightward & tug leftward & view focus -- 'h'-leftward :: MonadPlus m => (h :> a) -> m (h :> a)-leftward (Zipper _ _ []     _ _ ) = mzero-leftward (Zipper h n (l:ls) a rs) = return (Zipper h (n - 1) ls l (a:rs))+leftward :: MonadPlus m => h :> a:@i -> m (h :> a:@i)+leftward (Zipper h t o p i a) = movel p (Leaf i a) mzero $ \q j b -> return $ Zipper h t (o - 1) q j b {-# INLINE leftward #-}  -- | Move to the leftmost position of the current 'Traversal'. -- -- This is just a convenient alias for @'farthest' 'leftward'@. ----- >>> zipper "hello" & fromWithin traverse & rightmost & focus .~ 'a' & rezip--- "hella"-leftmost :: (a :> b) -> a :> b-leftmost = farthest leftward+-- >>> zipper "hello" & fromWithin traverse & leftmost & focus .~ 'a' & rezip+-- "aello"+leftmost :: a :> b:@i -> a :> b:@i+leftmost (Zipper h _ _ p i a) = startl Start (recompress p i a) (error "leftmost: bad Jacket structure") (Zipper h 0 0)+{-# INLINE leftmost #-}  -- | Move to the rightmost position of the current 'Traversal'. --@@ -198,11 +458,12 @@ -- -- >>> zipper "hello" & fromWithin traverse & rightmost & focus .~ 'y' & leftmost & focus .~ 'j' & rezip -- "jelly"-rightmost :: (a :> b) -> a :> b-rightmost = farthest rightward+rightmost :: a :> b:@i -> a :> b:@i+rightmost (Zipper h _ _ p i a) = startr Start (recompress p i a) (error "rightmost: bad Jacket structure") (\q -> Zipper h (offset q) 0 q)+{-# INLINE rightmost #-} --- | This allows you to safely 'tug leftward' or 'tug rightward' on a 'zipper'. This--- will attempt the move, and stay where it was if it fails.+-- | This allows you to safely 'tug' 'leftward' or 'tug' 'rightward' on a+-- 'Zipper'. This will attempt the move, and stay where it was if it fails. -- -- The more general signature allows its use in other circumstances, however. --@@ -217,9 +478,10 @@ tug f a = fromMaybe a (f a) {-# INLINE tug #-} --- | This allows you to safely @'tug' 'leftward'@ or @'tug' 'rightward'@ multiple times on a 'zipper',--- moving multiple steps in a given direction and stopping at the last place you--- couldn't move from. This lets you safely move a zipper, because it will stop at either end.+-- | This allows you to safely @'tug' 'leftward'@ or @'tug' 'rightward'@+-- multiple times on a 'Zipper', moving multiple steps in a given direction+-- and stopping at the last place you couldn't move from. This lets you safely+-- move a 'Zipper', because it will stop at either end. -- -- >>> fmap rezip $ zipper "stale" & within traverse <&> tugs rightward 2 <&> focus .~ 'y' -- "style"@@ -237,7 +499,7 @@  -- | Move in a direction as far as you can go, then stop there. ----- This repeatedly applies a function until it returns Nothing, and then returns the last answer.+-- This repeatedly applies a function until it returns 'Nothing', and then returns the last answer. -- -- >>> fmap rezip $ zipper ("hello","world") & downward _1 & within traverse <&> rightmost <&> focus .~ 'a' -- ("hella","world")@@ -249,7 +511,7 @@   go a = maybe a go (f a) {-# INLINE farthest #-} --- | This allows for you to repeatedly pull a 'zipper' in a given direction, failing if it falls off the end.+-- | This allows for you to repeatedly pull a 'Zipper' in a given direction, failing if it falls off the end. -- -- >>> isNothing $ zipper "hello" & within traverse >>= jerks rightward 10 -- True@@ -265,12 +527,14 @@     go n a = f a >>= go (n - 1) {-# INLINE jerks #-} --- | Returns the number of siblings at the current level in the 'zipper'.+-- | Returns the number of siblings at the current level in the 'Zipper'. -- -- @'teeth' z '>=' 1@ -- -- /NB:/ If the current 'Traversal' targets an infinite number of elements then this may not terminate. --+-- This is also a particularly expensive operation to perform on an unbalanced tree.+-- -- >>> zipper ("hello","world") & teeth -- 1 --@@ -288,8 +552,8 @@ -- -- >>> zipper ("hello","world") & fromWithin (both.traverse) & teeth -- 10-teeth :: (h :> a) -> Int-teeth (Zipper _ n _ _ rs) = n + 1 + length rs+teeth :: h :> a:@i -> Int+teeth (Zipper _ _ _ p _ _) = pathsize p {-# INLINE teeth #-}  -- | Move the 'Zipper' horizontally to the element in the @n@th position in the@@ -297,7 +561,7 @@ -- -- This returns 'Nothing' if the target element doesn't exist. ----- @'jerkTo' n ≡ 'jerks' 'rightward' n . 'farthest' 'leftward'@+-- @'jerkTo' n ≡ 'jerks' 'rightward' n '.' 'farthest' 'leftward'@ -- -- >>> isNothing $ zipper "not working." & jerkTo 20 -- True@@ -307,7 +571,7 @@ -- -- >>> fmap rezip $ zipper "not working" & within traverse >>= jerkTo 2 <&> focus .~ 'w' -- Just "now working"-jerkTo :: MonadPlus m => Int -> (h :> a) -> m (h :> a)+jerkTo :: MonadPlus m => Int -> (h :> a:@i) -> m (h :> a:@i) jerkTo n z = case compare k n of   LT -> jerks rightward (n - k) z   EQ -> return z@@ -318,13 +582,13 @@ -- | Move the 'Zipper' horizontally to the element in the @n@th position of the -- current level, absolutely indexed, starting with the 'farthest' 'leftward' as @0@. ----- If the element at that position doesn't exist, then this will clamp to the range @0 <= n < 'teeth'@.+-- If the element at that position doesn't exist, then this will clamp to the range @0 '<=' n '<' 'teeth'@. ----- @'tugTo' n ≡ 'tugs' 'rightward' n . 'farthest' 'leftward'@+-- @'tugTo' n ≡ 'tugs' 'rightward' n '.' 'farthest' 'leftward'@ -- -- >>> rezip $ zipper "not working." & fromWithin traverse & tugTo 100 & focus .~ '!' & tugTo 1 & focus .~ 'u' -- "nut working!"-tugTo :: Int -> (h :> a) -> h :> a+tugTo :: Int -> h :> a:@i -> h :> a:@i tugTo n z = case compare k n of   LT -> tugs rightward (n - k) z   EQ -> z@@ -332,126 +596,237 @@   where k = tooth z {-# INLINE tugTo #-} +-- | Move towards a particular index in the current 'Traversal'.+moveToward :: i -> h :> a:@i -> h :> a:@i+moveToward i z@(Zipper h _ _ p0 j s0)+  | i == j   = z+  | otherwise = go Start (recompress p0 j s0)+  where+    go _ Pure = z+    go p (Ap m nl nr li l r)+      | Last (Just k) <- maximal l, k >= i = go (ApL m nl nr li p r) l+      | otherwise      = go (ApR m nl nr li l p) r+    go p (Leaf k a) = Zipper h (offset p) 0 p k a+{-# INLINE moveToward #-}++-- | Move horizontally to a particular index @i@ in the current+-- 'Traversal'. In the case of simple zippers, the index is 'Int' and+-- we can move between traversals fairly easily:+--+-- >>> zipper (42, 32) & fromWithin both & moveTo 0 <&> view focus+-- 42+--+-- >>> zipper (42, 32) & fromWithin both & moveTo 1 <&> view focus+-- 32+--+moveTo :: MonadPlus m => i -> h :> a:@i -> m (h :> a:@i)+moveTo i z = case moveToward i z of+  z'@(Zipper _ _ _ _ j _)+    | i == j    -> return z'+    | otherwise -> mzero+{-# INLINE moveTo #-}++-- | Construct an 'IndexedLens' from 'ALens' where the index is fixed to @0@.+lensed :: ALens' s a -> IndexedLens' Int s a+lensed l f = cloneLens l (indexed f (0 :: Int))+{-# INLINE lensed #-}+ -- | Step down into a 'Lens'. This is a constrained form of 'fromWithin' for when you know -- there is precisely one target that can never fail. -- -- @--- 'downward' :: 'Simple' 'Lens' s a -> (h :> s) -> h :> s :> a--- 'downward' :: 'Simple' 'Iso' s a  -> (h :> s) -> h :> s :> a+-- 'downward' :: 'Lens'' s a -> (h ':>' s) -> h ':>' s ':>' a+-- 'downward' :: 'Iso'' s a  -> (h ':>' s) -> h ':>' s ':>' a -- @-downward :: SimpleLensLike (Context a a) s a -> (h :> s) -> h :> s :> a-downward l (Zipper h n ls s rs) = case l (Context id) s of-  Context k a -> Zipper (Snoc h (cloneLens l) n ls (k . head) rs) 0 [] a []+downward :: forall j h s a. ALens' s a -> h :> s:@j -> h :> s:@j :>> a+downward l (Zipper h t o p j s) = Zipper (Snoc h l' t o p j go) 0 0 Start 0 (s^.l')+  where l' :: IndexedLens' Int s a+        l' = lensed l+        go (Leaf _ b) = set l' b s+        go _ = error "downward: rezipping" {-# INLINE downward #-} +-- | Step down into a 'IndexedLens'. This is a constrained form of 'ifromWithin' for when you know+-- there is precisely one target that can never fail.+--+-- @+-- 'idownward' :: 'IndexedLens'' i s a -> (h ':>' s:\@j) -> h ':>' s:\@j ':>' a:\@i+-- @+idownward :: forall i j h s a. Ord i => AnIndexedLens' i s a -> h :> s:@j -> h :> s:@j :> a:@i+idownward l (Zipper h t o p j s) = Zipper (Snoc h l' t o p j go) 0 0 Start i a+  where l' :: IndexedLens' i s a+        l' = cloneIndexedLens l+        (i, a) = iview l' s+        go (Leaf _ b) = set l' b s+        go _ = error "idownward: rezipping"+{-# INLINE idownward #-}+ -- | Step down into the 'leftmost' entry of a 'Traversal'. -- -- @--- 'within' :: 'Simple' 'Traversal' s a -> (h :> s) -> Maybe (h :> s :> a)--- 'within' :: 'Simple' 'Lens' s a      -> (h :> s) -> Maybe (h :> s :> a)--- 'within' :: 'Simple' 'Iso' s a       -> (h :> s) -> Maybe (h :> s :> a)+-- 'within' :: 'Traversal'' s a -> (h ':>' s:\@j) -> 'Maybe' (h ':>' s:\@j ':>>' a)+-- 'within' :: 'Prism'' s a     -> (h ':>' s:\@j) -> 'Maybe' (h ':>' s:\@j ':>>' a)+-- 'within' :: 'Lens'' s a      -> (h ':>' s:\@j) -> 'Maybe' (h ':>' s:\@j ':>>' a)+-- 'within' :: 'Iso'' s a       -> (h ':>' s:\@j) -> 'Maybe' (h ':>' s:\@j ':>>' a) -- @-within :: MonadPlus m => SimpleLensLike (Bazaar a a) s a -> (h :> s) -> m (h :> s :> a)-within l (Zipper h n ls s rs) = case partsOf' l (Context id) s of-  Context _ []     -> mzero-  Context k (a:as) -> return (Zipper (Snoc h l n ls k rs) 0 [] a as)+--+-- @+-- 'within' :: 'MonadPlus' m => 'ATraversal'' s a -> (h ':>' s:\@j) -> m (h ':>' s:\@j ':>>' a)+-- @+within :: MonadPlus m => LensLike' (Indexing (Bazaar' (Indexed Int) a)) s a -> (h :> s:@j) -> m (h :> s:@j :>> a)+within = iwithin . indexing {-# INLINE within #-} +-- | Step down into the 'leftmost' entry of an 'IndexedTraversal'.+--+-- /Note:/ The index is assumed to be ordered and must increase monotonically or else you cannot (safely) 'moveTo' or 'moveToward' or use tapes.+--+-- @+-- 'iwithin' :: 'IndexedTraversal'' i s a -> (h ':>' s:\@j) -> 'Maybe' (h ':>' s:\@j ':>' a:\@i)+-- 'iwithin' :: 'IndexedLens'' i s a      -> (h ':>' s:\@j) -> 'Maybe' (h ':>' s:\@j ':>' a:\@i)+-- @+--+-- @+-- 'iwithin' :: 'MonadPlus' m => 'ATraversal'' s a -> (h ':>' s:\@j) -> m (h ':>' s:\@j ':>>' a)+-- @+iwithin :: (MonadPlus m, Ord i) => AnIndexedTraversal' i s a -> (h :> s:@j) -> m (h :> s:@j :> a:@i)+iwithin l (Zipper h t o p j s) = case jacket l (Context id) s of+  Context k xs -> startl Start xs mzero $ \q i a -> return $ Zipper (Snoc h l t o p j k) 0 0 q i a+{-# INLINE iwithin #-}+ -- | Step down into every entry of a 'Traversal' simultaneously. ----- >>> zipper ("hello","world") & withins both >>= leftward >>= withins traverse >>= rightward <&> focus %~ toUpper <&> rezip+-- >>> zipper ("hello","world") & withins both >>= leftward >>= withins traverse >>= rightward <&> focus %~ toUpper <&> rezip :: [(String,String)] -- [("hEllo","world"),("heLlo","world"),("helLo","world"),("hellO","world")] -- -- @--- 'withins' :: 'Simple' 'Traversal' s a -> (h :> s) -> [h :> s :> a]--- 'withins' :: 'Simple' 'Lens' s a      -> (h :> s) -> [h :> s :> a]--- 'withins' :: 'Simple' 'Iso' s a       -> (h :> s) -> [h :> s :> a]+-- 'withins' :: 'Traversal'' s a -> (h ':>' s:\@j) -> [h ':>' s:\@j ':>>' a]+-- 'withins' :: 'Lens'' s a      -> (h ':>' s:\@j) -> [h ':>' s:\@j ':>>' a]+-- 'withins' :: 'Iso'' s a       -> (h ':>' s:\@j) -> [h ':>' s:\@j ':>>' a] -- @-withins :: SimpleLensLike (Bazaar a a) s a -> (h :> s) -> [h :> s :> a]-withins l (Zipper h n ls s rs) = case partsOf' l (Context id) s of-  Context k ys -> go k [] ys-  where go k xs (y:ys) = Zipper (Snoc h l n ls k rs) 0 xs y ys : go k (y:xs) ys-        go _ _  []     = []+withins :: MonadPlus m => LensLike' (Indexing (Bazaar' (Indexed Int) a)) s a -> (h :> s:@j) -> m (h :> s:@j :>> a)+withins = iwithins . indexing+{-# INLINE withins #-} +-- | Step down into every entry of an 'IndexedTraversal' simultaneously.+--+-- /Note:/ The index is assumed to be ordered and must increase monotonically or else you cannot (safely) 'moveTo' or 'moveToward' or use tapes.+--+-- @+-- 'iwithins' :: 'IndexedTraversal'' i s a -> (h ':>' s:\@j) -> [h ':>' s:\@j ':>' a:\@i]+-- 'iwithins' :: 'IndexedLens'' i s a      -> (h ':>' s:\@j) -> [h ':>' s:\@j ':>' a:\@i]+-- @+iwithins :: (MonadPlus m, Ord i) => AnIndexedTraversal' i s a -> (h :> s:@j) -> m (h :> s:@j :> a:@i)+iwithins z (Zipper h t o p j s) = case jacket z (Context id) s of+  Context k xs -> let up = Snoc h z t o p j k+                      go q (Ap m nl nr li l r) = go (ApL m nl nr li q r) l `mplus` go (ApR m nl nr li l q) r+                      go q (Leaf i a)       = return $ Zipper up (offset q) 0 q i a+                      go _ Pure             = mzero+                  in  go Start xs+{-# INLINE iwithins #-}+ -- | Unsafely step down into a 'Traversal' that is /assumed/ to be non-empty. -- -- If this invariant is not met then this will usually result in an error! -- -- @--- 'fromWithin' :: 'Simple' 'Traversal' s a -> (h :> s) -> h :> s :> a--- 'fromWithin' :: 'Simple' 'Lens' s a      -> (h :> s) -> h :> s :> a--- 'fromWithin' :: 'Simple' 'Iso' s a       -> (h :> s) -> h :> s :> a+-- 'fromWithin' :: 'Traversal'' s a -> (h ':>' s:\@j) -> h ':>' s:\@j ':>>' a+-- 'fromWithin' :: 'Lens'' s a      -> (h ':>' s:\@j) -> h ':>' s:\@j ':>>' a+-- 'fromWithin' :: 'Iso'' s a       -> (h ':>' s:\@j) -> h ':>' s:\@j ':>>' a -- @ -- -- You can reason about this function as if the definition was: ----- @'fromWithin' l ≡ 'fromJust' '.' 'within' l@------ but it is lazier in such a way that if this invariant is violated, some code--- can still succeed if it is lazy enough in the use of the focused value.-fromWithin :: SimpleLensLike (Bazaar a a) s a -> (h :> s) -> h :> s :> a-fromWithin l (Zipper h n ls s rs) = case partsOf' l (Context id) s of-  Context k ~(a:as) -> Zipper (Snoc h l n ls k rs) 0 [] a as+-- @+-- 'fromWithin' l ≡ 'fromJust' '.' 'within' l+-- @+fromWithin :: LensLike' (Indexing (Bazaar' (Indexed Int) a)) s a -> (h :> s:@j) -> h :> s:@j :>> a+fromWithin = ifromWithin . indexing {-# INLINE fromWithin #-} +-- | Unsafey step down into an 'IndexedTraversal' that is /assumed/ to be non-empty+--+-- If this invariant is not met then this will usually result in an error!+--+-- @+-- 'ifromWithin' :: 'IndexedTraversal'' i s a -> (h ':>' s:\@j) -> h ':>' s:\@j ':>' a:\@i+-- 'ifromWithin' :: 'IndexedLens'' i s a      -> (h ':>' s:\@j) -> h ':>' s:\@j ':>' a:\@i+-- @+--+-- You can reason about this function as if the definition was:+--+-- @+-- 'fromWithin' l ≡ 'fromJust' '.' 'within' l+-- @+ifromWithin :: Ord i => AnIndexedTraversal' i s a -> (h :> s:@j) -> h :> s:@j :> a:@i+ifromWithin l (Zipper h t o p j s) = case jacket l (Context id) s of+  Context k xs -> let up = Snoc h l t o p j k in+    startl Start xs (Zipper up 0 0 Start (error "fromWithin an empty Traversal")+                                         (error "fromWithin an empty Traversal"))+                    (Zipper up 0 0)+{-# INLINE ifromWithin #-}+ -- | This enables us to pull the 'Zipper' back up to the 'Top'. class Zipping h a where-  recoil :: Coil h a -> [a] -> Zipped h a+  recoil :: Coil h i a -> Jacket i a -> Zipped h a  instance Zipping Top a where-  recoil Coil = head+  recoil Coil (Leaf _ a) = a+  recoil Coil _ = error "recoil: expected Leaf"   {-# INLINE recoil #-} -instance Zipping h s => Zipping (h :> s) a where-  recoil (Snoc h _ _ ls k rs) as = recoil h (reverseList ls ++ k as : rs)+instance Zipping h s => Zipping (Zipper h i s) a where+  recoil (Snoc h _ _ _ p i k) as = recoil h $ recompress p i (k as)   {-# INLINE recoil #-}  -- | Close something back up that you opened as a 'Zipper'.-rezip :: Zipping h a => (h :> a) -> Zipped h a-rezip (Zipper h _ ls a rs) = recoil h (reverseList ls ++ a : rs)+rezip :: Zipping h a => (h :> a:@i) -> Zipped h a+rezip (Zipper h _ _ p i a) = recoil h (recompress p i a) {-# INLINE rezip #-} --- | Extract the current 'focus' from a 'Zipper' as a 'Context'-focusedContext :: Zipping h a => (h :> a) -> Context a a (Zipped h a)-focusedContext z = Context (\a -> z & focus .~ a & rezip) (z^.focus)+-- | Extract the current 'focus' from a 'Zipper' as a 'Pretext', with access to the current index.+focusedContext :: (Indexable i p, Zipping h a) => (h :> a:@i) -> Pretext p a a (Zipped h a)+focusedContext (Zipper h t o p i a) = Pretext (\f -> rezip . Zipper h t o p i <$> indexed f i a)+{-# INLINE focusedContext #-}  ----------------------------------------------------------------------------- -- * Tapes ----------------------------------------------------------------------------- --- | A 'Tape' is a recorded path through the 'Traversal' chain of a 'Zipper'.-data Tape k where-  Tape :: Track h a -> {-# UNPACK #-} !Int -> Tape (h :> a)+-- | A 'Tape' is a recorded path through the (indexed) 'Traversal' chain of a 'Zipper'.+data Tape h i a where+  Tape :: Track h i a -> i -> Tape h i a  -- | Save the current path as as a 'Tape' we can play back later.-saveTape :: (h :> a) -> Tape (h :> a)-saveTape (Zipper h n _ _ _) = Tape (peel h) n+saveTape :: Zipper h i a -> Tape h i a+saveTape (Zipper h _ _ _ i _) = Tape (peel h) i {-# INLINE saveTape #-}  -- | Restore ourselves to a previously recorded position precisely. -- -- If the position does not exist, then fail.-restoreTape :: MonadPlus m => Tape (h :> a) -> Zipped h a -> m (h :> a)-restoreTape (Tape h n) = restoreTrack h >=> jerks rightward n+restoreTape :: MonadPlus m => Tape h i a -> Zipped h a -> m (Zipper h i a)+restoreTape (Tape h n) = restoreTrack h >=> moveTo n {-# INLINE restoreTape #-}  -- | Restore ourselves to a location near our previously recorded position. ----- When moving left to right through a 'Traversal', if this will clamp at each level to the range @0 <= k < teeth@,--- so the only failures will occur when one of the sequence of downward traversals find no targets.-restoreNearTape :: MonadPlus m => Tape (h :> a) -> Zipped h a -> m (h :> a)-restoreNearTape (Tape h n) a = liftM (tugs rightward n) (restoreNearTrack h a)+-- When moving left to right through a 'Traversal', if this will clamp at each+-- level to the range @0 '<=' k '<' 'teeth'@, so the only failures will occur+-- when one of the sequence of downward traversals find no targets.+restoreNearTape :: MonadPlus m => Tape h i a -> Zipped h a -> m (Zipper h i a)+restoreNearTape (Tape h n) a = liftM (moveToward n) (restoreNearTrack h a) {-# INLINE restoreNearTape #-}  -- | Restore ourselves to a previously recorded position. -- -- This *assumes* that nothing has been done in the meantime to affect the existence of anything on the entire path. ----- Motions leftward or rightward are clamped, but all traversals included on the 'Tape' are assumed to be non-empty.+-- Motions 'leftward' or 'rightward' are clamped, but all traversals included on the 'Tape' are assumed to be non-empty. -- -- Violate these assumptions at your own risk!-unsafelyRestoreTape :: Tape (h :> a) -> Zipped h a -> h :> a-unsafelyRestoreTape (Tape h n) = unsafelyRestoreTrack h >>> tugs rightward n+unsafelyRestoreTape :: Tape h i a -> Zipped h a -> Zipper h i a+unsafelyRestoreTape (Tape h n) = unsafelyRestoreTrack h >>> moveToward n {-# INLINE unsafelyRestoreTape #-}  -----------------------------------------------------------------------------@@ -459,56 +834,39 @@ -----------------------------------------------------------------------------  -- | This is used to peel off the path information from a 'Coil' for use when saving the current path for later replay.-peel :: Coil h a -> Track h a-peel Coil               = Track-peel (Snoc h l n _ _ _) = Fork (peel h) n l+peel :: Coil h i a -> Track h i a+peel Coil             = Track+peel (Snoc h l _ _ _ i _) = Fork (peel h) i l+{-# INLINE peel #-}  -- | The 'Track' forms the bulk of a 'Tape'.-data Track :: * -> * -> * where-  Track :: Track Top a-  Fork  :: Track h s -> {-# UNPACK #-} !Int -> SimpleLensLike (Bazaar a a) s a -> Track (h :> s) a+data Track t i a where+  Track :: Track Top Int a+  Fork  :: Ord i => Track h j s -> j -> AnIndexedTraversal' i s a -> Track (Zipper h j s) i a  -- | Restore ourselves to a previously recorded position precisely. -- -- If the position does not exist, then fail.-restoreTrack :: MonadPlus m => Track h a -> Zipped h a -> m (h :> a)-restoreTrack Track = return . zipper-restoreTrack (Fork h n l) = restoreTrack h >=> jerks rightward n >=> within l+restoreTrack :: MonadPlus m => Track h i a -> Zipped h a -> m (Zipper h i a)+restoreTrack Track        = return . zipper+restoreTrack (Fork h n l) = restoreTrack h >=> moveTo n >=> iwithin l  -- | Restore ourselves to a location near our previously recorded position. ----- When moving leftward to rightward through a 'Traversal', if this will clamp at each level to the range @0 <= k < teeth@,+-- When moving 'leftward' to 'rightward' through a 'Traversal', if this will clamp at each level to the range @0 '<=' k '<' 'teeth'@, -- so the only failures will occur when one of the sequence of downward traversals find no targets.-restoreNearTrack :: MonadPlus m => Track h a -> Zipped h a -> m (h :> a)-restoreNearTrack Track = return . zipper-restoreNearTrack (Fork h n l) = restoreNearTrack h >=> tugs rightward n >>> within l+restoreNearTrack :: MonadPlus m => Track h i a -> Zipped h a -> m (Zipper h i a)+restoreNearTrack Track        = return . zipper+restoreNearTrack (Fork h n l) = restoreNearTrack h >=> moveToward n >>> iwithin l  -- | Restore ourselves to a previously recorded position. ----- This *assumes* that nothing has been done in the meantime to affect the existence of anything on the entire path.+-- This *assumes* that nothing has been done in the meantime to affect the existence of anything on the entire 'Path'. ----- Motions leftward or rightward are clamped, but all traversals included on the 'Tape' are assumed to be non-empty.+-- Motions 'leftward' or 'rightward' are clamped, but all traversals included on the 'Tape' are assumed to be non-empty. -- -- Violate these assumptions at your own risk!-unsafelyRestoreTrack :: Track h a -> Zipped h a -> h :> a+unsafelyRestoreTrack :: Track h i a -> Zipped h a -> Zipper h i a unsafelyRestoreTrack Track = zipper-unsafelyRestoreTrack (Fork h n l) = unsafelyRestoreTrack h >>> tugs rightward n >>> fromWithin l---------------------------------------------------------------------------------- * Helper functions------------------------------------------------------------------------------+unsafelyRestoreTrack (Fork h n l) = unsafelyRestoreTrack h >>> moveToward n >>> ifromWithin l --- | Reverse a list.------ GHC doesn't optimize @reverse []@ into @[]@, so we'll nudge it with our own--- reverse function.------ This is relevant when descending into a lens, for example -- we know the--- unzipped part of the level will be empty.-reverseList :: [a] -> [a]-reverseList [] = []-reverseList (x:xs) = go [x] xs-  where-    go a [] = a-    go a (y:ys) = go (y:a) ys-{-# INLINE reverseList #-}
+ src/Control/Lens/Internal/Zoom.hs view
@@ -0,0 +1,292 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE KindSignatures #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE UndecidableInstances #-}+#ifdef TRUSTWORTHY+{-# LANGUAGE Trustworthy #-}+#endif+{-# OPTIONS_GHC -fno-warn-orphans #-}+-----------------------------------------------------------------------------+-- |+-- Module      :  Control.Lens.Internal.Zoom+-- Copyright   :  (C) 2012-2013 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  experimental+-- Portability :  non-portable+--+----------------------------------------------------------------------------+module Control.Lens.Internal.Zoom+  (+  -- * Zoom+    Zoomed+  , Focusing(..)+  , FocusingWith(..)+  , FocusingPlus(..)+  , FocusingOn(..)+  , FocusingMay(..), May(..)+  , FocusingErr(..), Err(..)+  -- * Magnify+  , Magnified+  , EffectRWS(..)+  ) where++import Control.Applicative+import Control.Category+import Control.Comonad+import Control.Lens.Internal.Action+import Control.Lens.Internal.Getter+import Control.Monad.Reader as Reader+import Control.Monad.Trans.State.Lazy as Lazy+import Control.Monad.Trans.State.Strict as Strict+import Control.Monad.Trans.Writer.Lazy as Lazy+import Control.Monad.Trans.Writer.Strict as Strict+import Control.Monad.Trans.RWS.Lazy as Lazy+import Control.Monad.Trans.RWS.Strict as Strict+import Control.Monad.Trans.Error+import Control.Monad.Trans.List+import Control.Monad.Trans.Identity+import Control.Monad.Trans.Maybe+import Data.Functor.Bind+import Data.Semigroup+import Prelude hiding ((.),id)++------------------------------------------------------------------------------+-- Zoomed+------------------------------------------------------------------------------++-- | This type family is used by 'Control.Lens.Zoom.Zoom' to describe the common effect type.+type family Zoomed (m :: * -> *) :: * -> * -> *+type instance Zoomed (Strict.StateT s z) = Focusing z+type instance Zoomed (Lazy.StateT s z) = Focusing z+type instance Zoomed (ReaderT e m) = Zoomed m+type instance Zoomed (IdentityT m) = Zoomed m+type instance Zoomed (Strict.RWST r w s z) = FocusingWith w z+type instance Zoomed (Lazy.RWST r w s z) = FocusingWith w z+type instance Zoomed (Strict.WriterT w m) = FocusingPlus w (Zoomed m)+type instance Zoomed (Lazy.WriterT w m) = FocusingPlus w (Zoomed m)+type instance Zoomed (ListT m) = FocusingOn [] (Zoomed m)+type instance Zoomed (MaybeT m) = FocusingMay (Zoomed m)+type instance Zoomed (ErrorT e m) = FocusingErr e (Zoomed m)++------------------------------------------------------------------------------+-- Focusing+------------------------------------------------------------------------------++-- | Used by 'Control.Lens.Lens.Zoom' to 'Control.Lens.Lens.zoom' into 'Control.Monad.State.StateT'.+newtype Focusing m s a = Focusing { unfocusing :: m (s, a) }++instance Monad m => Functor (Focusing m s) where+  fmap f (Focusing m) = Focusing $ do+     (s, a) <- m+     return (s, f a)+  {-# INLINE fmap #-}++instance (Monad m, Semigroup s) => Apply (Focusing m s) where+  Focusing mf <.> Focusing ma = Focusing $ do+    (s, f) <- mf+    (s', a) <- ma+    return (s <> s', f a)+  {-# INLINE (<.>) #-}++instance (Monad m, Monoid s) => Applicative (Focusing m s) where+  pure a = Focusing (return (mempty, a))+  {-# INLINE pure #-}+  Focusing mf <*> Focusing ma = Focusing $ do+    (s, f) <- mf+    (s', a) <- ma+    return (mappend s s', f a)+  {-# INLINE (<*>) #-}++------------------------------------------------------------------------------+-- FocusingWith+------------------------------------------------------------------------------++-- | Used by 'Control.Lens.Lens.Zoom' to 'Control.Lens.Lens.zoom' into 'Control.Monad.RWS.RWST'.+newtype FocusingWith w m s a = FocusingWith { unfocusingWith :: m (s, a, w) }++instance Monad m => Functor (FocusingWith w m s) where+  fmap f (FocusingWith m) = FocusingWith $ do+     (s, a, w) <- m+     return (s, f a, w)+  {-# INLINE fmap #-}++instance (Monad m, Semigroup s, Semigroup w) => Apply (FocusingWith w m s) where+  FocusingWith mf <.> FocusingWith ma = FocusingWith $ do+    (s, f, w) <- mf+    (s', a, w') <- ma+    return (s <> s', f a, w <> w')+  {-# INLINE (<.>) #-}++instance (Monad m, Monoid s, Monoid w) => Applicative (FocusingWith w m s) where+  pure a = FocusingWith (return (mempty, a, mempty))+  {-# INLINE pure #-}+  FocusingWith mf <*> FocusingWith ma = FocusingWith $ do+    (s, f, w) <- mf+    (s', a, w') <- ma+    return (mappend s s', f a, mappend w w')+  {-# INLINE (<*>) #-}++------------------------------------------------------------------------------+-- FocusingPlus+------------------------------------------------------------------------------++-- | Used by 'Control.Lens.Lens.Zoom' to 'Control.Lens.Lens.zoom' into 'Control.Monad.Writer.WriterT'.+newtype FocusingPlus w k s a = FocusingPlus { unfocusingPlus :: k (s, w) a }++instance Functor (k (s, w)) => Functor (FocusingPlus w k s) where+  fmap f (FocusingPlus as) = FocusingPlus (fmap f as)+  {-# INLINE fmap #-}++instance Apply (k (s, w)) => Apply (FocusingPlus w k s) where+  FocusingPlus kf <.> FocusingPlus ka = FocusingPlus (kf <.> ka)+  {-# INLINE (<.>) #-}++instance Applicative (k (s, w)) => Applicative (FocusingPlus w k s) where+  pure = FocusingPlus . pure+  {-# INLINE pure #-}+  FocusingPlus kf <*> FocusingPlus ka = FocusingPlus (kf <*> ka)+  {-# INLINE (<*>) #-}++------------------------------------------------------------------------------+-- FocusingOn+------------------------------------------------------------------------------++-- | Used by 'Control.Lens.Lens.Zoom' to 'Control.Lens.Lens.zoom' into 'Control.Monad.Trans.Maybe.MaybeT' or 'Control.Monad.Trans.List.ListT'.+newtype FocusingOn f k s a = FocusingOn { unfocusingOn :: k (f s) a }++instance Functor (k (f s)) => Functor (FocusingOn f k s) where+  fmap f (FocusingOn as) = FocusingOn (fmap f as)+  {-# INLINE fmap #-}++instance Apply (k (f s)) => Apply (FocusingOn f k s) where+  FocusingOn kf <.> FocusingOn ka = FocusingOn (kf <.> ka)+  {-# INLINE (<.>) #-}++instance Applicative (k (f s)) => Applicative (FocusingOn f k s) where+  pure = FocusingOn . pure+  {-# INLINE pure #-}+  FocusingOn kf <*> FocusingOn ka = FocusingOn (kf <*> ka)+  {-# INLINE (<*>) #-}++------------------------------------------------------------------------------+-- May+------------------------------------------------------------------------------++-- | Make a 'Monoid' out of 'Maybe' for error handling.+newtype May a = May { getMay :: Maybe a }++instance Semigroup a => Semigroup (May a) where+  May Nothing <> _ = May Nothing+  _ <> May Nothing = May Nothing+  May (Just a) <> May (Just b) = May (Just (a <> b))+  {-# INLINE (<>) #-}++instance Monoid a => Monoid (May a) where+  mempty = May (Just mempty)+  {-# INLINE mempty #-}+  May Nothing `mappend` _ = May Nothing+  _ `mappend` May Nothing = May Nothing+  May (Just a) `mappend` May (Just b) = May (Just (mappend a b))+  {-# INLINE mappend #-}++------------------------------------------------------------------------------+-- FocusingMay+------------------------------------------------------------------------------++-- | Used by 'Control.Lens.Lens.Zoom' to 'Control.Lens.Lens.zoom' into 'Control.Monad.Error.ErrorT'.+newtype FocusingMay k s a = FocusingMay { unfocusingMay :: k (May s) a }++instance Functor (k (May s)) => Functor (FocusingMay k s) where+  fmap f (FocusingMay as) = FocusingMay (fmap f as)+  {-# INLINE fmap #-}++instance Apply (k (May s)) => Apply (FocusingMay k s) where+  FocusingMay kf <.> FocusingMay ka = FocusingMay (kf <.> ka)+  {-# INLINE (<.>) #-}++instance Applicative (k (May s)) => Applicative (FocusingMay k s) where+  pure = FocusingMay . pure+  {-# INLINE pure #-}+  FocusingMay kf <*> FocusingMay ka = FocusingMay (kf <*> ka)+  {-# INLINE (<*>) #-}++------------------------------------------------------------------------------+-- Err+------------------------------------------------------------------------------++-- | Make a 'Monoid' out of 'Either' for error handling.+newtype Err e a = Err { getErr :: Either e a }++instance Semigroup a => Semigroup (Err e a) where+  Err (Left e) <> _ = Err (Left e)+  _ <> Err (Left e) = Err (Left e)+  Err (Right a) <> Err (Right b) = Err (Right (a <> b))+  {-# INLINE (<>) #-}++instance Monoid a => Monoid (Err e a) where+  mempty = Err (Right mempty)+  {-# INLINE mempty #-}+  Err (Left e) `mappend` _ = Err (Left e)+  _ `mappend` Err (Left e) = Err (Left e)+  Err (Right a) `mappend` Err (Right b) = Err (Right (mappend a b))+  {-# INLINE mappend #-}++------------------------------------------------------------------------------+-- FocusingErr+------------------------------------------------------------------------------++-- | Used by 'Control.Lens.Lens.Zoom' to 'Control.Lens.Lens.zoom' into 'Control.Monad.Error.ErrorT'.+newtype FocusingErr e k s a = FocusingErr { unfocusingErr :: k (Err e s) a }++instance Functor (k (Err e s)) => Functor (FocusingErr e k s) where+  fmap f (FocusingErr as) = FocusingErr (fmap f as)+  {-# INLINE fmap #-}++instance Apply (k (Err e s)) => Apply (FocusingErr e k s) where+  FocusingErr kf <.> FocusingErr ka = FocusingErr (kf <.> ka)+  {-# INLINE (<.>) #-}++instance Applicative (k (Err e s)) => Applicative (FocusingErr e k s) where+  pure = FocusingErr . pure+  {-# INLINE pure #-}+  FocusingErr kf <*> FocusingErr ka = FocusingErr (kf <*> ka)+  {-# INLINE (<*>) #-}++------------------------------------------------------------------------------+-- Magnified+------------------------------------------------------------------------------++-- | This type family is used by 'Control.Lens.Zoom.Magnify' to describe the common effect type.+type family Magnified (m :: * -> *) :: * -> * -> *+type instance Magnified (ReaderT b m) = Effect m+type instance Magnified ((->)b) = Accessor+type instance Magnified (Strict.RWST a w s m) = EffectRWS w s m+type instance Magnified (Lazy.RWST a w s m) = EffectRWS w s m+type instance Magnified (IdentityT m) = Magnified m++------------------------------------------------------------------------------+-- EffectRWS+------------------------------------------------------------------------------++-- | Wrap a monadic effect with a phantom type argument. Used when magnifying 'Control.Monad.RWS.RWST'.+newtype EffectRWS w st m s a = EffectRWS { getEffectRWS :: st -> m (s,st,w) }++instance Functor (EffectRWS w st m s) where+  fmap _ (EffectRWS m) = EffectRWS m+  {-# INLINE fmap #-}++instance (Semigroup s, Semigroup w, Bind m) => Apply (EffectRWS w st m s) where+  EffectRWS m <.> EffectRWS n = EffectRWS $ \st -> m st >>- \ (s,t,w) -> fmap (\(s',u,w') -> (s <> s', u, w <> w')) (n t)+  {-# INLINE (<.>) #-}++instance (Monoid s, Monoid w, Monad m) => Applicative (EffectRWS w st m s) where+  pure _ = EffectRWS $ \st -> return (mempty, st, mempty)+  {-# INLINE pure #-}+  EffectRWS m <*> EffectRWS n = EffectRWS $ \st -> m st >>= \ (s,t,w) -> n t >>= \ (s',u,w') -> return (mappend s s', u, mappend w w')+  {-# INLINE (<*>) #-}++instance Gettable (EffectRWS w st m s) where+  coerce (EffectRWS m) = EffectRWS m+  {-# INLINE coerce #-}
src/Control/Lens/Iso.hs view
@@ -1,21 +1,18 @@ {-# LANGUAGE CPP #-}-{-# LANGUAGE GADTs #-} {-# LANGUAGE Rank2Types #-}-{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FunctionalDependencies #-} #ifdef TRUSTWORTHY {-# LANGUAGE Trustworthy #-} #endif  #ifndef MIN_VERSION_bytestring-#define MIN_VERSION_bytestring(x,y,z)+#define MIN_VERSION_bytestring(x,y,z) 1 #endif ----------------------------------------------------------------------------- -- | -- Module      :  Control.Lens.Iso--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  provisional@@ -25,11 +22,10 @@ module Control.Lens.Iso   (   -- * Isomorphism Lenses-    Iso-  , AnIso+    Iso, Iso'+  , AnIso, AnIso'   -- * Isomorphism Construction-  , Isomorphic(..)-  , Isoid(..)+  , iso   -- * Consuming Isomorphisms   , from   , cloneIso@@ -44,24 +40,38 @@   , anon   , enum   , curried, uncurried+  , flipped+  , Swapped(..)   , Strict(..)-  -- * Simplicity-  , SimpleIso-  -- * Useful Type Families-  , CoA, CoB+  -- ** Uncommon Isomorphisms+  , magma+  , imagma+  , Magma+  -- * Profunctors+  , Profunctor(dimap,rmap,lmap)   ) where -import Control.Category-import Control.Lens.Classes-import Control.Lens.Internal+import Control.Lens.Internal.Context+import Control.Lens.Internal.Indexed+import Control.Lens.Internal.Iso+import Control.Lens.Internal.Magma+import Control.Lens.Internal.Setter import Control.Lens.Type+import Data.Bifunctor import Data.ByteString as StrictB import Data.ByteString.Lazy as LazyB import Data.Text as StrictT import Data.Text.Lazy as LazyT+import Data.Tuple (swap) import Data.Maybe-import Prelude hiding ((.),id)+import Data.Profunctor+import Data.Profunctor.Unsafe+#ifndef SAFE+import Unsafe.Coerce+#endif +{-# ANN module "HLint: ignore Use on" #-}+ -- $setup -- >>> import Control.Lens -- >>> import Data.Map as Map@@ -69,41 +79,68 @@ -- >>> import Data.Monoid  ----------------------------------------------------------------------------+-- Isomorphisms+-----------------------------------------------------------------------------++-- | When you see this as an argument to a function, it expects an 'Iso'.+type AnIso s t a b = Exchange a b a (Mutator b) -> Exchange a b s (Mutator t)++-- | A 'Simple' 'AnIso'.+type AnIso' s a = AnIso s s a a+++-- | Build a simple isomorphism from a pair of inverse functions.+--+-- @+-- 'Control.Lens.Getter.view' ('iso' f g) ≡ f+-- 'Control.Lens.Getter.view' ('Control.Lens.Iso.from' ('iso' f g)) ≡ g+-- 'Control.Lens.Setter.set' ('iso' f g) h ≡ g '.' h '.' f+-- 'Control.Lens.Setter.set' ('Control.Lens.Iso.from' ('iso' f g)) h ≡ f '.' h '.' g+-- @+iso :: (s -> a) -> (b -> t) -> Iso s t a b+iso sa bt = dimap sa (fmap bt)+{-# INLINE iso #-}++---------------------------------------------------------------------------- -- Consuming Isomorphisms -----------------------------------------------------------------------------  -- | Invert an isomorphism. ----- @'from' ('from' l) ≡ l@+-- @+-- 'from' ('from' l) ≡ l+-- @ from :: AnIso s t a b -> Iso b a t s-from Isoid       = id-from (Iso sa bt) = iso bt sa+from k = case runIso k of+  Exchange sa bt -> iso bt sa {-# INLINE from #-} --- | Convert from an 'Isomorphism' back to any 'Isomorphic' value.+-- | Convert from 'AnIso' back to any 'Iso'. -- -- This is useful when you need to store an isomorphism as a data type inside a container -- and later reconstitute it as an overloaded function. ----- See 'cloneLens' or 'Control.Lens.Traversal.cloneTraversal' for more information on why you might want to do this.+-- See 'Control.Lens.Lens.cloneLens' or 'Control.Lens.Traversal.cloneTraversal' for more information on why you might want to do this. cloneIso :: AnIso s t a b -> Iso s t a b-cloneIso Isoid       = id-cloneIso (Iso sa bt) = iso sa bt+cloneIso k = case runIso k of+  Exchange sa bt -> iso sa bt {-# INLINE cloneIso #-}  ----------------------------------------------------------------------------- -- Isomorphisms families as Lenses ----------------------------------------------------------------------------- --- | Isomorphism families can be composed with other lenses using ('.') and 'id'.-type Iso s t a b = forall k f. (Isomorphic k, Functor f) => k (a -> f b) (s -> f t)---- | When you see this as an argument to a function, it expects an 'Iso'.-type AnIso s t a b = Overloaded Isoid Mutator s t a b+-- | Extract the two functions, one from @s -> a@ and one from @b -> t@ that characterize+-- an 'Iso'.+runIso :: AnIso s t a b -> Exchange a b s t+#ifdef SAFE+runIso ai = case ai (Exchange id Mutator) of+  Exchange sa bt -> Exchange sa (runMutator #. bt)+#else+runIso ai = unsafeCoerce $ ai $ Exchange id Mutator+#endif --- |--- @type 'SimpleIso' = 'Control.Lens.Type.Simple' 'Iso'@-type SimpleIso s a = Iso s s a a+{-# INLINE runIso #-}  -- | Based on 'Control.Lens.Wrapped.ala' from Conor McBride's work on Epigram. --@@ -112,12 +149,11 @@ -- >>> au (wrapping Sum) foldMap [1,2,3,4] -- 10 au :: AnIso s t a b -> ((s -> a) -> e -> b) -> e -> t-au Isoid f e = f id e-au (Iso sa bt) f e = bt (f sa e)+au k = case runIso k of+  Exchange sa bt -> \ f e -> bt (f sa e) {-# INLINE au #-} --- |--- Based on @ala'@ from Conor McBride's work on Epigram.+-- | Based on @ala'@ from Conor McBride's work on Epigram. -- -- This version is generalized to accept any 'Iso', not just a @newtype@. --@@ -129,18 +165,22 @@ -- >>> auf (wrapping Sum) (foldMapOf both) Prelude.length ("hello","world") -- 10 auf :: AnIso s t a b -> ((r -> a) -> e -> b) -> (r -> s) -> e -> t-auf Isoid       f g e = f g e-auf (Iso sa bt) f g e = bt (f (sa . g) e)+auf k = case runIso k of+  Exchange sa bt -> \ f g e -> bt (f (sa . g) e) {-# INLINE auf #-} --- | The opposite of working 'over' a Setter is working 'under' an Isomorphism.+-- | The opposite of working 'Control.Lens.Setter.over' a 'Setter' is working 'under' an isomorphism. ----- @'under' ≡ 'over' '.' 'from'@+-- @+-- 'under' ≡ 'Control.Lens.Setter.over' '.' 'from'+-- @ ----- @'under' :: 'Iso' s t a b -> (s -> t) -> a -> b@+-- @+-- 'under' :: 'Iso' s t a b -> (s -> t) -> a -> b+-- @ under :: AnIso s t a b -> (t -> s) -> b -> a-under Isoid       ts b = ts b-under (Iso sa bt) ts b = sa (ts (bt b))+under k = case runIso k of+  Exchange sa bt -> \ts -> sa . ts . bt {-# INLINE under #-}  -----------------------------------------------------------------------------@@ -160,30 +200,30 @@ -- 'Enum' instances for 'Double', and 'Float' that exist solely for -- @[1.0 .. 4.0]@ sugar and the instances for those and 'Integer' don't -- cover all values in their range.-enum :: Enum a => Simple Iso Int a+enum :: Enum a => Iso' Int a enum = iso toEnum fromEnum {-# INLINE enum #-} --- | This can be used to lift any 'SimpleIso' into an arbitrary functor.+-- | This can be used to lift any 'Iso' into an arbitrary 'Functor'. mapping :: Functor f => AnIso s t a b -> Iso (f s) (f t) (f a) (f b)-mapping Isoid       = id-mapping (Iso sa bt) = iso (fmap sa) (fmap bt)+mapping k = case runIso k of+  Exchange sa bt -> iso (fmap sa) (fmap bt) {-# INLINE mapping #-}  -- | Composition with this isomorphism is occasionally useful when your 'Lens', -- 'Control.Lens.Traversal.Traversal' or 'Iso' has a constraint on an unused -- argument to force that argument to agree with the -- type of a used argument and avoid @ScopedTypeVariables@ or other ugliness.-simple :: Simple Iso a a+simple :: Iso' a a simple = id {-# INLINE simple #-} --- | If @v@ is an element of a type @a@, and @a'@ is @a@ sans the element @v@, then @non v@ is an isomorphism from--- @Maybe a'@ to @a@.+-- | If @v@ is an element of a type @a@, and @a'@ is @a@ sans the element @v@, then @'non' v@ is an isomorphism from+-- @'Maybe' a'@ to @a@. ----- Keep in mind this is only a real isomorphism if you treat the domain as being @'Maybe' (a sans v)@+-- Keep in mind this is only a real isomorphism if you treat the domain as being @'Maybe' (a sans v)@. ----- This is practically quite useful when you want to have a map where all the entries should have non-zero values.+-- This is practically quite useful when you want to have a 'Data.Map.Map' where all the entries should have non-zero values. -- -- >>> Map.fromList [("hello",1)] & at "hello" . non 0 +~ 2 -- fromList [("hello",3)]@@ -199,30 +239,30 @@ -- -- This combinator is also particularly useful when working with nested maps. ----- /e.g./ When you want to create the nested map when it is missing:+-- /e.g./ When you want to create the nested 'Data.Map.Map' when it is missing: -- -- >>> Map.empty & at "hello" . non Map.empty . at "world" ?~ "!!!" -- fromList [("hello",fromList [("world","!!!")])] ----- and when have deleting the last entry from the nested map mean that we+-- and when have deleting the last entry from the nested 'Data.Map.Map' mean that we -- should delete its entry from the surrounding one: -- -- >>> fromList [("hello",fromList [("world","!!!")])] & at "hello" . non Map.empty . at "world" .~ Nothing -- fromList []-non :: Eq a => a -> Simple Iso (Maybe a) a+non :: Eq a => a -> Iso' (Maybe a) a non a = anon a (a==) {-# INLINE non #-}  -- | @'anon' a p@ generalizes @'non' a@ to take any value and a predicate. ----- This function assumes that @p a@ holds @True@ and generates an isomorphism between @'Maybe' (a | not (p a))@ and @a@+-- This function assumes that @p a@ holds @'True'@ and generates an isomorphism between @'Maybe' (a | 'not' (p a))@ and @a@. -- -- >>> Map.empty & at "hello" . anon Map.empty Map.null . at "world" ?~ "!!!" -- fromList [("hello",fromList [("world","!!!")])] -- -- >>> fromList [("hello",fromList [("world","!!!")])] & at "hello" . anon Map.empty Map.null . at "world" .~ Nothing -- fromList []-anon :: a -> (a -> Bool) -> Simple Iso (Maybe a) a+anon :: a -> (a -> Bool) -> Iso' (Maybe a) a anon a p = iso (fromMaybe a) go where   go b | p b       = Nothing        | otherwise = Just b@@ -230,26 +270,54 @@  -- | The canonical isomorphism for currying and uncurrying a function. ----- @'curried' = 'iso' 'curry' 'uncurry'@+-- @+-- 'curried' = 'iso' 'curry' 'uncurry'+-- @ curried :: Iso ((a,b) -> c) ((d,e) -> f) (a -> b -> c) (d -> e -> f) curried = iso curry uncurry {-# INLINE curried #-}  -- | The canonical isomorphism for uncurrying and currying a function. ----- @'uncurried' = 'iso' 'uncurry' 'curry'@+-- @+-- 'uncurried' = 'iso' 'uncurry' 'curry'+-- @ ----- @'uncurried' = 'from' 'curried'@+-- @+-- 'uncurried' = 'from' 'curried'+-- @ uncurried :: Iso (a -> b -> c) (d -> e -> f) ((a,b) -> c) ((d,e) -> f) uncurried = iso uncurry curry {-# INLINE uncurried #-} +-- | The isomorphism for flipping a function.+flipped :: Iso (a -> b -> c) (a' -> b' -> c') (b -> a -> c) (b' -> a' -> c')+flipped = iso flip flip+{-# INLINE flipped #-}++-- | This class provides for symmetric bifunctors.+class Bifunctor p => Swapped p where+  -- |+  -- @+  -- 'swapped' '.' 'swapped' ≡ 'id'+  -- 'first' f '.' 'swapped' = 'swapped' '.' 'second' f+  -- 'second' g '.' 'swapped' = 'swapped' '.' 'first' g+  -- 'bimap' f g '.' 'swapped' = 'swapped' '.' 'bimap' g f+  -- @+  swapped :: Iso (p a b) (p c d) (p b a) (p d c)++instance Swapped (,) where+  swapped = iso swap swap++instance Swapped Either where+  swapped = iso (either Right Left) (either Right Left)+ -- | Ad hoc conversion between \"strict\" and \"lazy\" versions of a structure, -- such as 'StrictT.Text' or 'StrictB.ByteString'.-class Strict s t a b | s -> a, a -> s, b -> t, t -> b, s b -> a t, a t -> s b where-  strict :: Iso s t a b+class Strict s a | s -> a, a -> s where+  strict :: Iso' s a -instance Strict LazyB.ByteString LazyB.ByteString StrictB.ByteString StrictB.ByteString where+instance Strict LazyB.ByteString StrictB.ByteString where #if MIN_VERSION_bytestring(0,10,0)   strict = iso LazyB.toStrict LazyB.fromStrict #else@@ -257,6 +325,24 @@ #endif   {-# INLINE strict #-} -instance Strict LazyT.Text LazyT.Text StrictT.Text StrictT.Text where+instance Strict LazyT.Text StrictT.Text where   strict = iso LazyT.toStrict LazyT.fromStrict   {-# INLINE strict #-}++------------------------------------------------------------------------------+-- Magma+------------------------------------------------------------------------------++-- | This isomorphism can be used to inspect a 'Traversal' to see how it associates+-- the structure and it can also be used to bake the 'Traversal' into a 'Magma' so+-- that you can traverse over it multiple times.+magma :: LensLike (Mafic a b) s t a b -> Iso s u (Magma Int t b a) (Magma j u c c)+magma l = iso (runMafic `rmap` l sell) runMagma+{-# INLINE magma #-}++-- | This isomorphism can be used to inspect an 'IndexedTraversal' to see how it associates+-- the structure and it can also be used to bake the 'IndexedTraversal' into a 'Magma' so+-- that you can traverse over it multiple times with access to the original indices.+imagma :: Overloading (Indexed i) (->) (Molten i a b) s t a b -> Iso s t' (Magma i t b a) (Magma j t' c c)+imagma l = iso (runMolten #. l sell) (iextract .# Molten)+{-# INLINE imagma #-}
+ src/Control/Lens/Lens.hs view
@@ -0,0 +1,930 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE GADTs #-}+{-# LANGUAGE Rank2Types #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE MultiParamTypeClasses #-}+#ifdef TRUSTWORTHY+{-# LANGUAGE Trustworthy #-}+#endif++#ifndef MIN_VERSION_mtl+#define MIN_VERSION_mtl(x,y,z) 1+#endif+-------------------------------------------------------------------------------+-- |+-- Module      :  Control.Lens.Lens+-- Copyright   :  (C) 2012-13 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  provisional+-- Portability :  Rank2Types+--+-- A @'Lens' s t a b@ is a purely functional reference.+--+-- While a 'Control.Lens.Traversal.Traversal' could be used for+-- 'Control.Lens.Getter.Getting' like a valid 'Control.Lens.Fold.Fold',+-- it wasn't a valid 'Control.Lens.Getter.Getter' as 'Applicative' wasn't a superclass of+-- 'Control.Lens.Getter.Gettable'.+--+-- 'Functor', however is the superclass of both.+--+-- @+-- type 'Lens' s t a b = forall f. 'Functor' f => (a -> f b) -> s -> f t+-- @+--+-- Every 'Lens' is a valid 'Control.Lens.Setter.Setter'.+--+-- Every 'Lens' can be used for 'Control.Lens.Getter.Getting' like a+-- 'Control.Lens.Fold.Fold' that doesn't use the 'Applicative' or+-- 'Control.Lens.Getter.Gettable'.+--+-- Every 'Lens' is a valid 'Control.Lens.Traversal.Traversal' that only uses+-- the 'Functor' part of the 'Applicative' it is supplied.+--+-- Every 'Lens' can be used for 'Control.Lens.Getter.Getting' like a valid+-- 'Control.Lens.Getter.Getter', since 'Functor' is a superclass of 'Control.Lens.Getter.Gettable'.+--+-- Since every 'Lens' can be used for 'Control.Lens.Getter.Getting' like a+-- valid 'Control.Lens.Getter.Getter' it follows that it must view exactly one element in the+-- structure.+--+-- The 'Lens' laws follow from this property and the desire for it to act like+-- a 'Data.Traversable.Traversable' when used as a+-- 'Control.Lens.Traversal.Traversal'.+--+-- In the examples below, 'getter' and 'setter' are supplied as example getters+-- and setters, and are not actual functions supplied by this package.+-------------------------------------------------------------------------------+module Control.Lens.Lens+  (+  -- * Lenses+    Lens, Lens'+  , IndexedLens, IndexedLens'+  -- ** Concrete Lenses+  , ALens, ALens'+  , AnIndexedLens, AnIndexedLens'++  -- * Combinators+  , lens, ilens, iplens+  , (%%~), (%%=)+  , (%%@~), (%%@=)+  , (<%@~), (<%@=)++  -- * Lateral Composition+  , choosing+  , chosen+  , alongside+  , inside++  -- * Setting Functionally with Passthrough+  , (<%~), (<+~), (<-~), (<*~), (<//~)+  , (<^~), (<^^~), (<**~)+  , (<||~), (<&&~), (<<>~)+  , (<<%~), (<<.~)++  -- * Setting State with Passthrough+  , (<%=), (<+=), (<-=), (<*=), (<//=)+  , (<^=), (<^^=), (<**=)+  , (<||=), (<&&=), (<<>=)+  , (<<%=), (<<.=)+  , (<<~)++  -- * Cloning Lenses+  , cloneLens+  , cloneIndexPreservingLens+  , cloneIndexedLens++  -- * ALens Combinators+  , storing+  , (^#)+  , ( #~ ), ( #%~ ), ( #%%~ ), (<#~), (<#%~)+  , ( #= ), ( #%= ), ( #%%= ), (<#=), (<#%=)++  -- * Context+  , Context(..)+  , Context'+  , locus+  ) where++import Control.Applicative+import Control.Comonad+import Control.Lens.Combinators+import Control.Lens.Internal.Context+import Control.Lens.Internal.Indexed+import Control.Lens.Type+import Control.Monad.State as State+import Data.Monoid+import Data.Profunctor+import Data.Profunctor.Rep+import Data.Profunctor.Unsafe++{-# ANN module "HLint: ignore Use ***" #-}++-- $setup+-- >>> import Control.Lens+-- >>> import Debug.SimpleReflect.Expr+-- >>> import Debug.SimpleReflect.Vars as Vars hiding (f,g,h)+-- >>> let f :: Expr -> Expr; f = Debug.SimpleReflect.Vars.f+-- >>> let g :: Expr -> Expr; g = Debug.SimpleReflect.Vars.g+-- >>> let h :: Expr -> Expr -> Expr; h = Debug.SimpleReflect.Vars.h+-- >>> let getter :: Expr -> Expr; getter = fun "getter"+-- >>> let setter :: Expr -> Expr -> Expr; setter = fun "setter"++infixl 8 ^#+infixr 4 %%@~, <%@~, %%~, <+~, <*~, <-~, <//~, <^~, <^^~, <**~, <&&~, <||~, <<>~, <%~, <<%~, <<.~, <#~, #~, #%~, <#%~, #%%~+infix  4 %%@=, <%@=, %%=, <+=, <*=, <-=, <//=, <^=, <^^=, <**=, <&&=, <||=, <<>=, <%=, <<%=, <<.=, <#=, #=, #%=, <#%=, #%%=+infixr 2 <<~++-------------------------------------------------------------------------------+-- Lenses+-------------------------------------------------------------------------------++-- | When you see this as an argument to a function, it expects a 'Lens'.+--+-- This type can also be used when you need to store a 'Lens' in a container,+-- since it is rank-1. You can turn them back into a 'Lens' with 'cloneLens',+-- or use it directly with combinators like 'storing' and ('^#').+type ALens s t a b = LensLike (Pretext (->) a b) s t a b++-- | @+-- type 'ALens'' = 'Simple' 'ALens'+-- @+type ALens' s a = ALens s s a a++-- | When you see this as an argument to a function, it expects an 'IndexedLens'+type AnIndexedLens i s t a b = Overloading (Indexed i) (->) (Pretext (Indexed i) a b) s t a b++-- | @+-- type 'AnIndexedLens'' = 'Simple' ('AnIndexedLens' i)+-- @+type AnIndexedLens' i s a  = AnIndexedLens i s s a a++--------------------------+-- Constructing Lenses+--------------------------++-- | Build a 'Lens' from a getter and a setter.+--+-- @+-- 'lens' :: 'Functor' f => (s -> a) -> (s -> b -> t) -> (a -> f b) -> s -> f t+-- @+--+-- >>> s ^. lens getter setter+-- getter s+--+-- >>> s & lens getter setter .~ b+-- setter s b+--+-- >>> s & lens getter setter %~ f+-- setter s (f (getter s))+--+lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b+lens sa sbt afb s = sbt s <$> afb (sa s)+{-# INLINE lens #-}++-- | Build an index-preserving 'Lens' from a 'Control.Lens.Getter.Getter' and a 'Control.Lens.Setter.Setter'.+--+-- @+-- 'lens' :: (s -> a) -> (s -> b -> t) -> 'Lens' s t a b+-- 'lens' sa sbt afb s = sbt s '<$>' afb (sa s)+-- @+iplens :: (Conjoined p, Functor f) => (s -> a) -> (s -> b -> t) -> Overloaded p f s t a b+iplens sa sbt pafb = cotabulate $ \ws -> sbt (extract ws) <$> corep pafb (sa <$> ws)+{-# INLINE iplens #-}++-- | Build an 'IndexedLens' from a 'Control.Lens.Getter.Getter' and+-- a 'Control.Lens.Setter.Setter'.+ilens :: (s -> (i, a)) -> (s -> b -> t) -> IndexedLens i s t a b+ilens sia sbt iafb s = sbt s <$> uncurry (indexed iafb) (sia s)+{-# INLINE ilens #-}++-- | ('%%~') can be used in one of two scenarios:+--+-- When applied to a 'Lens', it can edit the target of the 'Lens' in a+-- structure, extracting a functorial result.+--+-- When applied to a 'Traversal', it can edit the+-- targets of the traversals, extracting an applicative summary of its+-- actions.+--+-- For all that the definition of this combinator is just:+--+-- @+-- ('%%~') ≡ 'id'+-- @+--+-- It may be beneficial to think about it as if it had these even more+-- restricted types, however:+--+-- @+-- ('%%~') :: 'Functor' f =>     'Control.Lens.Iso.Iso' s t a b       -> (a -> f b) -> s -> f t+-- ('%%~') :: 'Functor' f =>     'Lens' s t a b      -> (a -> f b) -> s -> f t+-- ('%%~') :: 'Applicative' f => 'Control.Lens.Traversal.Traversal' s t a b -> (a -> f b) -> s -> f t+-- @+--+-- When applied to a 'Traversal', it can edit the+-- targets of the traversals, extracting a supplemental monoidal summary+-- of its actions, by choosing @f = ((,) m)@+--+-- @+-- ('%%~') ::             'Control.Lens.Iso.Iso' s t a b       -> (a -> (r, b)) -> s -> (r, t)+-- ('%%~') ::             'Lens' s t a b      -> (a -> (r, b)) -> s -> (r, t)+-- ('%%~') :: 'Monoid' m => 'Control.Lens.Traversal.Traversal' s t a b -> (a -> (m, b)) -> s -> (m, t)+-- @+(%%~) :: Overloading p q f s t a b -> p a (f b) -> q s (f t)+(%%~) = id+{-# INLINE (%%~) #-}++-- | Modify the target of a 'Lens' in the current state returning some extra+-- information of type @r@ or modify all targets of a+-- 'Control.Lens.Traversal.Traversal' in the current state, extracting extra+-- information of type @r@ and return a monoidal summary of the changes.+--+-- >>> runState (_1 %%= \x -> (f x, g x)) (a,b)+-- (f a,(g a,b))+--+-- @+-- ('%%=') ≡ ('state' '.')+-- @+--+-- It may be useful to think of ('%%='), instead, as having either of the+-- following more restricted type signatures:+--+-- @+-- ('%%=') :: 'MonadState' s m             => 'Control.Lens.Iso.Iso' s s a b       -> (a -> (r, b)) -> m r+-- ('%%=') :: 'MonadState' s m             => 'Lens' s s a b      -> (a -> (r, b)) -> m r+-- ('%%=') :: ('MonadState' s m, 'Monoid' r) => 'Control.Lens.Traversal.Traversal' s s a b -> (a -> (r, b)) -> m r+-- @+(%%=) :: MonadState s m => Overloading p (->) ((,) r) s s a b -> p a (r, b) -> m r+#if MIN_VERSION_mtl(2,1,1)+l %%= f = State.state (l f)+#else+l %%= f = do+  (r, s) <- State.gets (l f)+  State.put s+  return r+#endif+{-# INLINE (%%=) #-}++-------------------------------------------------------------------------------+-- Common Lenses+-------------------------------------------------------------------------------++-- | Lift a 'Lens' so it can run under a function.+--+inside :: ALens s t a b -> Lens (e -> s) (e -> t) (e -> a) (e -> b)+inside l f es = o <$> f i where+  i e = ipos (l sell (es e))+  o ea e = ipeek (ea e) (l sell (es e))+--  i e = case l (Context id) (es e) of Context _ a -> a+--  o ea e = case l (Context id) (es e) of Context k _ -> k (ea e)+{-# INLINE inside #-}++-- | Merge two lenses, getters, setters, folds or traversals.+--+-- @+-- 'chosen' ≡ 'choosing' 'id' 'id'+-- @+--+-- @+-- 'choosing' :: 'Control.Lens.Getter.Getter' s a     -> 'Control.Lens.Getter.Getter' s' a     -> 'Control.Lens.Getter.Getter' ('Either' s s') a+-- 'choosing' :: 'Control.Lens.Fold.Fold' s a       -> 'Control.Lens.Fold.Fold' s' a       -> 'Control.Lens.Fold.Fold' ('Either' s s') a+-- 'choosing' :: 'Lens'' s a      -> 'Lens'' s' a      -> 'Lens'' ('Either' s s') a+-- 'choosing' :: 'Control.Lens.Traversal.Traversal'' s a -> 'Control.Lens.Traversal.Traversal'' s' a -> 'Control.Lens.Traversal.Traversal'' ('Either' s s') a+-- 'choosing' :: 'Control.Lens.Setter.Setter'' s a    -> 'Control.Lens.Setter.Setter'' s' a    -> 'Control.Lens.Setter.Setter'' ('Either' s s') a+-- @+choosing :: Functor f+       => LensLike f s t a b+       -> LensLike f s' t' a b+       -> LensLike f (Either s s') (Either t t') a b+choosing l _ f (Left a)   = Left <$> l f a+choosing _ r f (Right a') = Right <$> r f a'+{-# INLINE choosing #-}++-- | This is a 'Lens' that updates either side of an 'Either', where both sides have the same type.+--+-- @+-- 'chosen' ≡ 'choosing' 'id' 'id'+-- @+--+-- >>> Left a^.chosen+-- a+--+-- >>> Right a^.chosen+-- a+--+-- >>> Right "hello"^.chosen+-- "hello"+--+-- >>> Right a & chosen *~ b+-- Right (a * b)+--+-- @+-- 'chosen' :: 'Lens' ('Either' a a) ('Either' b b) a b+-- 'chosen' f ('Left' a)  = 'Left' '<$>' f a+-- 'chosen' f ('Right' a) = 'Right' '<$>' f a+-- @+chosen :: IndexPreservingLens (Either a a) (Either b b) a b+chosen pafb = cotabulate $ \weaa -> corep (either id id `lmap` pafb) weaa <&> \b -> case extract weaa of+  Left _  -> Left  b+  Right _ -> Right b+{-# INLINE chosen #-}++-- | 'alongside' makes a 'Lens' from two other lenses.+--+-- >>> (Left a, Right b)^.alongside chosen chosen+-- (a,b)+--+-- >>> (Left a, Right b) & alongside chosen chosen .~ (c,d)+-- (Left c,Right d)+--+-- @+-- 'alongside' :: 'Lens' s t a b -> 'Lens' s' t' a' b' -> 'Lens' (s,s') (t,t') (a,a') (b,b')+-- @+alongside :: ALens s t a b -> ALens s' t' a' b' -> Lens (s,s') (t,t') (a,a') (b,b')+alongside l r f (s, s') = f (ipos ls, ipos rs) <&> \(b, b') -> (ipeek b ls, ipeek b' rs) where+  ls = l sell s+  rs = r sell s'+{-# INLINE alongside #-}++-- | This 'Lens' lets you 'view' the current 'pos' of any indexed+-- store comonad and 'seek' to a new position. This reduces the API+-- for working these instances to a single 'Lens'.+--+-- @+-- 'ipos' w ≡ w 'Control.Lens.Getter.^.' 'locus'+-- 'iseek' s w ≡ w '&' 'locus' 'Control.Lens.Setter..~' s+-- 'iseeks' f w ≡ w '&' 'locus' 'Control.Lens.Setter.%~' f+-- @+--+-- @+-- 'locus' :: 'Lens'' ('Context'' a s) a+-- 'locus' :: 'Lens'' ('Pretext'' p a s) a+-- 'locus' :: 'Lens'' ('PretextT'' p g a s) a+-- @+locus :: IndexedComonadStore p => Lens (p a c s) (p b c s) a b+locus f w = (`iseek` w) <$> f (ipos w)+{-# INLINE locus #-}++-------------------------------------------------------------------------------+-- Cloning Lenses+-------------------------------------------------------------------------------++-- | Cloning a 'Lens' is one way to make sure you aren't given+-- something weaker, such as a 'Control.Lens.Traversal.Traversal' and can be+-- used as a way to pass around lenses that have to be monomorphic in @f@.+--+-- Note: This only accepts a proper 'Lens'.+--+-- >>> let example l x = set (cloneLens l) (x^.cloneLens l + 1) x in example _2 ("hello",1,"you")+-- ("hello",2,"you")+cloneLens :: ALens s t a b -> Lens s t a b+cloneLens l afb s = runPretext (l sell s) afb+{-# INLINE cloneLens #-}++-- | Clone a 'Lens' as an 'IndexedPreservingLens' that just passes through whatever+-- index is on any 'IndexedLens', 'IndexedFold', 'IndexedGetter' or  'IndexedTraversal' it is composed with.+cloneIndexPreservingLens :: ALens s t a b -> IndexPreservingLens s t a b+cloneIndexPreservingLens l pafb = cotabulate $ \ws -> runPretext (l sell (extract ws)) $ \a -> corep pafb (a <$ ws)+{-# INLINE cloneIndexPreservingLens #-}++-- | Clone an 'IndexedLens' as an 'IndexedLens' with the same index.+cloneIndexedLens :: AnIndexedLens i s t a b -> IndexedLens i s t a b+cloneIndexedLens l f s = runPretext (l sell s) (Indexed (indexed f))+{-# INLINE cloneIndexedLens #-}++-------------------------------------------------------------------------------+-- Setting and Remembering+-------------------------------------------------------------------------------++-- | Modify the target of a 'Lens' and return the result.+--+-- When you do not need the result of the addition, ('Control.Lens.Setter.%~') is more flexible.+--+-- @+-- ('<%~') ::             'Lens' s t a b      -> (a -> b) -> s -> (b, t)+-- ('<%~') ::             'Control.Lens.Iso.Iso' s t a b       -> (a -> b) -> s -> (b, t)+-- ('<%~') :: 'Monoid' b => 'Control.Lens.Traversal.Traversal' s t a b -> (a -> b) -> s -> (b, t)+-- @+(<%~) :: Profunctor p => Overloading p q ((,) b) s t a b -> p a b -> q s (b, t)+l <%~ f = l $ rmap (\t -> (t, t)) f+{-# INLINE (<%~) #-}++-- | Increment the target of a numerically valued 'Lens' and return the result.+--+-- When you do not need the result of the addition, ('Control.Lens.Setter.+~') is more flexible.+--+-- @+-- ('<+~') :: 'Num' a => 'Lens'' s a -> a -> s -> (a, s)+-- ('<+~') :: 'Num' a => 'Control.Lens.Iso.Iso'' s a  -> a -> s -> (a, s)+-- @+(<+~) :: Num a => Overloading (->) q ((,)a) s t a a -> a -> q s (a, t)+l <+~ a = l <%~ (+ a)+{-# INLINE (<+~) #-}++-- | Decrement the target of a numerically valued 'Lens' and return the result.+--+-- When you do not need the result of the subtraction, ('Control.Lens.Setter.-~') is more flexible.+--+-- @+-- ('<-~') :: 'Num' a => 'Lens'' s a -> a -> s -> (a, s)+-- ('<-~') :: 'Num' a => 'Control.Lens.Iso.Iso'' s a  -> a -> s -> (a, s)+-- @+(<-~) :: Num a => Overloading (->) q ((,)a) s t a a -> a -> q s (a, t)+l <-~ a = l <%~ subtract a+{-# INLINE (<-~) #-}++-- | Multiply the target of a numerically valued 'Lens' and return the result.+--+-- When you do not need the result of the multiplication, ('Control.Lens.Setter.*~') is more+-- flexible.+--+-- @+-- ('<*~') :: 'Num' b => 'Lens'' s a -> a -> a -> (s, a)+-- ('<*~') :: 'Num' b => 'Control.Lens.Iso.Iso''  s a -> a -> a -> (s, a)+-- @+(<*~) :: Num a => Overloading (->) q ((,)a) s t a a -> a -> q s (a, t)+l <*~ a = l <%~ (* a)+{-# INLINE (<*~) #-}++-- | Divide the target of a fractionally valued 'Lens' and return the result.+--+-- When you do not need the result of the division, ('Control.Lens.Setter.//~') is more flexible.+--+-- @+-- ('<//~') :: 'Fractional' b => 'Lens'' s a -> a -> a -> (s, a)+-- ('<//~') :: 'Fractional' b => 'Control.Lens.Iso.Iso''  s a -> a -> a -> (s, a)+-- @+(<//~) :: Fractional a => Overloading (->) q ((,)a) s t a a -> a -> q s (a, t)+l <//~ a = l <%~ (/ a)+{-# INLINE (<//~) #-}++-- | Raise the target of a numerically valued 'Lens' to a non-negative+-- 'Integral' power and return the result.+--+-- When you do not need the result of the division, ('Control.Lens.Setter.^~') is more flexible.+--+-- @+-- ('<^~') :: ('Num' b, 'Integral' e) => 'Lens'' s a -> e -> a -> (a, s)+-- ('<^~') :: ('Num' b, 'Integral' e) => 'Control.Lens.Iso.Iso'' s a -> e -> a -> (a, s)+-- @+(<^~) :: (Num a, Integral e) => Overloading (->) q ((,)a) s t a a -> e -> q s (a, t)+l <^~ e = l <%~ (^ e)+{-# INLINE (<^~) #-}++-- | Raise the target of a fractionally valued 'Lens' to an 'Integral' power+-- and return the result.+--+-- When you do not need the result of the division, ('Control.Lens.Setter.^^~') is more flexible.+--+-- @+-- ('<^^~') :: ('Fractional' b, 'Integral' e) => 'Lens'' s a -> e -> a -> (a, s)+-- ('<^^~') :: ('Fractional' b, 'Integral' e) => 'Control.Lens.Iso.Iso'' s a -> e -> a -> (a, s)+-- @+(<^^~) :: (Fractional a, Integral e) => Overloading (->) q ((,)a) s t a a -> e -> q s (a, t)+l <^^~ e = l <%~ (^^ e)+{-# INLINE (<^^~) #-}++-- | Raise the target of a floating-point valued 'Lens' to an arbitrary power+-- and return the result.+--+-- When you do not need the result of the division, ('Control.Lens.Setter.**~') is more flexible.+--+-- @+-- ('<**~') :: 'Floating' a => 'Lens'' s a -> a -> s -> (a, s)+-- ('<**~') :: 'Floating' a => 'Control.Lens.Iso.Iso'' s a  -> a -> s -> (a, s)+-- @+(<**~) :: Floating a => Overloading (->) q ((,)a) s t a a -> a -> q s (a, t)+l <**~ a = l <%~ (** a)+{-# INLINE (<**~) #-}++-- | Logically '||' a Boolean valued 'Lens' and return the result.+--+-- When you do not need the result of the operation, ('Control.Lens.Setter.||~') is more flexible.+--+-- @+-- ('<||~') :: 'Lens'' s 'Bool' -> 'Bool' -> s -> ('Bool', s)+-- ('<||~') :: 'Control.Lens.Iso.Iso'' s 'Bool'  -> 'Bool' -> s -> ('Bool', s)+-- @+(<||~) :: Overloading (->) q ((,)Bool) s t Bool Bool -> Bool -> q s (Bool, t)+l <||~ b = l <%~ (|| b)+{-# INLINE (<||~) #-}++-- | Logically '&&' a Boolean valued 'Lens' and return the result.+--+-- When you do not need the result of the operation, ('Control.Lens.Setter.&&~') is more flexible.+--+-- @+-- ('<&&~') :: 'Lens'' s 'Bool' -> 'Bool' -> s -> ('Bool', s)+-- ('<&&~') :: 'Control.Lens.Iso.Iso'' s 'Bool'  -> 'Bool' -> s -> ('Bool', s)+-- @+(<&&~) :: Overloading (->) q ((,)Bool) s t Bool Bool -> Bool -> q s (Bool, t)+l <&&~ b = l <%~ (&& b)+{-# INLINE (<&&~) #-}++-- | Modify the target of a 'Lens', but return the old value.+--+-- When you do not need the result of the addition, ('Control.Lens.Setter.%~') is more flexible.+--+-- @+-- ('<<%~') ::             'Lens' s t a b      -> (a -> b) -> s -> (b, t)+-- ('<<%~') ::             'Control.Lens.Iso.Iso' s t a b       -> (a -> b) -> s -> (b, t)+-- ('<<%~') :: 'Monoid' b => 'Control.Lens.Traversal.Traversal' s t a b -> (a -> b) -> s -> (b, t)+-- @+(<<%~) :: Strong p => Overloading p q ((,)a) s t a b -> p a b -> q s (a, t)+(<<%~) l = l . lmap (\a -> (a, a)) . second'+{-# INLINE (<<%~) #-}++-- | Modify the target of a 'Lens', but return the old value.+--+-- When you do not need the old value, ('Control.Lens.Setter.%~') is more flexible.+--+-- @+-- ('<<%~') ::             'Lens' s t a b      -> b -> s -> (a, t)+-- ('<<%~') ::             'Control.Lens.Iso.Iso' s t a b       -> b -> s -> (a, t)+-- ('<<%~') :: 'Monoid' b => 'Control.Lens.Traversal.Traversal' s t a b -> b -> s -> (a, t)+-- @+(<<.~) :: Overloading (->) q ((,)a) s t a b -> b -> q s (a, t)+l <<.~ b = l $ \a -> (a, b)+{-# INLINE (<<.~) #-}++-------------------------------------------------------------------------------+-- Setting and Remembering State+-------------------------------------------------------------------------------++-- | Modify the target of a 'Lens' into your 'Monad'\'s state by a user supplied+-- function and return the result.+--+-- When applied to a 'Control.Lens.Traversal.Traversal', it this will return a monoidal summary of all of the intermediate+-- results.+--+-- When you do not need the result of the operation, ('Control.Lens.Setter.%=') is more flexible.+--+-- @+-- ('<%=') :: 'MonadState' s m             => 'Lens'' s a      -> (a -> a) -> m a+-- ('<%=') :: 'MonadState' s m             => 'Control.Lens.Iso.Iso'' s a       -> (a -> a) -> m a+-- ('<%=') :: ('MonadState' s m, 'Monoid' a) => 'Control.Lens.Traversal.Traversal'' s a -> (a -> a) -> m a+-- @+(<%=) :: (Profunctor p, MonadState s m) => Overloading p (->) ((,)b) s s a b -> p a b -> m b+l <%= f = l %%= rmap (\b -> (b, b)) f+{-# INLINE (<%=) #-}+++-- | Add to the target of a numerically valued 'Lens' into your 'Monad'\'s state+-- and return the result.+--+-- When you do not need the result of the addition, ('Control.Lens.Setter.+=') is more+-- flexible.+--+-- @+-- ('<+=') :: ('MonadState' s m, 'Num' a) => 'Lens'' s a -> a -> m a+-- ('<+=') :: ('MonadState' s m, 'Num' a) => 'Control.Lens.Iso.Iso'' s a -> a -> m a+-- @+(<+=) :: (MonadState s m, Num a) => LensLike' ((,)a) s a -> a -> m a+l <+= a = l <%= (+ a)+{-# INLINE (<+=) #-}++-- | Subtract from the target of a numerically valued 'Lens' into your 'Monad'\'s+-- state and return the result.+--+-- When you do not need the result of the subtraction, ('Control.Lens.Setter.-=') is more+-- flexible.+--+-- @+-- ('<-=') :: ('MonadState' s m, 'Num' a) => 'Lens'' s a -> a -> m a+-- ('<-=') :: ('MonadState' s m, 'Num' a) => 'Control.Lens.Iso.Iso'' s a -> a -> m a+-- @+(<-=) :: (MonadState s m, Num a) => LensLike' ((,)a) s a -> a -> m a+l <-= a = l <%= subtract a+{-# INLINE (<-=) #-}++-- | Multiply the target of a numerically valued 'Lens' into your 'Monad'\'s+-- state and return the result.+--+-- When you do not need the result of the multiplication, ('Control.Lens.Setter.*=') is more+-- flexible.+--+-- @+-- ('<*=') :: ('MonadState' s m, 'Num' a) => 'Lens'' s a -> a -> m a+-- ('<*=') :: ('MonadState' s m, 'Num' a) => 'Control.Lens.Iso.Iso'' s a -> a -> m a+-- @+(<*=) :: (MonadState s m, Num a) => LensLike' ((,)a) s a -> a -> m a+l <*= a = l <%= (* a)+{-# INLINE (<*=) #-}++-- | Divide the target of a fractionally valued 'Lens' into your 'Monad'\'s state+-- and return the result.+--+-- When you do not need the result of the division, ('Control.Lens.Setter.//=') is more flexible.+--+-- @+-- ('<//=') :: ('MonadState' s m, 'Fractional' a) => 'Lens'' s a -> a -> m a+-- ('<//=') :: ('MonadState' s m, 'Fractional' a) => 'Control.Lens.Iso.Iso'' s a -> a -> m a+-- @+(<//=) :: (MonadState s m, Fractional a) => LensLike' ((,)a) s a -> a -> m a+l <//= a = l <%= (/ a)+{-# INLINE (<//=) #-}++-- | Raise the target of a numerically valued 'Lens' into your 'Monad'\'s state+-- to a non-negative 'Integral' power and return the result.+--+-- When you do not need the result of the operation, ('Control.Lens.Setter.**=') is more flexible.+--+-- @+-- ('<^=') :: ('MonadState' s m, 'Num' a, 'Integral' e) => 'Lens'' s a -> e -> m a+-- ('<^=') :: ('MonadState' s m, 'Num' a, 'Integral' e) => 'Control.Lens.Iso.Iso'' s a -> e -> m a+-- @+(<^=) :: (MonadState s m, Num a, Integral e) => LensLike' ((,)a) s a -> e -> m a+l <^= e = l <%= (^ e)+{-# INLINE (<^=) #-}++-- | Raise the target of a fractionally valued 'Lens' into your 'Monad'\'s state+-- to an 'Integral' power and return the result.+--+-- When you do not need the result of the operation, ('Control.Lens.Setter.^^=') is more flexible.+--+-- @+-- ('<^^=') :: ('MonadState' s m, 'Fractional' b, 'Integral' e) => 'Lens'' s a -> e -> m a+-- ('<^^=') :: ('MonadState' s m, 'Fractional' b, 'Integral' e) => 'Control.Lens.Iso.Iso'' s a  -> e -> m a+-- @+(<^^=) :: (MonadState s m, Fractional a, Integral e) => LensLike' ((,)a) s a -> e -> m a+l <^^= e = l <%= (^^ e)+{-# INLINE (<^^=) #-}++-- | Raise the target of a floating-point valued 'Lens' into your 'Monad'\'s+-- state to an arbitrary power and return the result.+--+-- When you do not need the result of the operation, ('Control.Lens.Setter.**=') is more flexible.+--+-- @+-- ('<**=') :: ('MonadState' s m, 'Floating' a) => 'Lens'' s a -> a -> m a+-- ('<**=') :: ('MonadState' s m, 'Floating' a) => 'Control.Lens.Iso.Iso'' s a -> a -> m a+-- @+(<**=) :: (MonadState s m, Floating a) => LensLike' ((,)a) s a -> a -> m a+l <**= a = l <%= (** a)+{-# INLINE (<**=) #-}++-- | Logically '||' a Boolean valued 'Lens' into your 'Monad'\'s state and return+-- the result.+--+-- When you do not need the result of the operation, ('Control.Lens.Setter.||=') is more flexible.+--+-- @+-- ('<||=') :: 'MonadState' s m => 'Lens'' s 'Bool' -> 'Bool' -> m 'Bool'+-- ('<||=') :: 'MonadState' s m => 'Control.Lens.Iso.Iso'' s 'Bool'  -> 'Bool' -> m 'Bool'+-- @+(<||=) :: MonadState s m => LensLike' ((,)Bool) s Bool -> Bool -> m Bool+l <||= b = l <%= (|| b)+{-# INLINE (<||=) #-}++-- | Logically '&&' a Boolean valued 'Lens' into your 'Monad'\'s state and return+-- the result.+--+-- When you do not need the result of the operation, ('Control.Lens.Setter.&&=') is more flexible.+--+-- @+-- ('<&&=') :: 'MonadState' s m => 'Lens'' s 'Bool' -> 'Bool' -> m 'Bool'+-- ('<&&=') :: 'MonadState' s m => 'Control.Lens.Iso.Iso'' s 'Bool'  -> 'Bool' -> m 'Bool'+-- @+(<&&=) :: MonadState s m => LensLike' ((,)Bool) s Bool -> Bool -> m Bool+l <&&= b = l <%= (&& b)+{-# INLINE (<&&=) #-}++-- | Modify the target of a 'Lens' into your 'Monad'\'s state by a user supplied+-- function and return the /old/ value that was replaced.+--+-- When applied to a 'Control.Lens.Traversal.Traversal', it this will return a monoidal summary of all of the old values+-- present.+--+-- When you do not need the result of the operation, ('Control.Lens.Setter.%=') is more flexible.+--+-- @+-- ('<<%=') :: 'MonadState' s m             => 'Lens'' s a      -> (a -> a) -> m a+-- ('<<%=') :: 'MonadState' s m             => 'Control.Lens.Iso.Iso'' s a       -> (a -> a) -> m a+-- ('<<%=') :: ('MonadState' s m, 'Monoid' b) => 'Control.Lens.Traversal.Traversal'' s a -> (a -> a) -> m a+-- @+--+-- @('<<%=') :: 'MonadState' s m => 'LensLike' ((,)a) s s a b -> (a -> b) -> m a@+(<<%=) :: (Strong p, MonadState s m) => Overloading p (->) ((,)a) s s a b -> p a b -> m a+l <<%= f = l %%= lmap (\a -> (a,a)) (second' f)+{-# INLINE (<<%=) #-}++-- | Modify the target of a 'Lens' into your 'Monad'\'s state by a user supplied+-- function and return the /old/ value that was replaced.+--+-- When applied to a 'Control.Lens.Traversal.Traversal', it this will return a monoidal summary of all of the old values+-- present.+--+-- When you do not need the result of the operation, ('Control.Lens.Setter.%=') is more flexible.+--+-- @+-- ('<<%=') :: 'MonadState' s m             => 'Lens'' s a      -> (a -> a) -> m a+-- ('<<%=') :: 'MonadState' s m             => 'Control.Lens.Iso.Iso'' s a       -> (a -> a) -> m a+-- ('<<%=') :: ('MonadState' s m, 'Monoid' t) => 'Control.Lens.Traversal.Traversal'' s a -> (a -> a) -> m a+-- @+(<<.=) :: MonadState s m => LensLike ((,)a) s s a b -> b -> m a+l <<.= b = l %%= \a -> (a,b)+{-# INLINE (<<.=) #-}++-- | Run a monadic action, and set the target of 'Lens' to its result.+--+-- @+-- ('<<~') :: 'MonadState' s m => 'Control.Lens.Iso.Iso' s s a b   -> m b -> m b+-- ('<<~') :: 'MonadState' s m => 'Lens' s s a b  -> m b -> m b+-- @+--+-- NB: This is limited to taking an actual 'Lens' than admitting a 'Control.Lens.Traversal.Traversal' because+-- there are potential loss of state issues otherwise.+(<<~) :: MonadState s m => ALens s s a b -> m b -> m b+l <<~ mb = do+  b <- mb+  modify $ \s -> ipeek b (l sell s)+  return b+{-# INLINE (<<~) #-}++-- | 'mappend' a monoidal value onto the end of the target of a 'Lens' and+-- return the result.+--+-- When you do not need the result of the operation, ('Control.Lens.Setter.<>~') is more flexible.+(<<>~) :: Monoid m => Overloading (->) q ((,)m) s t m m -> m -> q s (m, t)+l <<>~ m = l <%~ (`mappend` m)+{-# INLINE (<<>~) #-}++-- | 'mappend' a monoidal value onto the end of the target of a 'Lens' into+-- your 'Monad'\'s state and return the result.+--+-- When you do not need the result of the operation, ('Control.Lens.Setter.<>=') is more flexible.+(<<>=) :: (MonadState s m, Monoid r) => LensLike' ((,)r) s r -> r -> m r+l <<>= r = l <%= (`mappend` r)+{-# INLINE (<<>=) #-}++------------------------------------------------------------------------------+-- Indexed+------------------------------------------------------------------------------++-- | Adjust the target of an 'IndexedLens' returning the intermediate result, or+-- adjust all of the targets of an 'Control.Lens.Traversal.IndexedTraversal' and return a monoidal summary+-- along with the answer.+--+-- @l '<%~' f ≡ l '<%@~' 'const' f@+--+-- When you do not need access to the index then ('<%~') is more liberal in what it can accept.+--+-- If you do not need the intermediate result, you can use ('Control.Lens.Setter.%@~') or even ('Control.Lens.Setter.%~').+--+-- @+-- ('<%@~') ::             'IndexedLens' i s t a b      -> (i -> a -> b) -> s -> (b, t)+-- ('<%@~') :: 'Monoid' b => 'Control.Lens.Traversal.IndexedTraversal' i s t a b -> (i -> a -> b) -> s -> (b, t)+-- @+(<%@~) :: Overloading (Indexed i) q ((,) b) s t a b -> (i -> a -> b) -> q s (b, t)+l <%@~ f = l (Indexed $ \i a -> let b = f i a in (b, b))+{-# INLINE (<%@~) #-}++-- | Adjust the target of an 'IndexedLens' returning a supplementary result, or+-- adjust all of the targets of an 'Control.Lens.Traversal.IndexedTraversal' and return a monoidal summary+-- of the supplementary results and the answer.+--+-- @('%%@~') ≡ 'Control.Lens.Indexed.withIndex'@+--+-- @+-- ('%%@~') :: 'Functor' f => 'IndexedLens' i s t a b      -> (i -> a -> f b) -> s -> f t+-- ('%%@~') :: 'Functor' f => 'Control.Lens.Traversal.IndexedTraversal' i s t a b -> (i -> a -> f b) -> s -> f t+-- @+--+-- In particular, it is often useful to think of this function as having one of these even more+-- restricted type signatures:+--+-- @+-- ('%%@~') ::             'IndexedLens' i s t a b      -> (i -> a -> (r, b)) -> s -> (r, t)+-- ('%%@~') :: 'Monoid' r => 'Control.Lens.Traversal.IndexedTraversal' i s t a b -> (i -> a -> (r, b)) -> s -> (r, t)+-- @+(%%@~) :: IndexedLensLike i f s t a b -> (i -> a -> f b) -> s -> f t+(%%@~) l = l .# Indexed+{-# INLINE (%%@~) #-}++-- | Adjust the target of an 'IndexedLens' returning a supplementary result, or+-- adjust all of the targets of an 'Control.Lens.Traversal.IndexedTraversal' within the current state, and+-- return a monoidal summary of the supplementary results.+--+-- @l '%%@=' f ≡ 'state' (l '%%@~' f)@+--+-- @+-- ('%%@=') :: 'MonadState' s m                'IndexedLens' i s s a b      -> (i -> a -> (r, b)) -> s -> m r+-- ('%%@=') :: ('MonadState' s m, 'Monoid' r) => 'Control.Lens.Traversal.IndexedTraversal' i s s a b -> (i -> a -> (r, b)) -> s -> m r+-- @+(%%@=) :: MonadState s m => IndexedLensLike i ((,) r) s s a b -> (i -> a -> (r, b)) -> m r+#if MIN_VERSION_mtl(2,1,0)+l %%@= f = State.state (l %%@~ f)+#else+l %%@= f = do+  (r, s) <- State.gets (l %%@~ f)+  State.put s+  return r+#endif+{-# INLINE (%%@=) #-}++-- | Adjust the target of an 'IndexedLens' returning the intermediate result, or+-- adjust all of the targets of an 'Control.Lens.Traversal.IndexedTraversal' within the current state, and+-- return a monoidal summary of the intermediate results.+--+-- @+-- ('<%@=') :: 'MonadState' s m                'IndexedLens' i s s a b      -> (i -> a -> b) -> m b+-- ('<%@=') :: ('MonadState' s m, 'Monoid' b) => 'Control.Lens.Traversal.IndexedTraversal' i s s a b -> (i -> a -> b) -> m b+-- @+(<%@=) :: MonadState s m => IndexedLensLike i ((,) b) s s a b -> (i -> a -> b) -> m b+l <%@= f = l %%@= \ i a -> let b = f i a in (b, b)+{-# INLINE (<%@=) #-}++------------------------------------------------------------------------------+-- ALens Combinators+------------------------------------------------------------------------------++-- | A version of ('Control.Lens.Getter.^.') that works on 'ALens'.+--+-- >>> ("hello","world")^#_2+-- "world"+(^#) :: s -> ALens s t a b -> a+s ^# l = ipos (l sell s)+{-# INLINE (^#) #-}++-- | A version of 'Control.Lens.Setter.set' that works on 'ALens'.+--+-- >>> storing _2 "world" ("hello","there")+-- ("hello","world")+storing :: ALens s t a b -> b -> s -> t+storing l b s = ipeek b (l sell s)+{-# INLINE storing #-}++-- | A version of ('Control.Lens.Setter..~') that works on 'ALens'.+--+-- >>> ("hello","there") & _2 #~ "world"+-- ("hello","world")+( #~ ) :: ALens s t a b -> b -> s -> t+( #~ ) l b s = ipeek b (l sell s)+{-# INLINE ( #~ ) #-}++-- | A version of ('Control.Lens.Setter.%~') that works on 'ALens'.+--+-- >>> ("hello","world") & _2 #%~ length+-- ("hello",5)+( #%~ ) :: ALens s t a b -> (a -> b) -> s -> t+( #%~ ) l f s = ipeeks f (l sell s)+{-# INLINE ( #%~ ) #-}++-- | A version of ('%%~') that works on 'ALens'.+--+-- >>> ("hello","world") & _2 #%%~ \x -> (length x, x ++ "!")+-- (5,("hello","world!"))+( #%%~ ) :: Functor f => ALens s t a b -> (a -> f b) -> s -> f t+( #%%~ ) l f s = runPretext (l sell s) f+{-# INLINE ( #%%~ ) #-}++-- | A version of ('Control.Lens.Setter..=') that works on 'ALens'.+( #= ) :: MonadState s m => ALens s s a b -> b -> m ()+l #= f = modify (l #~ f)+{-# INLINE ( #= ) #-}++-- | A version of ('Control.Lens.Setter.%=') that works on 'ALens'.+( #%= ) :: MonadState s m => ALens s s a b -> (a -> b) -> m ()+l #%= f = modify (l #%~ f)+{-# INLINE ( #%= ) #-}++-- | A version of ('<%~') that works on 'ALens'.+--+-- >>> ("hello","world") & _2 <#%~ length+-- (5,("hello",5))+(<#%~) :: ALens s t a b -> (a -> b) -> s -> (b, t)+l <#%~ f = \s -> runPretext (l sell s) $ \a -> let b = f a in (b, b)+{-# INLINE (<#%~) #-}++-- | A version of ('<%=') that works on 'ALens'.+(<#%=) :: MonadState s m => ALens s s a b -> (a -> b) -> m b+l <#%= f = l #%%= \a -> let b = f a in (b, b)+{-# INLINE (<#%=) #-}++-- | A version of ('%%=') that works on 'ALens'.+( #%%= ) :: MonadState s m => ALens s s a b -> (a -> (r, b)) -> m r+#if MIN_VERSION_mtl(2,1,1)+l #%%= f = State.state $ \s -> runPretext (l sell s) f+#else+l #%%= f = do+  p <- State.gets (l sell)+  let (r, t) = runPretext p f+  State.put t+  return r+#endif++-- | A version of ('Control.Lens.Setter.<.~') that works on 'ALens'.+--+-- >>> ("hello","there") & _2 <#~ "world"+-- ("world",("hello","world"))+(<#~) :: ALens s t a b -> b -> s -> (b, t)+l <#~ b = \s -> (b, storing l b s)++-- | A version of ('Control.Lens.Setter.<#=') that works on 'ALens'.+(<#=) :: MonadState s m => ALens s s a b -> b -> m b+l <#= b = do+  l #= b+  return b
+ src/Control/Lens/Level.hs view
@@ -0,0 +1,113 @@+{-# LANGUAGE Rank2Types #-}+{-# LANGUAGE FlexibleContexts #-}+-----------------------------------------------------------------------------+-- |+-- Module      :  Control.Lens.Level+-- Copyright   :  (C) 2012-13 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  provisional+-- Portability :  Rank2Types+--+-- This module provides combinators for breadth-first searching within+-- arbitrary traversals.+----------------------------------------------------------------------------+module Control.Lens.Level+  ( Level+  , levels+  , ilevels+  ) where++import Control.Applicative+import Control.Lens.Internal.Bazaar+import Control.Lens.Internal.Context+import Control.Lens.Internal.Getter+import Control.Lens.Internal.Indexed+import Control.Lens.Internal.Level+import Control.Lens.Traversal+import Data.Profunctor.Unsafe++-- $setup+-- >>> import Control.Lens+-- >>> import Data.Char++levelIns :: Bazaar (->) a b t -> [Level () a]+levelIns = go 0 . (runAccessor #. bazaar (Accessor #. deepening ())) where+  go k z = k `seq` runDeepening z k $ \ xs b ->+    xs : if b then (go $! k + 1) z else []+{-# INLINE levelIns #-}++levelOuts :: Bazaar (->) a b t -> [Level j b] -> t+levelOuts bz = runFlows $ runBazaar bz $ \ _ -> Flows $ \t -> case t of+  One _ a : _ -> a+  _           -> error "levelOuts: wrong shape"+{-# INLINE levelOuts #-}++-- | This provides a breadth-first 'Traversal' of the individual 'levels' of any other 'Traversal'+-- via iterative deepening depth-first search. The levels are returned to you in a compressed format.+--+-- This can permit us to extract the 'levels' directly:+--+-- >>> ["hello","world"]^..levels (traverse.traverse)+-- [Zero,Zero,One () 'h',Two 0 (One () 'e') (One () 'w'),Two 0 (One () 'l') (One () 'o'),Two 0 (One () 'l') (One () 'r'),Two 0 (One () 'o') (One () 'l'),One () 'd']+--+-- But we can also traverse them in turn:+--+-- >>> ["hello","world"]^..levels (traverse.traverse).traverse+-- "hewlolrold"+--+-- We can use this to traverse to a fixed depth in the tree of ('<*>') used in the 'Traversal':+--+-- >>> ["hello","world"] & taking 4 (levels (traverse.traverse)).traverse %~ toUpper+-- ["HEllo","World"]+--+-- Or we can use it to traverse the first @n@ elements in found in that 'Traversal' regardless of the depth+-- at which they were found.+--+-- >>> ["hello","world"] & taking 4 (levels (traverse.traverse).traverse) %~ toUpper+-- ["HELlo","World"]+--+-- The resulting 'Traversal' of the 'levels' which is indexed by the depth of each 'Level'.+--+-- >>> ["dog","cat"]^@..levels (traverse.traverse) <. traverse+-- [(2,'d'),(3,'o'),(3,'c'),(4,'g'),(4,'a'),(5,'t')]+--+-- /Note:/ Internally this is implemented by using an illegal 'Applicative', as it extracts information+-- in an order that violates the 'Applicative' laws.+levels :: ATraversal s t a b -> IndexedTraversal Int s t (Level () a) (Level () b)+levels l f s = levelOuts bz <$> traversed f (levelIns bz) where+  bz = l sell s+{-# INLINE levels #-}++ilevelIns :: Bazaar (Indexed i) a b t -> [Level i a]+ilevelIns = go 0 . (runAccessor #. bazaar (Indexed $ \ i -> Accessor #. deepening i)) where+  go k z = k `seq` runDeepening z k $ \ xs b ->+    xs : if b then (go $! k + 1) z else []+{-# INLINE ilevelIns #-}++ilevelOuts :: Bazaar (Indexed i) a b t -> [Level j b] -> t+ilevelOuts bz = runFlows $ runBazaar bz $ Indexed $ \ _ _ -> Flows $ \t -> case t of+  One _ a : _ -> a+  _           -> error "ilevelOuts: wrong shape"+{-# INLINE ilevelOuts #-}++-- | This provides a breadth-first 'Traversal' of the individual levels of any other 'Traversal'+-- via iterative deepening depth-first search. The levels are returned to you in a compressed format.+--+-- This is similar to 'levels', but retains the index of the original 'IndexedTraversal', so you can+-- access it when traversing the levels later on.+--+-- >>> ["dog","cat"]^@..ilevels (traversed<.>traversed).itraversed+-- [((0,0),'d'),((0,1),'o'),((1,0),'c'),((0,2),'g'),((1,1),'a'),((1,2),'t')]+--+-- The resulting 'Traversal' of the levels which is indexed by the depth of each 'Level'.+--+-- >>> ["dog","cat"]^@..ilevels (traversed<.>traversed)<.>itraversed+-- [((2,(0,0)),'d'),((3,(0,1)),'o'),((3,(1,0)),'c'),((4,(0,2)),'g'),((4,(1,1)),'a'),((5,(1,2)),'t')]+--+-- /Note:/ Internally this is implemented by using an illegal 'Applicative', as it extracts information+-- in an order that violates the 'Applicative' laws.+ilevels :: AnIndexedTraversal i s t a b -> IndexedTraversal Int s t (Level i a) (Level j b)+ilevels l f s = ilevelOuts bz <$> traversed f (ilevelIns bz) where+  bz = l sell s+{-# INLINE ilevels #-}
src/Control/Lens/Loupe.hs view
@@ -1,181 +1,44 @@-{-# LANGUAGE CPP #-}-#ifdef TRUSTWORTHY-{-# LANGUAGE Trustworthy #-}-#endif--#ifndef MIN_VERSION_mtl-#define MIN_VERSION_mtl(x,y,z) 1-#endif-+{-# LANGUAGE Rank2Types #-} ------------------------------------------------------------------------------- -- | -- Module      :  Control.Lens.Loupe--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  provisional -- Portability :  Rank2Types ----- A 'Loupe' is a minimalist 'Lens' suitable for storing in containers--- or returning monadically that can still be composed with other lenses.+-- This module exports a minimalist API for working with lenses in highly+-- monomorphic settings. ------------------------------------------------------------------------------- module Control.Lens.Loupe   (-  -- * Lenses-    Loupe+    ALens, ALens'+  , cloneLens   , storing   , (^#)-  , (#~), (#%~), (#%%~), (<#~), (<#%~)-  , (#=), (#%=), (#%%=), (<#=), (<#%=)--  -- * Simplified-  , SimpleLoupe--  -- * ALens forward compatibility-  , ALens-  , ALens'-  , cloneLens+  , ( #~ ), ( #%~ ), ( #%%~ ), (<#~), (<#%~)+  , ( #= ), ( #%= ), ( #%%= ), (<#=), (<#%=)+  -- * Deprecated Aliases+  , Loupe, SimpleLoupe   ) where -import Control.Applicative              as Applicative-import Control.Lens.Internal+import Control.Lens.Internal.Context+import Control.Lens.Lens import Control.Lens.Type-import Control.Monad.State.Class        as State --- $setup--- >>> import Control.Lens--infixl 8 ^#-infixr 4 <#~, #~, #%~, <#%~, #%%~-infix  4 <#=, #=, #%=, <#%=, #%%=------------------------------------------------------------------------------------ Lenses------------------------------------------------------------------------------------ |--- A @'Loupe' s t a b@ is almost a 'Lens'. It can be composed on the left of other lenses,--- you can use 'cloneLens' to promote it to a 'Lens', and it provides a minimalist lens-like--- interface. They can be used in an API where you need to pass around lenses inside containers--- or as monadic results. Unlike a 'ReifiedLens' they can be composed and used directly, but--- they are slightly lower performance.---- 1) You get back what you put in:------ @'Control.Lens.Setter.set' l b a '^#' l ≡ b@------ 2) Putting back what you got doesn't change anything:------ @'storing' l (a '^#' l) a  ≡ a@------ 3) Setting twice is the same as setting once:------ @'storing' l c ('storing' l b a) ≡ 'storing' l c a@------ These laws are strong enough that the 4 type parameters of a 'Loupe' cannot--- vary fully independently. For more on how they interact, read the \"Why is--- it a Lens Family?\" section of <http://comonad.com/reader/2012/mirrored-lenses/>.--type Loupe s t a b = LensLike (Context a b) s t a b----- | @type 'SimpleLoupe' = 'Simple' 'Loupe'@-type SimpleLoupe s a = Loupe s s a a--type ALens s t a b = Loupe s t a b--type ALens' s a = Loupe s s a a---- | A 'Loupe'-specific version of ('Control.Lens.Getter.^.')------ >>> ("hello","world")^#_2--- "world"-(^#) :: s -> Loupe s t a b -> a-s ^# l = case l (Context id) s of-  Context _ a -> a-{-# INLINE (^#) #-}---- | A 'Loupe'-specific version of 'Control.Lens.Setter.set'------ >>> storing _2 "world" ("hello","there")--- ("hello","world")-storing :: Loupe s t a b -> b -> s -> t-storing l b s = case l (Context id) s of-  Context g _ -> g b-{-# INLINE storing #-}---- | A 'Loupe'-specific version of ('Control.Lens.Setter..~')------ >>> ("hello","there") & _2 #~ "world"--- ("hello","world")-(#~) :: Loupe s t a b -> b -> s -> t-(#~) l b s = case l (Context id ) s of-  Context g _ -> g b-{-# INLINE (#~) #-}---- | A 'Loupe'-specific version of ('Control.Lens.Setter.%~')------ >>> ("hello","world") & _2 #%~ length--- ("hello",5)-(#%~) :: Loupe s t a b -> (a -> b) -> s -> t-(#%~) l f s = case l (Context id) s of-  Context g a -> g (f a)-{-# INLINE (#%~) #-}---- | A 'Loupe'-specific version of ('Control.Lens.Type.%%~')------ >>> ("hello","world") & _2 #%%~ \x -> (length x, x ++ "!")--- (5,("hello","world!"))-(#%%~) :: Functor f => Loupe s t a b -> (a -> f b) -> s -> f t-(#%%~) l f s = case l (Context id) s of-  Context g a -> g <$> f a---- | A 'Loupe'-specific version of ('Control.Lens.Setter..=')-(#=) :: MonadState s m => Loupe s s a b -> b -> m ()-l #= f = modify (l #~ f)-{-# INLINE (#=) #-}---- | A 'Loupe'-specific version of ('Control.Lens.Setter.%=')-(#%=) :: MonadState s m => Loupe s s a b -> (a -> b) -> m ()-l #%= f = modify (l #%~ f)-{-# INLINE (#%=) #-}---- | Modify the target of a 'Loupe' and return the result.+-- | This is an older alias for a type-restricted form of lens that is able to be passed around+-- in containers monomorphically. ----- >>> ("hello","world") & _2 <#%~ length--- (5,("hello",5))-(<#%~) :: Loupe s t a b -> (a -> b) -> s -> (b, t)-l <#%~ f = \s -> case l (Context id) s of-  Context g a -> let b = f a in (b, g b)-{-# INLINE (<#%~) #-}---- | Modify the target of a 'Loupe' into your monad's state by a user supplied function and return the result.-(<#%=) :: MonadState s m => Loupe s s a b -> (a -> b) -> m b-l <#%= f = l #%%= \a -> let b = f a in (b,b)-{-# INLINE (<#%=) #-}---- | Modify the target of a 'Loupe' in the current monadic state, returning an auxiliary result.-(#%%=) :: MonadState s m => Loupe s s a b -> (a -> (r, b)) -> m r-#if MIN_VERSION_mtl(2,1,1)-l #%%= f = State.state $ \s -> case l (Context id) s of-  Context g a -> g <$> f a-#else-l #%%= f = do-  Context g a <- State.gets (l (Context id))-  let (r, b) = f a-  State.put (g b)-  return r-#endif+-- Deprecated. This has since been renamed to 'ALens' for consistency.+type Loupe s t a b = LensLike (Pretext (->) a b) s t a b+{-# DEPRECATED Loupe "use ALens" #-} --- | Replace the target of a 'Loupe' and return the new value.+-- | @+-- type 'SimpleLoupe' = 'Simple' 'Loupe'+-- @ ----- >>> ("hello","there") & _2 <#~ "world"--- ("world",("hello","world"))-(<#~) :: Loupe s t a b -> b -> s -> (b, t)-l <#~ b = \s -> (b, storing l b s)---- | Replace the target of a 'Loupe' in the current monadic state, returning the new value.-(<#=) :: MonadState s m => Loupe s s a b -> b -> m b-l <#= b = do-  l #= b-  return b+-- Deprecated for two reasons. 'Loupe' is now 'ALens', and we no longer use the verbose @SimpleFoo@ naming+-- convention, this has since been renamed to 'ALens'' for consistency.+type SimpleLoupe s a = Loupe s s a a+{-# DEPRECATED SimpleLoupe "use ALens'" #-}
+ src/Control/Lens/Operators.hs view
@@ -0,0 +1,106 @@+-----------------------------------------------------------------------------+-- |+-- Module      :  Control.Lens.Operators+-- Copyright   :  (C) 2012-13 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  experimental+-- Portability :  non-portable+--+-- This module exists for users who like to work with qualified imports+-- but want access to the operators from Lens.+--+-- > import qualified Control.Lens as L+-- > import Control.Lens.Operators+----------------------------------------------------------------------------+module Control.Lens.Operators+  (+  -- * General Purpose+    (&), (<&>), (??)++  -- * Getting+  , (^.), (^@.)+  -- ** Loupes+  , (^#)+  -- ** with Effects+  , (^!), (^@!)+  , (^!!), (^@!!)+  , (^!?), (^@!?)+  -- ** from Folds+  , (^..), (^@..)+  , (^?), (^@?)+  , (^?!), (^@?!)++  -- * Common Operators+  -- ** Setting+  , (.~) , (.=)+  , (<.~), (<.=)+  , (<<.~), (<<.=)+  --- *** Loupes+  , ( #~ ), ( #= )+  , (<#~), (<#=)+  -- *** Just+  , (?~), (?=)+  , (<?~), (<?=)++  -- ** Modifying+  , (%~), (%=)+  , (<%~), (<%=)+  , (<<%~), (<<%=)+  -- *** Loupes+  , ( #%~ ), ( #%= )+  , (<#%~), (<#%=)+  -- *** with Indices+  , (%@~), (%@=)+  , (<%@~), (<%@=)++  -- ** Traversing+  , (%%~), (%%=)+   --- *** Loupes+  , ( #%%~ ), ( #%%= )+   --- *** with Indices+  , (%%@~), (%%@=)++  -- ** Addition+  , (+~), (+=), (<+~), (<+=)+  -- ** Subtraction+  , (-~), (-=), (<-~), (<-=)+  -- ** Multiplication+  , (*~), (*=), (<*~), (<*=)+  -- ** Division+  , (//~), (//=), (<//~), (<//=)+  -- ** Exponentiation+  , (^~), (^=), (<^~), (<^=)+  , (^^~), (^^=), (<^^~), (<^^=)+  , (**~), (**=), (<**~), (<**=)+  -- ** Logical Or+  , (||~), (||=), (<||~), (<||=)+  -- ** Logical And+  , (&&~), (&&=), (<&&~), (<&&=)+  -- ** Monoidal+  , (<>~), (<>=), (<<>~), (<<>=)++  -- * Composing Indices+  , (<.>), (<.), (.>)++  -- * Monadic Assignment+  , (<~), (<<~)++  -- * Zippers+  , (:>)(), (:>>)()++  -- * Cons and Snoc+  , (<|), (|>)+  ) where++import Control.Lens.Action+import Control.Lens.Combinators+import Control.Lens.Cons+import Control.Lens.Fold+import Control.Lens.Getter+import Control.Lens.Indexed+import Control.Lens.Lens+import Control.Lens.Setter+import Control.Lens.Zipper++{-# ANN module "HLint: ignore Use import/export shortcut" #-}
src/Control/Lens/Plated.hs view
@@ -1,6 +1,5 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE Rank2Types #-}-{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MultiParamTypeClasses #-}@@ -17,7 +16,7 @@ ------------------------------------------------------------------------------- -- | -- Module      :  Control.Lens.Plated--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  provisional@@ -30,12 +29,13 @@ -- <http://community.haskell.org/~ndm/uniplate/> -- -- The combinators in here are designed to be compatible with and subsume the--- 'uniplate' API with the notion of a 'Traversal' replacing a uniplate or--- biplate.+-- @uniplate@ API with the notion of a 'Traversal' replacing+-- a 'Data.Data.Lens.uniplate' or 'Data.Data.Lens.biplate'. ----- By implementing these combinators in terms of 'plate' instead of 'uniplate'--- additional type safety is gained, as the user is no longer responsible for--- maintaining invariants such as the number of children they received.+-- By implementing these combinators in terms of 'plate' instead of+-- 'Data.Data.Lens.uniplate' additional type safety is gained, as the user is+-- no longer responsible for maintaining invariants such as the number of+-- children they received. -- -- Note: The @Biplate@ is /deliberately/ excluded from the API here, with the -- intention that you replace them with either explicit traversals, or by using the@@ -82,10 +82,11 @@ import           Control.Applicative import           Control.Lens.Fold import           Control.Lens.Getter-import           Control.Lens.Internal+import           Control.Lens.Indexed+import           Control.Lens.Internal.Context+import           Control.Lens.Type import           Control.Lens.Setter import           Control.Lens.Traversal-import           Control.Lens.Type import qualified Language.Haskell.TH as TH #ifdef DEFAULT_SIGNATURES import           Data.Data@@ -94,6 +95,8 @@ import           Data.Monoid import           Data.Tree +{-# ANN module "HLint: ignore Reduce duplication" #-}+ -- | A 'Plated' type is one where we know how to extract its immediate self-similar children. -- -- /Example 1/:@@ -169,15 +172,17 @@ -- -- If you want to find something unplated and non-recursive with 'Data.Data.Lens.biplate' -- use the @...OnOf@ variant with 'ignored', though those usecases are much better served--- in most cases by using the existing lens combinators! e.g.+-- in most cases by using the existing 'Lens' combinators! e.g. ----- @'toListOf' 'biplate' ≡ 'universeOnOf' 'biplate' 'ignored'@.+-- @+-- 'toListOf' 'biplate' ≡ 'universeOnOf' 'biplate' 'ignored'+-- @ -- -- This same ability to explicitly pass the 'Traversal' in question is why there is no -- analogue to uniplate's @Biplate@. -- -- Moreover, since we can allow custom traversals, we implement reasonable defaults for--- polymorphic data types, that only traverse into themselves, and /not/ their+-- polymorphic data types, that only 'Control.Traversable.traverse' into themselves, and /not/ their -- polymorphic arguments.  class Plated a where@@ -186,9 +191,9 @@   -- If you're using GHC 7.2 or newer and your type has a 'Data' instance,   -- 'plate' will default to 'uniplate' and you can choose to not override   -- it with your own definition.-  plate :: Simple Traversal a a+  plate :: Traversal' a a #ifdef DEFAULT_SIGNATURES-  default plate :: Data a => Simple Traversal a a+  default plate :: Data a => Traversal' a a   plate = uniplate #endif @@ -215,7 +220,9 @@  -- | Extract the immediate descendants of a 'Plated' container. ----- @'children' ≡ 'toListOf' 'plate'@+-- @+-- 'children' ≡ 'toListOf' 'plate'+-- @ children :: Plated a => a -> [a] children = toListOf plate {-# INLINE children #-}@@ -227,7 +234,9 @@ -- | Rewrite by applying a rule everywhere you can. Ensures that the rule cannot -- be applied anywhere in the result: ----- @propRewrite r x = 'all' ('Data.Just.isNothing' . r) ('universe' ('rewrite' r x))@+-- @+-- propRewrite r x = 'all' ('Data.Just.isNothing' '.' r) ('universe' ('rewrite' r x))+-- @ -- -- Usually 'transform' is more appropriate, but 'rewrite' can give better -- compositionality. Given two single transformations @f@ and @g@, you can@@ -239,19 +248,21 @@ -- | Rewrite by applying a rule everywhere you can. Ensures that the rule cannot -- be applied anywhere in the result: ----- @propRewriteOf l r x = 'all' ('Data.Just.isNothing' . r) ('universeOf' l ('rewriteOf' l r x))@+-- @+-- propRewriteOf l r x = 'all' ('Data.Just.isNothing' '.' r) ('universeOf' l ('rewriteOf' l r x))+-- @ -- -- Usually 'transformOf' is more appropriate, but 'rewriteOf' can give better -- compositionality. Given two single transformations @f@ and @g@, you can -- construct @\a -> f a `mplus` g a@ which performs both rewrites until a fixed point. -- -- @--- 'rewriteOf' :: 'Simple' 'Control.Lens.Iso.Iso' a a       -> (a -> 'Maybe' a) -> a -> a--- 'rewriteOf' :: 'Simple' 'Lens' a a      -> (a -> 'Maybe' a) -> a -> a--- 'rewriteOf' :: 'Simple' 'Traversal' a a -> (a -> 'Maybe' a) -> a -> a--- 'rewriteOf' :: 'Simple' 'Setter' a a    -> (a -> 'Maybe' a) -> a -> a+-- 'rewriteOf' :: 'Control.Lens.Iso.Iso'' a a       -> (a -> 'Maybe' a) -> a -> a+-- 'rewriteOf' :: 'Lens'' a a      -> (a -> 'Maybe' a) -> a -> a+-- 'rewriteOf' :: 'Traversal'' a a -> (a -> 'Maybe' a) -> a -> a+-- 'rewriteOf' :: 'Setter'' a a    -> (a -> 'Maybe' a) -> a -> a -- @-rewriteOf :: SimpleSetting a a -> (a -> Maybe a) -> a -> a+rewriteOf :: ASetter' a a -> (a -> Maybe a) -> a -> a rewriteOf l f = go where   go = transformOf l (\x -> maybe x go (f x)) {-# INLINE rewriteOf #-}@@ -259,24 +270,24 @@ -- | Rewrite recursively over part of a larger structure. -- -- @--- 'rewriteOn' :: 'Plated' a => 'Simple' 'Control.Lens.Iso.Iso' s a       -> (a -> 'Maybe' a) -> s -> s--- 'rewriteOn' :: 'Plated' a => 'Simple' 'Lens' s a      -> (a -> 'Maybe' a) -> s -> s--- 'rewriteOn' :: 'Plated' a => 'Simple' 'Traversal' s a -> (a -> 'Maybe' a) -> s -> s--- 'rewriteOn' :: 'Plated' a => 'Simple' 'Setting' s a   -> (a -> 'Maybe' a) -> s -> s+-- 'rewriteOn' :: 'Plated' a => 'Control.Lens.Iso.Iso'' s a       -> (a -> 'Maybe' a) -> s -> s+-- 'rewriteOn' :: 'Plated' a => 'Lens'' s a      -> (a -> 'Maybe' a) -> s -> s+-- 'rewriteOn' :: 'Plated' a => 'Traversal'' s a -> (a -> 'Maybe' a) -> s -> s+-- 'rewriteOn' :: 'Plated' a => 'ASetter'' s a   -> (a -> 'Maybe' a) -> s -> s -- @-rewriteOn :: Plated a => Setting s t a a -> (a -> Maybe a) -> s -> t+rewriteOn :: Plated a => ASetter s t a a -> (a -> Maybe a) -> s -> t rewriteOn b = over b . rewrite {-# INLINE rewriteOn #-} --- | Rewrite recursively over part of a larger structure using a specified setter.+-- | Rewrite recursively over part of a larger structure using a specified 'Setter'. -- -- @--- 'rewriteOnOf' :: 'Plated' a => 'Simple' 'Control.Lens.Iso.Iso' s a       -> 'Simple' 'Control.Lens.Iso.Iso' a a       -> (a -> 'Maybe' a) -> s -> s--- 'rewriteOnOf' :: 'Plated' a => 'Simple' 'Lens' s a      -> 'Simple' 'Lens' a a      -> (a -> 'Maybe' a) -> s -> s--- 'rewriteOnOf' :: 'Plated' a => 'Simple' 'Traversal' s a -> 'Simple' 'Traversal' a a -> (a -> 'Maybe' a) -> s -> s--- 'rewriteOnOf' :: 'Plated' a => 'Simple' 'Setter' s a    -> 'Simple' 'Setter' a a    -> (a -> 'Maybe' a) -> s -> s+-- 'rewriteOnOf' :: 'Plated' a => 'Control.Lens.Iso.Iso'' s a       -> 'Control.Lens.Iso.Iso'' a a       -> (a -> 'Maybe' a) -> s -> s+-- 'rewriteOnOf' :: 'Plated' a => 'Lens'' s a      -> 'Lens'' a a      -> (a -> 'Maybe' a) -> s -> s+-- 'rewriteOnOf' :: 'Plated' a => 'Traversal'' s a -> 'Traversal'' a a -> (a -> 'Maybe' a) -> s -> s+-- 'rewriteOnOf' :: 'Plated' a => 'Setter'' s a    -> 'Setter'' a a    -> (a -> 'Maybe' a) -> s -> s -- @-rewriteOnOf :: Setting s t a a -> SimpleSetting a a -> (a -> Maybe a) -> s -> t+rewriteOnOf :: ASetter s t a a -> ASetter' a a -> (a -> Maybe a) -> s -> t rewriteOnOf b l = over b . rewriteOf l {-# INLINE rewriteOnOf #-} @@ -288,7 +299,7 @@  -- | Rewrite by applying a monadic rule everywhere you recursing with a user-specified 'Traversal'. -- Ensures that the rule cannot be applied anywhere in the result.-rewriteMOf :: Monad m => SimpleLensLike (WrappedMonad m) a a -> (a -> m (Maybe a)) -> a -> m a+rewriteMOf :: Monad m => LensLike' (WrappedMonad m) a a -> (a -> m (Maybe a)) -> a -> m a rewriteMOf l f = go where   go = transformMOf l (\x -> f x >>= maybe (return x) go) {-# INLINE rewriteMOf #-}@@ -301,7 +312,7 @@  -- | Rewrite by applying a monadic rule everywhere inside of a structure located by a user-specified 'Traversal', -- using a user-specified 'Traversal' for recursion. Ensures that the rule cannot be applied anywhere in the result.-rewriteMOnOf :: Monad m => LensLike (WrappedMonad m) s t a a -> SimpleLensLike (WrappedMonad m) a a -> (a -> m (Maybe a)) -> s -> m t+rewriteMOnOf :: Monad m => LensLike (WrappedMonad m) s t a a -> LensLike' (WrappedMonad m) a a -> (a -> m (Maybe a)) -> s -> m t rewriteMOnOf b l = mapMOf b . rewriteMOf l {-# INLINE rewriteMOnOf #-} @@ -314,9 +325,11 @@ universe = universeOf plate {-# INLINE universe #-} --- | Given a fold that knows how to locate immediate children, retrieve all of the transitive descendants of a node, including itself.+-- | Given a 'Fold' that knows how to locate immediate children, retrieve all of the transitive descendants of a node, including itself. ----- @'universeOf' :: 'Fold' a a -> a -> [a]@+-- @+-- 'universeOf' :: 'Fold' a a -> a -> [a]+-- @ universeOf :: Getting [a] a b a b -> a -> [a] universeOf l = go where   go a = a : foldMapOf l go a@@ -330,7 +343,9 @@ -- | Given a 'Fold' that knows how to locate immediate children, retrieve all of the transitive descendants of a node, including itself that lie -- in a region indicated by another 'Fold'. ----- @'toListOf' l ≡ 'universeOnOf' l 'ignored'@+-- @+-- 'toListOf' l ≡ 'universeOnOf' l 'ignored'+-- @ universeOnOf :: Getting [a] s t a b -> Getting [a] a b a b -> s -> [a] universeOnOf b = foldMapOf b . universeOf {-# INLINE universeOnOf #-}@@ -355,20 +370,20 @@ -- | Transform every element in the tree in a bottom-up manner over a region indicated by a 'Setter'. -- -- @--- 'transformOn' :: 'Plated' a => 'Simple' 'Traversal' s a -> (a -> a) -> s -> s--- 'transformOn' :: 'Plated' a => 'Simple' 'Setter' s a    -> (a -> a) -> s -> s+-- 'transformOn' :: 'Plated' a => 'Traversal'' s a -> (a -> a) -> s -> s+-- 'transformOn' :: 'Plated' a => 'Setter'' s a    -> (a -> a) -> s -> s -- @-transformOn :: Plated a => Setting s t a a -> (a -> a) -> s -> t+transformOn :: Plated a => ASetter s t a a -> (a -> a) -> s -> t transformOn b = over b . transform {-# INLINE transformOn #-}  -- | Transform every element by recursively applying a given 'Setter' in a bottom-up manner. -- -- @--- 'transformOf' :: 'Simple' 'Traversal' a a -> (a -> a) -> a -> a--- 'transformOf' :: 'Simple' 'Setter' a a    -> (a -> a) -> a -> a+-- 'transformOf' :: 'Traversal'' a a -> (a -> a) -> a -> a+-- 'transformOf' :: 'Setter'' a a    -> (a -> a) -> a -> a -- @-transformOf :: SimpleSetting a a -> (a -> a) -> a -> a+transformOf :: ASetter' a a -> (a -> a) -> a -> a transformOf l f = go where   go = f . over l go {-# INLINE transformOf #-}@@ -377,10 +392,10 @@ -- in a bottom-up manner. -- -- @--- 'transformOnOf' :: 'Simple' 'Setter' s a -> 'Simple' 'Traversal' a a -> (a -> a) -> s -> s--- 'transformOnOf' :: 'Simple' 'Setter' s a -> 'Simple' 'Setter' a a    -> (a -> a) -> s -> s+-- 'transformOnOf' :: 'Setter'' s a -> 'Traversal'' a a -> (a -> a) -> s -> s+-- 'transformOnOf' :: 'Setter'' s a -> 'Setter'' a a    -> (a -> a) -> s -> s -- @-transformOnOf :: Setting s t a a -> SimpleSetting a a -> (a -> a) -> s -> t+transformOnOf :: ASetter s t a a -> ASetter' a a -> (a -> a) -> s -> t transformOnOf b l = over b . transformOf l {-# INLINE transformOnOf #-} @@ -391,15 +406,19 @@  -- | Transform every element in the tree in a region indicated by a supplied 'Traversal', in a bottom-up manner, monadically. ----- @'transformMOn' :: ('Monad' m, 'Plated' a) => 'Simple' 'Traversal' s a -> (a -> m a) -> s -> m s@+-- @+-- 'transformMOn' :: ('Monad' m, 'Plated' a) => 'Traversal'' s a -> (a -> m a) -> s -> m s+-- @ transformMOn :: (Monad m, Plated a) => LensLike (WrappedMonad m) s t a a -> (a -> m a) -> s -> m t transformMOn b = mapMOf b . transformM {-# INLINE transformMOn #-}  -- | Transform every element in a tree using a user supplied 'Traversal' in a bottom-up manner with a monadic effect. ----- @'transformMOf' :: 'Monad' m => 'Simple 'Traversal' a a -> (a -> m a) -> a -> m a@-transformMOf :: Monad m => SimpleLensLike (WrappedMonad m) a a -> (a -> m a) -> a -> m a+-- @+-- 'transformMOf' :: 'Monad' m => 'Traversal'' a a -> (a -> m a) -> a -> m a+-- @+transformMOf :: Monad m => LensLike' (WrappedMonad m) a a -> (a -> m a) -> a -> m a transformMOf l f = go where   go t = mapMOf l go t >>= f {-# INLINE transformMOf #-}@@ -407,8 +426,10 @@ -- | Transform every element in a tree that lies in a region indicated by a supplied 'Traversal', walking with a user supplied 'Traversal' in -- a bottom-up manner with a monadic effect. ----- @'transformMOnOf' :: 'Monad' m => 'Simple' 'Traversal' s a -> 'Simple' 'Traversal' a a -> (a -> m a) -> s -> m s@-transformMOnOf :: Monad m => LensLike (WrappedMonad m) s a a a -> SimpleLensLike (WrappedMonad m) a a -> (a -> m a) -> s -> m a+-- @+-- 'transformMOnOf' :: 'Monad' m => 'Traversal'' s a -> 'Traversal'' a a -> (a -> m a) -> s -> m s+-- @+transformMOnOf :: Monad m => LensLike (WrappedMonad m) s a a a -> LensLike' (WrappedMonad m) a a -> (a -> m a) -> s -> m a transformMOnOf b l = mapMOf b . transformMOf l {-# INLINE transformMOnOf #-} @@ -419,11 +440,13 @@ -- | Return a list of all of the editable contexts for every location in the structure, recursively. -- -- @--- propUniverse x = 'universe' x == 'map' 'pos' ('contexts' x)--- propId x = 'all' ('==' x) [extract w | w <- 'contexts' x]+-- propUniverse x = 'universe' x '==' 'map' 'Control.Comonad.Store.Class.pos' ('contexts' x)+-- propId x = 'all' ('==' x) ['Control.Lens.Internal.Context.extract' w | w <- 'contexts' x] -- @ ----- @'contexts' ≡ 'contextsOf' 'plate'@+-- @+-- 'contexts' ≡ 'contextsOf' 'plate'+-- @ contexts :: Plated a => a -> [Context a a a] contexts = contextsOf plate {-# INLINE contexts #-}@@ -431,78 +454,99 @@ -- | Return a list of all of the editable contexts for every location in the structure, recursively, using a user-specified 'Traversal' to walk each layer. -- -- @--- propUniverse l x = 'universeOf' l x == 'map' 'pos' ('contextsOf' l x)--- propId l x = 'all' ('==' x) [extract w | w <- 'contextsOf' l x]+-- propUniverse l x = 'universeOf' l x '==' 'map' 'Control.Comonad.Store.Class.pos' ('contextsOf' l x)+-- propId l x = 'all' ('==' x) ['Control.Lens.Internal.Context.extract' w | w <- 'contextsOf' l x] -- @ ----- @'contextsOf' :: 'Simple' 'Traversal' a a -> a -> ['Context' a a]@-contextsOf :: SimpleLensLike (Bazaar a a) a a -> a -> [Context a a a]-contextsOf l x = Context id x : f (holesOf l x) where+-- @+-- 'contextsOf' :: 'Traversal'' a a -> a -> ['Context' a a]+-- @+contextsOf :: ATraversal' a a -> a -> [Context a a a]+contextsOf l x = sell x : f (map context (holesOf l x)) where   f xs = do     Context ctx child <- xs-    Context context y <- contextsOf l child-    return $ Context (ctx . context) y+    Context cont y <- contextsOf l child+    return $ Context (ctx . cont) y {-# INLINE contextsOf #-}  -- | Return a list of all of the editable contexts for every location in the structure in an areas indicated by a user supplied 'Traversal', recursively using 'plate'. ----- @'contextsOn' b ≡ 'contextsOnOf' b 'plate'@+-- @+-- 'contextsOn' b ≡ 'contextsOnOf' b 'plate'+-- @ ----- @'contextsOn' :: 'Plated' a => 'Simple' 'Traversal' s a -> s -> ['Context' a a s]@-contextsOn :: Plated a => LensLike (Bazaar a a) s t a a -> s -> [Context a a t]+-- @+-- 'contextsOn' :: 'Plated' a => 'Traversal'' s a -> s -> ['Context' a a s]+-- @+contextsOn :: Plated a => ATraversal s t a a -> s -> [Context a a t] contextsOn b = contextsOnOf b plate {-# INLINE contextsOn #-}  -- | Return a list of all of the editable contexts for every location in the structure in an areas indicated by a user supplied 'Traversal', recursively using -- another user-supplied 'Traversal' to walk each layer. ----- @'contextsOnOf' :: 'Simple' 'Traversal' s a -> 'Simple' 'Traversal' a a -> s -> ['Context' a a s]@-contextsOnOf :: LensLike (Bazaar a a) s t a a -> SimpleLensLike (Bazaar a a) a a -> s -> [Context a a t]-contextsOnOf b l = f . holesOf b where+-- @+-- 'contextsOnOf' :: 'Traversal'' s a -> 'Traversal'' a a -> s -> ['Context' a a s]+-- @+contextsOnOf :: ATraversal s t a a -> ATraversal' a a -> s -> [Context a a t]+contextsOnOf b l = f . map context . holesOf b where   f xs = do     Context ctx child <- xs-    Context context y <- contextsOf l child-    return $ Context (ctx . context) y+    Context cont y <- contextsOf l child+    return $ Context (ctx . cont) y {-# INLINE contextsOnOf #-}  -- | The one-level version of 'context'. This extracts a list of the immediate children as editable contexts. ----- Given a context you can use 'pos' to see the values, 'peek' at what the structure would be like with an edited result, or simply 'extract' the original structure.+-- Given a context you can use 'Control.Comonad.Store.Class.pos' to see the values, 'Control.Comonad.Store.Class.peek' at what the structure would be like with an edited result, or simply 'Control.Lens.Internal.Context.extract' the original structure. -- -- @--- propChildren x = 'children' l x '==' 'map' 'pos' ('holes' l x)--- propId x = 'all' ('==' x) [extract w | w <- 'holes' l x]+-- propChildren x = 'children' l x '==' 'map' 'Control.Comonad.Store.Class.pos' ('holes' l x)+-- propId x = 'all' ('==' x) ['Control.Lens.Internal.Context.extract' w | w <- 'holes' l x] -- @ ----- @'holes' = 'holesOf' 'plate'@-holes :: Plated a => a -> [Context a a a]+-- @+-- 'holes' = 'holesOf' 'plate'+-- @+holes :: Plated a => a -> [Pretext (->) a a a] holes = holesOf plate {-# INLINE holes #-}  -- | An alias for 'holesOf', provided for consistency with the other combinators. ----- @'holesOn' ≡ 'holesOf'@+-- @+-- 'holesOn' ≡ 'holesOf'+-- @ -- -- @--- 'holesOn' :: 'Simple' 'Iso' s a       -> s -> ['Context' a a s]--- 'holesOn' :: 'Simple' 'Lens' s a      -> s -> ['Context' a a s]--- 'holesOn' :: 'Simple' 'Traversal' s a -> s -> ['Context' a a s]+-- 'holesOn' :: 'Iso'' s a                -> s -> ['Pretext' (->) a a s]+-- 'holesOn' :: 'Lens'' s a               -> s -> ['Pretext' (->) a a s]+-- 'holesOn' :: 'Traversal'' s a          -> s -> ['Pretext' (->) a a s]+-- 'holesOn' :: 'IndexedLens'' i s a      -> s -> ['Pretext' ('Control.Lens.Internal.Indexed.Indexed' i) a a s]+-- 'holesOn' :: 'IndexedTraversal'' i s a -> s -> ['Pretext' ('Control.Lens.Internal.Indexed.Indexed' i) a a s] -- @-holesOn :: LensLike (Bazaar a a) s t a a -> s -> [Context a a t]+holesOn :: Conjoined p => Overloading p (->) (Bazaar p a a) s t a a -> s -> [Pretext p a a t] holesOn = holesOf {-# INLINE holesOn #-} --- | Extract one level of holes from a container in a region specified by one 'Traversal', using another.+-- | Extract one level of 'holes' from a container in a region specified by one 'Traversal', using another. ----- @'holesOnOf' b l ≡ 'holesOf' (b '.' l)@+-- @+-- 'holesOnOf' b l ≡ 'holesOf' (b '.' l)+-- @ -- -- @--- 'holesOnOf' :: 'Simple' 'Iso' s a       -> 'Simple' 'Iso' a a       -> s -> ['Context' a a s]--- 'holesOnOf' :: 'Simple' 'Lens' s a      -> 'Simple' 'Lens' a a      -> s -> ['Context' a a s]--- 'holesOnOf' :: 'Simple' 'Traversal' s a -> 'Simple' 'Traversal' a a -> s -> ['Context' a a s]+-- 'holesOnOf' :: 'Iso'' s a       -> 'Iso'' a a                -> s -> ['Pretext' (->) a a s]+-- 'holesOnOf' :: 'Lens'' s a      -> 'Lens'' a a               -> s -> ['Pretext' (->) a a s]+-- 'holesOnOf' :: 'Traversal'' s a -> 'Traversal'' a a          -> s -> ['Pretext' (->) a a s]+-- 'holesOnOf' :: 'Lens'' s a      -> 'IndexedLens'' i a a      -> s -> ['Pretext' ('Control.Lens.Internal.Indexed.Indexed' i) a a s]+-- 'holesOnOf' :: 'Traversal'' s a -> 'IndexedTraversal'' i a a -> s -> ['Pretext' ('Control.Lens.Internal.Indexed.Indexed' i) a a s] -- @-holesOnOf :: LensLike (Bazaar r r) s t a b -> LensLike (Bazaar r r) a b r r -> s -> [Context r r t]-holesOnOf b l = holesOf (b.l)+holesOnOf :: Conjoined p+          => LensLike (Bazaar p  r r) s t a b+          -> Overloading p (->) (Bazaar p r r) a b r r+          -> s -> [Pretext p r r t]+holesOnOf b l = holesOf (b . l) {-# INLINE holesOnOf #-}  -------------------------------------------------------------------------------@@ -511,7 +555,9 @@  -- | Perform a fold-like computation on each value, technically a paramorphism. ----- @'paraOf' :: 'Fold' a a -> (a -> [r] -> r) -> a -> r@+-- @+-- 'paraOf' :: 'Fold' a a -> (a -> [r] -> r) -> a -> r+-- @ paraOf :: Getting (Endo [a]) a b a b -> (a -> [r] -> r) -> a -> r paraOf l f = go where   go a = f a (go <$> toListOf l a)@@ -519,7 +565,9 @@  -- | Perform a fold-like computation on each value, technically a paramorphism. ----- @'para' ≡ 'paraOf' 'plate'@+-- @+-- 'para' ≡ 'paraOf' 'plate'+-- @ para :: Plated a => (a -> [r] -> r) -> a -> r para = paraOf plate {-# INLINE para #-}@@ -545,7 +593,9 @@  -- | Fold the immediate children of a 'Plated' container. ----- @'composOpFold' z c f = 'foldrOf' 'plate' (c '.' f) z@+-- @+-- 'composOpFold' z c f = 'foldrOf' 'plate' (c '.' f) z+-- @ composOpFold :: Plated a => b -> (b -> b -> b) -> (a -> b) -> a -> b composOpFold z c f = foldrOf plate (c . f) z {-# INLINE composOpFold #-}@@ -556,10 +606,12 @@  -- | The original @uniplate@ combinator, implemented in terms of 'Plated' as a 'Lens'. ----- @'parts' ≡ 'partsOf' 'plate'@+-- @+-- 'parts' ≡ 'partsOf' 'plate'+-- @ ----- The resulting lens is safer to use as it ignores 'over-application' and deals gracefully with under-application,--- but it is only a proper lens if you don't change the list 'length'!-parts :: Plated a => Simple Lens a [a]+-- The resulting 'Lens' is safer to use as it ignores 'over-application' and deals gracefully with under-application,+-- but it is only a proper 'Lens' if you don't change the list 'length'!+parts :: Plated a => Lens' a [a] parts = partsOf plate {-# INLINE parts #-}
src/Control/Lens/Prism.hs view
@@ -1,16 +1,12 @@ {-# LANGUAGE CPP #-}-{-# LANGUAGE GADTs #-} {-# LANGUAGE Rank2Types #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE MultiParamTypeClasses #-} #ifdef TRUSTWORTHY {-# LANGUAGE Trustworthy #-} #endif ------------------------------------------------------------------------------- -- | -- Module      :  Control.Lens.Prism--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  provisional@@ -20,47 +16,39 @@ module Control.Lens.Prism   (   -- * Prisms-    Prism-  , APrism+    Prism, Prism'+  , APrism, APrism'   -- * Constructing Prisms-  , Prismatic(..)-  , Prismoid(..)-+  , prism+  , prism'   -- * Consuming Prisms   , clonePrism-  , remit-  , review, reviews-  , reuse, reuses   , outside   , aside   , without-+  , isn't   -- * Common Prisms-  , _left-  , _right-  , _just--  -- * Simple-  , SimplePrism+  , _Left+  , _Right+  , _Just+  -- * Prismatic profunctors+  , Choice(..)   ) where  import Control.Applicative-import Control.Arrow-import Control.Category-import Control.Monad.Reader as Reader-import Control.Monad.State as State-import Control.Lens.Classes import Control.Lens.Combinators-import Control.Lens.Getter-import Control.Lens.Internal+import Control.Lens.Internal.Prism+import Control.Lens.Internal.Setter import Control.Lens.Type-import Prelude hiding (id,(.))+import Data.Bifunctor+import Data.Profunctor+#ifndef SAFE+import Unsafe.Coerce+#endif  -- $setup -- >>> import Control.Lens -- >>> import Numeric.Natural--- >>> :set -XFlexibleContexts -XTypeFamilies--- >>> let nat :: Simple Prism Integer Natural; nat = prism toInteger $ \i -> if i <= 0 then Left i else Right (fromInteger i) -- >>> let isLeft  (Left  _) = True; isLeft  _ = False -- >>> let isRight (Right _) = True; isRight _ = False @@ -68,292 +56,148 @@ -- Prism Internals ------------------------------------------------------------------------------ --- | A 'Prism' @l@ is a 0-or-1 target 'Traversal' that can also be turned around with 'remit' to--- obtain a 'Getter' in the opposite direction.------ There are two laws that a 'Prism' should satisfy:------ First, if I 'remit' or 'review' a value with a 'Prism' and then 'preview' or use ('^?'), I will get it back:------ * @'preview' l ('review' l b) ≡ 'Just' b@------ Second, if you can extract a value @a@ using a Prism @l@ from a value @s@, then the value @s@ is completely described my @l@ and @a@:------ * If @'preview' l s ≡ 'Just' a@ then @'review' l a ≡ s@------ These two laws imply that the 'Traversal' laws hold for every 'Prism' and that we 'traverse' at most 1 element:------ @'Control.Lens.Fold.lengthOf' l x '<=' 1@------ It may help to think of this as a 'Control.Lens.Iso.Iso' that can be partial in one direction.------ Every 'Prism' is a valid 'Traversal'.------ Every 'Control.Lens.Iso.Iso' is a valid 'Prism'.------ For example, you might have a @'Simple' 'Prism' 'Integer' Natural@ allows you to always--- go from a 'Natural' to an 'Integer', and provide you with tools to check if an 'Integer' is--- a 'Natural' and/or to edit one if it is.--------- @--- 'nat' :: 'Simple' 'Prism' 'Integer' 'Numeric.Natural.Natural'--- 'nat' = 'prism' 'toInteger' '$' \\ i ->---    if i '<' 0---    then 'Left' i---    else 'Right' ('fromInteger' i)--- @------ Now we can ask if an 'Integer' is a 'Natural'.------ >>> 5^?nat--- Just 5------ >>> (-5)^?nat--- Nothing------ We can update the ones that are:------ >>> (-3,4) & both.nat *~ 2--- (-3,8)------ And we can then convert from a 'Natural' to an 'Integer'.------ >>> 5 ^. remit nat -- :: Natural--- 5------ Similarly we can use a 'Prism' to 'traverse' the left half of an 'Either':------ >>> Left "hello" & _left %~ length--- Left 5------ or to construct an 'Either':------ >>> 5^.remit _left--- Left 5------ such that if you query it with the 'Prism', you will get your original input back.------ >>> 5^.remit _left ^? _left--- Just 5------ Another interesting way to think of a 'Prism' is as the categorical dual of a 'Lens'--- -- a /co/-'Lens', so to speak. This is what permits the construction of 'outside'.-type Prism s t a b = forall k f. (Prismatic k, Applicative f) => k (a -> f b) (s -> f t)+-- | If you see this in a signature for a function, the function is expecting a 'Prism'.+type APrism s t a b = Market a b a (Mutator b) -> Market a b s (Mutator t) --- | If you see this in a signature for a function, the function is expecting a 'Prism',--- not some kind of alien invader.-type APrism s t a b = Overloaded Prismoid Mutator s t a b+-- | @+-- type APrism' = 'Simple' 'APrism'+-- @+type APrism' s a = APrism s s a a --- | A @'Simple' 'Prism'@.-type SimplePrism s a = Prism s s a a+-- | Convert 'APrism' to the pair of functions that characterize it.+runPrism :: APrism s t a b -> Market a b s t+#ifdef SAFE+runPrism k = case k (Market Mutator Right) of+  Market bt seta -> Market (runMutator #. bt) (either (Left . runMutator) Right . seta)+#else+runPrism k = unsafeCoerce (k (Market Mutator Right))+#endif+{-# INLINE runPrism #-}  -- | Clone a 'Prism' so that you can reuse the same monomorphically typed 'Prism' for different purposes. ----- See 'cloneLens' and 'cloneTraversal' for examples of why you might want to do this.+-- See 'Control.Lens.Lens.cloneLens' and 'Control.Lens.Traversal.cloneTraversal' for examples of why you might want to do this. clonePrism :: APrism s t a b -> Prism s t a b-clonePrism Prismoid    = id-clonePrism (Prism f g) = prism f g+clonePrism k = case runPrism k of+  Market bt seta -> prism bt seta+{-# INLINE clonePrism #-}  ------------------------------------------------------------------------------ -- Prism Combinators ------------------------------------------------------------------------------ +-- | Build a 'Control.Lens.Prism.Prism'.+--+-- @'Either' t a@ is used instead of @'Maybe' a@ to permit the types of @s@ and @t@ to differ.+prism :: (b -> t) -> (s -> Either t a) -> Prism s t a b+prism bt seta = dimap seta (either pure (fmap bt)) . right'+{-# INLINE prism #-}++-- | Build a 'Prism''.+prism' :: (a -> s) -> (s -> Maybe a) -> Prism' s a+prism' as sma = prism as (\s -> maybe (Left s) Right (sma s))+{-# INLINE prism' #-}+ -- | Use a 'Prism' as a kind of first-class pattern. -- -- @'outside' :: 'Prism' s t a b -> 'Lens' (t -> r) (s -> r) (b -> r) (a -> r)@ outside :: APrism s t a b -> Lens (t -> r) (s -> r) (b -> r) (a -> r)-outside Prismoid        f tr = f tr-outside (Prism bt seta) f tr = f (tr.bt) <&> \ar -> either tr ar . seta+outside k = case runPrism k of+  Market bt seta -> \f tr -> f (tr.bt) <&> \ar -> either tr ar . seta+{-# INLINE outside #-}  -- | Use a 'Prism' to work over part of a structure. aside :: APrism s t a b -> Prism (e, s) (e, t) (e, a) (e, b)-aside Prismoid = id-aside (Prism bt seta) = prism (fmap bt) $ \(e,s) -> case seta s of-  Left t -> Left (e,t)-  Right a -> Right (e,a)+aside k = case runPrism k of+  Market bt seta -> prism (fmap bt) $ \(e,s) -> case seta s of+    Left t -> Left (e,t)+    Right a -> Right (e,a)+{-# INLINE aside #-}  -- | Given a pair of prisms, project sums. ----- Viewing a 'Prism' as a co-lens, this combinator can be seen to be dual to 'alongside'.+-- Viewing a 'Prism' as a co-'Lens', this combinator can be seen to be dual to 'Control.Lens.Lens.alongside'. without :: APrism s t a b         -> APrism u v c d         -> Prism (Either s u) (Either t v) (Either a c) (Either b d)-without Prismoid Prismoid = id-without (Prism bt seta) Prismoid = prism (left bt) go where-  go (Left s) = either (Left . Left) (Right . Left) (seta s)-  go (Right u) = Right (Right u)-without Prismoid (Prism dv uevc) = prism (right dv) go where-  go (Left s) = Right (Left s)-  go (Right u) = either (Left . Right) (Right . Right) (uevc u)-without (Prism bt seta) (Prism dv uevc) = prism (bt +++ dv) go where-  go (Left s) = either (Left . Left) (Right . Left) (seta s)-  go (Right u) = either (Left . Right) (Right . Right) (uevc u)---- | Turn a 'Prism' or 'Control.Lens.Iso.Iso' around to build a 'Getter'.------ If you have an 'Control.Lens.Iso.Iso', 'Control.Lens.Iso.from' is a more powerful version of this function--- that will return an 'Control.Lens.Iso.Iso' instead of a mere 'Getter'.------ >>> 5 ^.remit _left--- Left 5------ @--- 'remit' :: 'Prism' s t a b -> 'Getter' b t--- 'remit' :: 'Iso' s t a b   -> 'Getter' b t--- @-remit :: APrism s t a b -> Getter b t-remit Prismoid     = id-remit (Prism bt _) = to bt---- | This can be used to turn an 'Control.Lens.Iso.Iso' or 'Prism' around and 'view' a value (or the current environment) through it the other way.------ @'review' ≡ 'view' '.' 'remit'@------ >>> review _left "mustard"--- Left "mustard"------ Usually 'review' is used in the @(->)@ monad with a 'Simple' 'Prism' or 'Control.Lens.Iso.Iso', in which case it may be useful to think of--- it as having one of these more restricted type signatures:------ @--- 'review' :: 'Simple' 'Iso' s a        -> a -> s--- 'review' :: 'Simple' 'Prism' s a -> a -> s--- @------ However, when working with a monad transformer stack, it is sometimes useful to be able to 'review' the current environment, in which case one of--- these more slightly more liberal type signatures may be beneficial to think of it as having:------ @--- 'review' :: 'MonadReader' a m => 'Simple' 'Iso' s a        -> m s--- 'review' :: 'MonadReader' a m => 'Simple' 'Prism' s a -> m s--- @-review :: MonadReader b m => APrism s t a b -> m t-review Prismoid     = ask-review (Prism bt _) = asks bt-{-# INLINE review #-}---- | This can be used to turn an 'Control.Lens.Iso.Iso' or 'Prism' around and 'view' a value (or the current environment) through it the other way,--- applying a function.------ @'reviews' ≡ 'views' '.' 'remit'@------ >>> reviews _left isRight "mustard"--- False------ Usually this function is used in the @(->)@ monad with a 'Simple' 'Prism' or 'Control.Lens.Iso.Iso', in which case it may be useful to think of--- it as having one of these more restricted type signatures:------ @--- 'reviews' :: 'Simple' 'Iso' s a        -> (s -> r) -> a -> r--- 'reviews' :: 'Simple' 'Prism' s a -> (s -> r) -> a -> r--- @------ However, when working with a monad transformer stack, it is sometimes useful to be able to 'review' the current environment, in which case one of--- these more slightly more liberal type signatures may be beneficial to think of it as having:------ @--- 'reviews' :: 'MonadReader' a m => 'Simple' 'Iso' s a        -> (s -> r) -> m r--- 'reviews' :: 'MonadReader' a m => 'Simple' 'Prism' s a -> (s -> r) -> m r--- @-reviews :: MonadReader b m => APrism s t a b -> (t -> r) -> m r-reviews Prismoid     f = asks f-reviews (Prism bt _) f = asks (f . bt)-{-# INLINE reviews #-}---- | This can be used to turn an 'Control.Lens.Iso.Iso' or 'Prism' around and 'use' a value (or the current environment) through it the other way.------ @'reuse' ≡ 'use' '.' 'remit'@------ >>> evalState (reuse _left) 5--- Left 5------ @--- 'reuse' :: 'MonadState' a m => 'Simple' 'Prism' s a -> m s--- 'reuse' :: 'MonadState' a m => 'Simple' 'Iso' s a        -> m s--- @-reuse :: MonadState b m => APrism s t a b -> m t-reuse Prismoid     = get-reuse (Prism bt _) = gets bt-{-# INLINE reuse #-}+without k = case runPrism k of+  Market bt seta -> \ k' -> case runPrism k' of+    Market dv uevc -> prism (bimap bt dv) $ \su -> case su of+      Left s  -> bimap Left Left (seta s)+      Right u -> bimap Right Right (uevc u)+{-# INLINE without #-} --- | This can be used to turn an 'Control.Lens.Iso.Iso' or 'Prism' around and 'use' the current state through it the other way,--- applying a function.------ @'reuses' ≡ 'uses' '.' 'remit'@+-- | Check to see if this 'Prism' doesn't match. ----- >>> evalState (reuses _left isLeft) (5 :: Int)+-- >>> isn't _Left (Right 12) -- True ----- @--- 'reuses' :: 'MonadState' a m => 'Simple' 'Prism' s a -> (s -> r) -> m r--- 'reuses' :: 'MonadState' a m => 'Simple' 'Iso' s a        -> (s -> r) -> m r--- @-reuses :: MonadState b m => APrism s t a b -> (t -> r) -> m r-reuses Prismoid     f = gets f-reuses (Prism bt _) f = gets (f . bt)-{-# INLINE reuses #-}+-- >>> isn't _Left (Left 12)+-- False+isn't :: APrism s t a b -> s -> Bool+isn't k s = case runPrism k of+  Market _ seta -> case seta s of+    Left _ -> True+    Right _ -> False+{-# INLINE isn't #-}  ------------------------------------------------------------------------------ -- Common Prisms ------------------------------------------------------------------------------ --- | This prism provides a traversal for tweaking the left-hand value of an 'Either':+-- | This 'Prism' provides a 'Traversal' for tweaking the 'Left' half of an 'Either': ----- >>> over _left (+1) (Left 2)+-- >>> over _Left (+1) (Left 2) -- Left 3 ----- >>> over _left (+1) (Right 2)+-- >>> over _Left (+1) (Right 2) -- Right 2 ----- >>> Right 42 ^._left :: String+-- >>> Right 42 ^._Left :: String -- "" ----- >>> Left "hello" ^._left+-- >>> Left "hello" ^._Left -- "hello" -- -- It also can be turned around to obtain the embedding into the 'Left' half of an 'Either': ----- >>> 5^.remit _left+-- >>> 5^.re _Left -- Left 5-_left :: Prism (Either a c) (Either b c) a b-_left = prism Left $ either Right (Left . Right)-{-# INLINE _left #-}+_Left :: Prism (Either a c) (Either b c) a b+_Left = prism Left $ either Right (Left . Right)+{-# INLINE _Left #-} --- | This prism provides a traversal for tweaking the right-hand value of an 'Either':+-- | This 'Prism' provides a 'Traversal' for tweaking the 'Right' half of an 'Either': ----- >>> over _right (+1) (Left 2)+-- >>> over _Right (+1) (Left 2) -- Left 2 ----- >>> over _right (+1) (Right 2)+-- >>> over _Right (+1) (Right 2) -- Right 3 ----- >>> Right "hello" ^._right+-- >>> Right "hello" ^._Right -- "hello" ----- >>> Left "hello" ^._right :: [Double]+-- >>> Left "hello" ^._Right :: [Double] -- [] -- -- It also can be turned around to obtain the embedding into the 'Right' half of an 'Either': ----- >>> 5^.remit _right+-- >>> 5^.re _Right -- Right 5------ (Unfortunately the instance for--- @'Data.Traversable.Traversable' ('Either' c)@ is still missing from base,--- so this can't just be 'Data.Traversable.traverse'.)-_right :: Prism (Either c a) (Either c b) a b-_right = prism Right $ left Left-{-# INLINE _right #-}+_Right :: Prism (Either c a) (Either c b) a b+_Right = prism Right $ either (Left . Left) Right+{-# INLINE _Right #-} --- | This prism provides a traversal for tweaking the target of the value of 'Just' in a 'Maybe'.+-- | This 'Prism' provides a 'Traversal' for tweaking the target of the value of 'Just' in a 'Maybe'. ----- >>> over _just (+1) (Just 2)+-- >>> over _Just (+1) (Just 2) -- Just 3 ----- Unlike 'traverse' this is a 'Prism', and so you can use it to inject as well:+-- Unlike 'Data.Traversable.traverse' this is a 'Prism', and so you can use it to inject as well: ----- >>> 5^.remit _just+-- >>> 5^.re _Just -- Just 5-_just :: Prism (Maybe a) (Maybe b) a b-_just = prism Just $ maybe (Left Nothing) Right+_Just :: Prism (Maybe a) (Maybe b) a b+_Just = prism Just $ maybe (Left Nothing) Right+{-# INLINE _Just #-}
+ src/Control/Lens/Reified.hs view
@@ -0,0 +1,92 @@+{-# LANGUAGE Rank2Types #-}+------------------------------------------------------------------------------+-- |+-- Module      :  Control.Lens.Reified+-- Copyright   :  (C) 2012-13 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  provisional+-- Portability :  Rank2Types+--+------------------------------------------------------------------------------+module Control.Lens.Reified where++import Control.Lens.Type++------------------------------------------------------------------------------+-- Reifying+------------------------------------------------------------------------------++-- | Reify a 'Lens' so it can be stored safely in a container.+newtype ReifiedLens s t a b = ReifyLens { reflectLens :: Lens s t a b }++-- | @+-- type 'ReifiedLens'' = 'Simple' 'ReifiedLens'+-- @+type ReifiedLens' s a = ReifiedLens s s a a++-- | Reify an 'IndexedLens' so it can be stored safely in a container.+newtype ReifiedIndexedLens i s t a b = ReifyIndexedLens { reflectIndexedLens :: IndexedLens i s t a b }++-- | @+-- type 'ReifiedIndexedLens'' i = 'Simple' ('ReifiedIndexedLens' i)+-- @+type ReifiedIndexedLens' i s a = ReifiedIndexedLens i s s a a++-- | Reify an 'IndexedTraversal' so it can be stored safely in a container.+newtype ReifiedIndexedTraversal i s t a b = ReifyIndexedTraversal { reflectIndexedTraversal :: IndexedTraversal i s t a b }++-- | @+-- type 'ReifiedIndexedTraversal'' i = 'Simple' ('ReifiedIndexedTraversal' i)+-- @+type ReifiedIndexedTraversal' i s a = ReifiedIndexedTraversal i s s a a++-- | A form of 'Traversal' that can be stored monomorphically in a container.+data ReifiedTraversal s t a b = ReifyTraversal { reflectTraversal :: Traversal s t a b }++-- | @+-- type 'ReifiedTraversal'' = 'Simple' 'ReifiedTraversal'+-- @+type ReifiedTraversal' s a = ReifiedTraversal s s a a++-- | Reify a 'Getter' so it can be stored safely in a container.+newtype ReifiedGetter s a = ReifyGetter { reflectGetter :: Getter s a }++-- | Reify an 'IndexedGetter' so it can be stored safely in a container.+newtype ReifiedIndexedGetter i s a = ReifyIndexedGetter { reflectIndexedGetter :: IndexedGetter i s a }++-- | Reify a 'Fold' so it can be stored safely in a container.+newtype ReifiedFold s a = ReifyFold { reflectFold :: Fold s a }++-- | Reify a 'Setter' so it can be stored safely in a container.+newtype ReifiedSetter s t a b = ReifySetter { reflectSetter :: Setter s t a b }++-- | @+-- type 'ReifiedSetter'' = 'Simple' 'ReifiedSetter'+-- @+type ReifiedSetter' s a = ReifiedSetter s s a a++-- | Reify an 'IndexedSetter' so it can be stored safely in a container.+newtype ReifiedIndexedSetter i s t a b =+  ReifyIndexedSetter { reflectIndexedSetter :: IndexedSetter i s t a b }++-- | @+-- type 'ReifiedIndexedSetter'' i = 'Simple' ('ReifiedIndexedSetter' i)+-- @+type ReifiedIndexedSetter' i s a = ReifiedIndexedSetter i s s a a++-- | Reify an 'Iso' so it can be stored safely in a container.+newtype ReifiedIso s t a b = ReifyIso { reflectIso :: Iso s t a b }++-- | @+-- type 'ReifiedIso'' = 'Simple' 'ReifiedIso'+-- @+type ReifiedIso' s a = ReifiedIso s s a a++-- | Reify a 'Prism' so it can be stored safely in a container.+newtype ReifiedPrism s t a b = ReifyPrism { reflectPrism :: Prism s t a b }++-- | @+-- type 'ReifiedPrism'' = 'Simple' 'ReifiedPrism'+-- @+type ReifiedPrism' s a = ReifiedPrism s s a a
− src/Control/Lens/Representable.hs
@@ -1,320 +0,0 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE MagicHash #-}-{-# LANGUAGE RankNTypes #-}-{-# LANGUAGE FlexibleContexts #-}-#ifdef TRUSTWORTHY-{-# LANGUAGE Trustworthy #-}-#endif--------------------------------------------------------------------------------- |--- Module      :  Control.Lens.Representable--- Copyright   :  (C) 2012 Edward Kmett--- License     :  BSD-style (see the file LICENSE)--- Maintainer  :  Edward Kmett <ekmett@gmail.com>--- Stability   :  provisional--- Portability :  RankNTypes------ Corepresentable endofunctors represented by their polymorphic lenses------ The polymorphic lenses of the form @(forall x. 'Lens' (f x) x)@ each--- represent a distinct path into a functor @f@. If the functor is entirely--- characterized by assigning values to these paths, then the functor is--- representable.------ Consider the following example.------ > import Control.Lens--- > import Data.Distributive------ > data Pair a = Pair { _x :: a, _y :: a }------ @ 'Control.Lens.TH.makeLenses' \'\'Pair@------ @--- instance 'Representable' Pair where---   'rep' f = Pair (f x) (f y)--- @------ From there, you can get definitions for a number of instances for free.------ @--- instance 'Applicative' Pair where---   'pure'  = 'pureRep'---   ('<*>') = 'apRep'--- @------ @--- instance 'Monad' Pair where---   'return' = 'pureRep'---   ('>>=') = 'bindRep'--- @------ @--- instance 'Data.Distributive.Distributive' Pair where---   'Data.Distributive.distribute' = 'distributeRep'--- @---------------------------------------------------------------------------------module Control.Lens.Representable-  (-  -- * Representable Functors-    Representable(..)-  -- * Using Lenses as Representations-  , Rep-  -- * Default definitions-  , fmapRep-  , pureRep-  , apRep-  , bindRep-  , distributeRep-  -- * Wrapped Representations-  , Path(..)-  , paths-  , tabulated-  -- * Setting with Representation-  , rmap-  -- * Folding with Representation-  , rfoldMap-  , rfoldr-  -- * Traversing with Representation-  , rtraverse-  , rtraverse_-  , rfor-  , rmapM-  , rmapM_-  , rforM-  -- * Representable Setters, Folds and Traversals-  , rmapped-  , rfolded-  , rtraversed-  ) where--import Control.Applicative-import Control.Lens.Classes-import Control.Lens.Getter-import Control.Lens.IndexedFold-import Control.Lens.IndexedLens-import Control.Lens.IndexedSetter-import Control.Lens.IndexedTraversal-import Control.Lens.Internal-import Control.Lens.Internal.Combinators-import Control.Lens.Type-import Control.Lens.Wrapped-import Data.Foldable         as Foldable-import Data.Functor.Identity-import Data.Monoid-import Data.Traversable      as Traversable---- | The representation of a 'Representable' 'Functor' as Lenses-type Rep f = forall a. Simple Lens (f a) a---- | Representable Functors.------ A 'Functor' @f@ is 'Representable' if it is isomorphic to @(x -> a)@--- for some x. Nearly all such functors can be represented by choosing @x@ to be--- the set of lenses that are polymorphic in the contents of the 'Functor',--- that is to say @x = 'Rep' f@ is a valid choice of 'x' for (nearly) every--- 'Representable' 'Functor'.------ Note: Some sources refer to covariant representable functors as--- corepresentable functors, and leave the \"representable\" name to--- contravariant functors (those are isomorphic to @(a -> x)@ for some @x@).------ As the covariant case is vastly more common, and both are often referred to--- as representable functors, we choose to call these functors 'Representable'--- here.-class Functor f => Representable f where-  rep :: (Rep f -> a) -> f a--instance Representable Identity where-  rep f = Identity (f (unwrapping Identity))---- | NB: The 'Eq' requirement on this instance is a consequence of the choice of 'Lens' as a 'Rep', it isn't fundamental.-instance Eq e => Representable ((->) e) where-  rep f e = f (resultAt e)---- | 'fmapRep' is a valid default definition for 'fmap' for a 'Representable'--- functor.------ @'fmapRep' f m = 'rep' '$' \\i -> f (m '^.' i)@------ Usage for a @'Representable' Foo@:------ @--- instance 'Functor' Foo where---   'fmap' = 'fmapRep'--- @-fmapRep :: Representable f => (a -> b) -> f a -> f b-fmapRep f m = rep $ \i -> f (m^.i)-{-# INLINE fmapRep #-}---- | 'pureRep' is a valid default definition for 'pure' and 'return' for a--- 'Representable' functor.------ @'pureRep' = 'rep' . 'const'@------ Usage for a @'Representable' Foo@:------ @--- instance 'Applicative' Foo where---   'pure' = 'pureRep'---   ...--- @------ @--- instance 'Monad' Foo where---   'return' = 'pureRep'---   ...--- @-pureRep :: Representable f => a -> f a-pureRep = rep . const-{-# INLINE pureRep #-}---- | 'apRep' is a valid default definition for ('<*>') for a 'Representable'--- functor.------ @'apRep' mf ma = 'rep' '$' \\i -> mf '^.' i '$' ma '^.' i@------ Usage for a @'Representable' Foo@:------ @--- instance 'Applicative' Foo where---   'pure' = 'pureRep'---   ('<*>') = 'apRep'--- @-apRep :: Representable f => f (a -> b) -> f a -> f b-apRep mf ma = rep $ \i -> mf^.i $ ma^.i-{-# INLINE apRep #-}---- | 'bindRep' is a valid default default definition for '(>>=)' for a--- representable functor.------ @'bindRep' m f = 'rep' '$' \\i -> f (m '^.' i) '^.' i@------ Usage for a @'Representable' Foo@:------ @--- instance 'Monad' Foo where---   'return' = 'pureRep'---   ('>>=') = 'bindRep'--- @-bindRep :: Representable f => f a -> (a -> f b) -> f b-bindRep m f = rep $ \i -> f(m^.i)^.i-{-# INLINE bindRep #-}---- | A default definition for 'Data.Distributive.distribute' for a 'Representable' 'Functor'------ @'distributeRep' wf = 'rep' '$' \\i -> 'fmap' ('^.' i) wf@------ Usage for a @'Representable' Foo@:------ @--- instance 'Data.Distributive.Distributive' Foo where---   'Data.Distributive.distribute' = 'distributeRep'--- @-distributeRep :: (Representable f, Functor w) => w (f a) -> f (w a)-distributeRep wf = rep $ \i -> fmap (^.i) wf-{-# INLINE distributeRep #-}---------------------------------------------------------------------------------- Paths---------------------------------------------------------------------------------- | Sometimes you need to store a path lens into a container, but at least--- at this time, @ImpredicativePolymorphism@ in GHC is somewhat lacking.------ This type provides a way to, say, store a @[]@ of paths.-newtype Path f = Path { walk :: Rep f }---- | A 'Representable' 'Functor' has a fixed shape. This fills each position--- in it with a 'Path'-paths :: Representable f => f (Path f)-paths = rep Path-{-# INLINE paths #-}---- | A version of 'rep' that is an isomorphism. Predicativity requires that--- we wrap the 'Rep' as a 'Key', however.-tabulated :: Representable f => (Path f -> a) -> f a-tabulated f = rep (f . Path)-{-# INLINE tabulated #-}---------------------------------------------------------------------------------- Traversal---------------------------------------------------------------------------------- | Map over a 'Representable' functor with access to the 'Lens' for the--- current position------ @'rmap' f m = 'rep' '$' \\i -> f i (m '^.' i)@-rmap :: Representable f => (Rep f -> a -> b) -> f a -> f b-rmap f m = rep $ \i -> f i (m^.i)-{-# INLINE rmap #-}---- | Traverse a 'Representable' functor with access to the current path-rtraverse :: (Representable f, Traversable f, Applicative g)-          => (Rep f -> a -> g b) -> f a -> g (f b)-rtraverse f m = sequenceA (rmap f m)-{-# INLINE rtraverse #-}---- | Traverse a 'Representable' functor with access to the current path--- as a 'Lens', discarding the result-rtraverse_ :: (Representable f, Foldable f, Applicative g)-           => (Rep f -> a -> g b) -> f a -> g ()-rtraverse_ f m = sequenceA_ (rmap f m)-{-# INLINE rtraverse_ #-}---- | Traverse a 'Representable' functor with access to the current path--- and a 'Lens' (and the arguments flipped)-rfor :: (Representable f, Traversable f, Applicative g)-     => f a -> (Rep f -> a -> g b) -> g (f b)-rfor m f = sequenceA (rmap f m)-{-# INLINE rfor #-}---- | 'mapM' over a 'Representable' functor with access to the current path--- as a 'Lens'-rmapM :: (Representable f, Traversable f, Monad m)-      => (Rep f -> a -> m b) -> f a -> m (f b)-rmapM f m = Traversable.sequence (rmap f m)-{-# INLINE rmapM #-}---- | 'mapM' over a 'Representable' functor with access to the current path--- as a 'Lens', discarding the result-rmapM_ :: (Representable f, Foldable f, Monad m)-       => (Rep f -> a -> m b) -> f a -> m ()-rmapM_ f m = Foldable.sequence_ (rmap f m)-{-# INLINE rmapM_ #-}---- | 'mapM' over a 'Representable' functor with access to the current path--- as a 'Lens' (with the arguments flipped)-rforM :: (Representable f, Traversable f, Monad m)-      => f a -> (Rep f -> a -> m b) -> m (f b)-rforM m f = Traversable.sequence (rmap f m)-{-# INLINE rforM #-}---- | Fold over a 'Representable' functor with access to the current path--- as a 'Lens', yielding a 'Monoid'-rfoldMap :: (Representable f, Foldable f, Monoid m)-         => (Rep f -> a -> m) -> f a -> m-rfoldMap f m = fold (rmap f m)-{-# INLINE rfoldMap #-}---- | Fold over a 'Representable' functor with access to the current path--- as a 'Lens'.-rfoldr :: (Representable f, Foldable f) => (Rep f -> a -> b -> b) -> b -> f a -> b-rfoldr f b m = Foldable.foldr id b (rmap f m)-{-# INLINE rfoldr #-}---- | An 'IndexedSetter' that walks an 'Representable' 'Functor' using a 'Path' for an index.-rmapped :: Representable f => IndexedSetter (Path f) (f a) (f b) a b-rmapped = indexed $ \f -> tainted# (rmap (\i -> untainted# (f (Path i))))-{-# INLINE rmapped #-}---- | An 'IndexedFold' that walks an 'Foldable' 'Representable' 'Functor' using a 'Path' for an index.-rfolded :: (Representable f, Foldable f) => IndexedFold (Path f) (f a) a-rfolded = indexed $ \f -> coerce . getFolding . rfoldMap (\i -> folding# (f (Path i)))-{-# INLINE rfolded #-}---- | An 'IndexedTraversal' for a 'Traversable' 'Representable' 'Functor'.-rtraversed :: (Representable f, Traversable f) => IndexedTraversal (Path f) (f a) (f b) a b-rtraversed = indexed $ \ f -> sequenceA . rmap (f . Path)-{-# INLINE rtraversed #-}
+ src/Control/Lens/Review.hs view
@@ -0,0 +1,185 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE Rank2Types #-}+#ifdef TRUSTWORTHY+{-# LANGUAGE Trustworthy #-}+#endif+-------------------------------------------------------------------------------+-- |+-- Module      :  Control.Lens.Review+-- Copyright   :  (C) 2012-13 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  provisional+-- Portability :  non-portable+--+-- A 'Review' is a type-restricted form of a 'Prism' that can only be used for+-- writing back via 're', 'review', 'reuse'.+-------------------------------------------------------------------------------+module Control.Lens.Review+  (+  -- * Reviewing+    Review, Review'+  , AReview, AReview'+  , unto+  , re+  , review, reviews+  , reuse, reuses+  -- * Reviewable Profunctors+  , Reviewable(..)+  ) where++import Control.Monad.Reader as Reader+import Control.Monad.State as State+import Control.Lens.Getter+import Control.Lens.Internal.Review+import Control.Lens.Internal.Setter+import Control.Lens.Type+import Data.Functor.Identity+import Data.Profunctor+import Data.Profunctor.Unsafe++-- $setup+-- >>> import Control.Lens+-- >>> let isLeft  (Left  _) = True; isLeft  _ = False+-- >>> let isRight (Right _) = True; isRight _ = False++------------------------------------------------------------------------------+-- Review+------------------------------------------------------------------------------++-- | This is a limited form of a 'Prism' that can only be used for 're' operations.+--+-- Like with a 'Getter', there are no laws to state for a 'Review'.+--+-- You can generate a 'Review' by using 'unto'. You can also use any 'Prism' or 'Iso'+-- directly as a 'Review'.+type Review s t a b = forall p f. (Reviewable p, Settable f) => Overloaded p f s t a b++-- | A 'Simple' 'Review'+type Review' t b = Review t t b b++-- | If you see this in a signature for a function, the function is expecting a 'Review'+-- (in practice, this usually means a 'Prism').+type AReview s t a b = Overloaded Reviewed Identity s t a b++-- | A 'Simple' 'AReview'+type AReview' t b = AReview t t b b++-- | An analogue of 'to' for 'review'.+--+-- @+-- 'unto' :: (b -> t) -> 'Review'' t b+-- @+unto :: (Reviewable p, Functor f) => (b -> t) -> Overloaded p f s t a b+unto f = retagged . rmap (fmap f)++-- | Turn a 'Prism' or 'Control.Lens.Iso.Iso' around to build a 'Getter'.+--+-- If you have an 'Control.Lens.Iso.Iso', 'Control.Lens.Iso.from' is a more powerful version of this function+-- that will return an 'Control.Lens.Iso.Iso' instead of a mere 'Getter'.+--+-- >>> 5 ^.re _Left+-- Left 5+--+-- @+-- 'review'  ≡ 'view'  '.' 're'+-- 'reviews' ≡ 'views' '.' 're'+-- 'reuse'   ≡ 'use'   '.' 're'+-- 'reuses'  ≡ 'uses'  '.' 're'+-- @+--+-- @+-- 're' :: 'Prism' s t a b -> 'Getter' b t+-- 're' :: 'Iso' s t a b   -> 'Getter' b t+-- @+re :: AReview s t a b -> Getter b t+re p = to (runIdentity #. runReviewed #. p .# Reviewed .# Identity)+{-# INLINE re #-}++-- | This can be used to turn an 'Control.Lens.Iso.Iso' or 'Prism' around and 'view' a value (or the current environment) through it the other way.+--+-- @+-- 'review' ≡ 'view' '.' 're'+-- @+--+-- >>> review _Left "mustard"+-- Left "mustard"+--+-- Usually 'review' is used in the @(->)@ 'Monad' with a 'Prism' or 'Control.Lens.Iso.Iso', in which case it may be useful to think of+-- it as having one of these more restricted type signatures:+--+-- @+-- 'review' :: 'Iso'' s a   -> a -> s+-- 'review' :: 'Prism'' s a -> a -> s+-- @+--+-- However, when working with a 'Monad' transformer stack, it is sometimes useful to be able to 'review' the current environment, in which case one of+-- these more slightly more liberal type signatures may be beneficial to think of it as having:+--+-- @+-- 'review' :: 'MonadReader' a m => 'Iso'' s a   -> m s+-- 'review' :: 'MonadReader' a m => 'Prism'' s a -> m s+-- @+review :: MonadReader b m => AReview s t a b -> m t+review p = asks (runIdentity #. runReviewed #. p .# Reviewed .# Identity)+{-# INLINE review #-}++-- | This can be used to turn an 'Control.Lens.Iso.Iso' or 'Prism' around and 'view' a value (or the current environment) through it the other way,+-- applying a function.+--+-- @+-- 'reviews' ≡ 'views' '.' 're'+-- @+--+-- >>> reviews _Left isRight "mustard"+-- False+--+-- Usually this function is used in the @(->)@ 'Monad' with a 'Prism' or 'Control.Lens.Iso.Iso', in which case it may be useful to think of+-- it as having one of these more restricted type signatures:+--+-- @+-- 'reviews' :: 'Iso'' s a   -> (s -> r) -> a -> r+-- 'reviews' :: 'Prism'' s a -> (s -> r) -> a -> r+-- @+--+-- However, when working with a 'Monad' transformer stack, it is sometimes useful to be able to 'review' the current environment, in which case one of+-- these more slightly more liberal type signatures may be beneficial to think of it as having:+--+-- @+-- 'reviews' :: 'MonadReader' a m => 'Iso'' s a   -> (s -> r) -> m r+-- 'reviews' :: 'MonadReader' a m => 'Prism'' s a -> (s -> r) -> m r+-- @+reviews :: MonadReader b m => AReview s t a b -> (t -> r) -> m r+reviews p tr = asks (tr . runIdentity #. runReviewed #. p .# Reviewed .# Identity)+{-# INLINE reviews #-}++-- | This can be used to turn an 'Control.Lens.Iso.Iso' or 'Prism' around and 'use' a value (or the current environment) through it the other way.+--+-- @'reuse' ≡ 'use' '.' 're'@+--+-- >>> evalState (reuse _Left) 5+-- Left 5+--+-- @+-- 'reuse' :: 'MonadState' a m => 'Prism'' s a -> m s+-- 'reuse' :: 'MonadState' a m => 'Iso'' s a   -> m s+-- @+reuse :: MonadState b m => AReview s t a b -> m t+reuse p = gets (runIdentity #. runReviewed #. p .# Reviewed .# Identity)+{-# INLINE reuse #-}++-- | This can be used to turn an 'Control.Lens.Iso.Iso' or 'Prism' around and 'use' the current state through it the other way,+-- applying a function.+--+-- @'reuses' ≡ 'uses' '.' 're'@+--+-- >>> evalState (reuses _Left isLeft) (5 :: Int)+-- True+--+-- @+-- 'reuses' :: 'MonadState' a m => 'Prism'' s a -> (s -> r) -> m r+-- 'reuses' :: 'MonadState' a m => 'Iso'' s a   -> (s -> r) -> m r+-- @+reuses :: MonadState b m => AReview s t a b -> (t -> r) -> m r+reuses p tr = gets (tr . runIdentity #. runReviewed #. p .# Reviewed .# Identity)+{-# INLINE reuses #-}
src/Control/Lens/Setter.hs view
@@ -1,10 +1,15 @@-{-# LANGUAGE MagicHash #-}+{-# LANGUAGE CPP #-} {-# LANGUAGE Rank2Types #-}-{-# LANGUAGE LiberalTypeSynonyms #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE FlexibleContexts #-}+#ifdef TRUSTWORTHY+{-# LANGUAGE Trustworthy #-}+#endif ----------------------------------------------------------------------------- -- | -- Module      :  Control.Lens.Setter--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  provisional@@ -12,12 +17,14 @@ -- -- A @'Setter' s t a b@ is a generalization of 'fmap' from 'Functor'. It allows you to map into a -- structure and change out the contents, but it isn't strong enough to allow you to--- enumerate those contents. Starting with @fmap :: 'Functor' f => (a -> b) -> f a -> f b@--- we monomorphize the type to obtain @(a -> b) -> s -> t@ and then decorate it with 'Data.Functor.Identity.Identity' to obtain+-- enumerate those contents. Starting with @'fmap' :: 'Functor' f => (a -> b) -> f a -> f b@+-- we monomorphize the type to obtain @(a -> b) -> s -> t@ and then decorate it with 'Data.Functor.Identity.Identity' to obtain: ----- @type 'Setter' s t a b = (a -> 'Data.Functor.Identity.Identity' b) -> s -> 'Data.Functor.Identity.Identity' t@+-- @+-- type 'Setter' s t a b = (a -> 'Data.Functor.Identity.Identity' b) -> s -> 'Data.Functor.Identity.Identity' t+-- @ ----- Every 'Control.Lens.Traversal.Traversal' is a valid 'Setter', since 'Data.Functor.Identity.Identity' is 'Applicative'.+-- Every 'Traversal' is a valid 'Setter', since 'Data.Functor.Identity.Identity' is 'Applicative'. -- -- Everything you can do with a 'Functor', you can do with a 'Setter'. There -- are combinators that generalize 'fmap' and ('<$').@@ -25,15 +32,22 @@ module Control.Lens.Setter   (   -- * Setters-    Setter+    Setter, Setter'+  , IndexedSetter, IndexedSetter'+  , ASetter, ASetter'+  , AnIndexedSetter, AnIndexedSetter'+  , Setting, Setting'   -- * Building Setters-  , sets+  , sets, setting+  , cloneSetter+  , cloneIndexPreservingSetter+  , cloneIndexedSetter   -- * Common Setters-  , mapped-  , lifted+  , mapped, lifted+  , contramapped+  , argument   -- * Functional Combinators   , over-  , mapOf   , set   , (.~), (%~)   , (+~), (-~), (*~), (//~), (^~), (^^~), (**~), (||~), (<>~), (&&~), (<.~), (?~), (<?~)@@ -42,31 +56,43 @@   , (.=), (%=)   , (+=), (-=), (*=), (//=), (^=), (^^=), (**=), (||=), (<>=), (&&=), (<.=), (?=), (<?=)   , (<~)+  -- * Writer Combinators+  , scribe+  , passing, ipassing+  , censoring, icensoring   -- * Simplified State Setting   , set'-  -- * Storing Setters-  , ReifiedSetter(..)-  -- * Setter Internals-  , Setting-  , SimpleSetting-  -- * Simplicity-  , SimpleSetter-  , SimpleReifiedSetter+  -- * Indexed Setters+  , imapOf, iover+  , isets+  , (%@~), (%@=)   -- * Exported for legible error messages   , Settable   , Mutator+  -- * Deprecated+  , mapOf   ) where -import Control.Lens.Classes-import Control.Lens.Internal-import Control.Lens.Internal.Combinators+import Control.Applicative+import Control.Comonad+import Control.Lens.Internal.Indexed+import Control.Lens.Internal.Setter+import Control.Lens.Type import Control.Monad (liftM) import Control.Monad.State.Class as State+import Control.Monad.Writer.Class as Writer+import Data.Functor.Contravariant import Data.Monoid+import Data.Profunctor+import Data.Profunctor.Rep+import Data.Profunctor.Unsafe +{-# ANN module "HLint: ignore Avoid lambda" #-}+ -- $setup -- >>> import Control.Lens -- >>> import Control.Monad.State+-- >>> import Data.Char -- >>> import Data.Map as Map -- >>> import Debug.SimpleReflect.Expr as Expr -- >>> import Debug.SimpleReflect.Vars as Vars@@ -76,92 +102,59 @@ -- >>> let getter :: Expr -> Expr; getter = fun "getter" -- >>> let setter :: Expr -> Expr -> Expr; setter = fun "setter" --- This would be nice to have for the Monoid examples, but adding data types or--- instances causes doctest on Travis-CI to flip out.------ >>> instance Monoid Expr where mappend = Expr.op InfixR 6 "<>"; mempty = var "mempty"--infixr 4 .~, +~, *~, -~, //~, ^~, ^^~, **~, &&~, <>~, ||~, %~, <.~, ?~, <?~-infix  4 .=, +=, *=, -=, //=, ^=, ^^=, **=, &&=, <>=, ||=, %=, <.=, ?=, <?=+infixr 4 %@~, .~, +~, *~, -~, //~, ^~, ^^~, **~, &&~, <>~, ||~, %~, <.~, ?~, <?~+infix  4 %@=, .=, +=, *=, -=, //=, ^=, ^^=, **=, &&=, <>=, ||=, %=, <.=, ?=, <?= infixr 2 <~  ------------------------------------------------------------------------------ -- Setters ------------------------------------------------------------------------------ --- |--- The only 'Control.Lens.Type.Lens'-like law that can apply to a 'Setter' @l@ is that------ @'set' l y ('set' l x a) ≡ 'set' l y a@------ You can't 'view' a 'Setter' in general, so the other two laws are irrelevant.+-- | Running a 'Setter' instantiates it to a concrete type. ----- However, two 'Functor' laws apply to a 'Setter':+-- When consuming a setter directly to perform a mapping, you can use this type, but most+-- user code will not need to use this type. ----- @--- 'over' l 'id' ≡ 'id'--- 'over' l f '.' 'over' l g ≡ 'over' l (f '.' g)--- @+-- By choosing 'Mutator' rather than 'Data.Functor.Identity.Identity', we get nicer error messages.+type ASetter s t a b = (a -> Mutator b) -> s -> Mutator t++-- | This is a useful alias for use when consuming a 'Setter''. ----- These an be stated more directly:+-- Most user code will never have to use this type. -- -- @--- l 'pure' ≡ 'pure'--- l f . 'untainted' . l g ≡ l (f . 'untainted' . g)+-- type 'ASetter'' = 'Simple' 'ASetter' -- @------ You can compose a 'Setter' with a 'Control.Lens.Type.Lens' or a 'Control.Lens.Traversal.Traversal' using ('.') from the Prelude--- and the result is always only a 'Setter' and nothing more.------ >>> over traverse f [a,b,c,d]--- [f a,f b,f c,f d]------ >>> over _1 f (a,b)--- (f a,b)------ >>> over (traverse._1) f [(a,b),(c,d)]--- [(f a,b),(f c,d)]------ >>> over both f (a,b)--- (f a,f b)------ >>> over (traverse.both) f [(a,b),(c,d)]--- [(f a,f b),(f c,f d)]-type Setter s t a b = forall f. Settable f => (a -> f b) -> s -> f t+type ASetter' s a = ASetter s s a a --- |--- Running a 'Setter' instantiates it to a concrete type.+-- | Running an 'IndexedSetter' instantiates it to a concrete type. -- -- When consuming a setter directly to perform a mapping, you can use this type, but most -- user code will not need to use this type. -- -- By choosing 'Mutator' rather than 'Data.Functor.Identity.Identity', we get nicer error messages.-type Setting s t a b = (a -> Mutator b) -> s -> Mutator t+type AnIndexedSetter i s t a b = Indexed i a (Mutator b) -> s -> Mutator t --- |------ A Simple Setter is just a 'Setter' that doesn't change the types.------ These are particularly common when talking about monomorphic containers. /e.g./------ @'sets' Data.Text.map :: 'SimpleSetter' 'Data.Text.Internal.Text' 'Char'@------ @type 'SimpleSetter' = 'Control.Lens.Type.Simple' 'Setter'@-type SimpleSetter s a = Setter s s a a+-- | @+-- type 'AnIndexedSetter'' i = 'Simple' ('AnIndexedSetter' i)+-- @+type AnIndexedSetter' i s a = AnIndexedSetter i s s a a --- |--- This is a useful alias for use when consuming a 'SimpleSetter'.------ Most user code will never have to use this type.------ @type 'SimpleSetting' m = 'Control.Lens.Type.Simple' 'Setting'@-type SimpleSetting s a = Setting s s a a+-- | This is a convenient alias when defining highly polymorphic code that takes both+-- 'ASetter' and 'AnIndexedSetter' as appropriate. If a function takes this it is+-- expecting one of those two things based on context.+type Setting p s t a b = p a (Mutator b) -> s -> Mutator t +-- | This is a convenient alias when defining highly polymorphic code that takes both+-- 'ASetter'' and 'AnIndexedSetter'' as appropriate. If a function takes this it is+-- expecting one of those two things based on context.+type Setting' p s a = Setting p s s a a+ ----------------------------------------------------------------------------- -- Setters ----------------------------------------------------------------------------- --- | This setter can be used to map over all of the values in a 'Functor'.+-- | This 'Setter' can be used to map over all of the values in a 'Functor'. -- -- @ -- 'fmap' ≡ 'over' 'mapped'@@ -183,13 +176,19 @@ -- -- >>> over (mapped._2) length [("hello","world"),("leaders","!!!")] -- [("hello",5),("leaders",3)]+--+-- @+-- 'mapped' :: 'Functor' f => 'Setter' (f a) (f b) a b+-- @+--+-- If you want an 'IndexPreservingSetter' use @'setting' 'fmap'@. mapped :: Functor f => Setter (f a) (f b) a b mapped = sets fmap {-# INLINE mapped #-} --- | This setter can be used to modify all of the values in a 'Monad'.+-- | This 'setter' can be used to modify all of the values in a 'Monad'. ----- You sometimes have to use this, rather than 'mapped', because due to+-- You sometimes have to use this rather than 'mapped' -- due to -- temporary insanity 'Functor' is not a superclass of 'Monad'. -- -- @@@ -201,12 +200,59 @@ -- -- >>> set lifted b (Just a) -- Just b+--+-- If you want an 'IndexPreservingSetter' use @'setting' 'liftM'@. lifted :: Monad m => Setter (m a) (m b) a b lifted = sets liftM {-# INLINE lifted #-} --- | Build a Setter from a map-like function.+-- | This 'Setter' can be used to map over all of the inputs to a 'Contravariant'. --+-- @+-- 'contramap' ≡ 'over' 'contramapped'+-- @+--+-- >>> getPredicate (over contramapped (*2) (Predicate even)) 5+-- True+--+-- >>> getOp (over contramapped (*5) (Op show)) 100+-- "500"+--+-- >>> Prelude.map ($ 1) $ over (mapped . wrapping Op . contramapped) (*12) [(*2),(+1),(^3)]+-- [24,13,1728]+--+contramapped :: Contravariant f => Setter (f b) (f a) a b+contramapped = sets contramap+{-# INLINE contramapped #-}++-- | This 'Setter' can be used to map over the input of a 'Profunctor'.+--+-- The most common 'Profunctor' to use this with is @(->)@.+--+-- >>> (argument %~ f) g x+-- g (f x)+--+-- >>> (argument %~ show) length [1,2,3]+-- 7+--+-- >>> (argument %~ f) h x y+-- h (f x) y+--+-- Map over the argument of the result of a function -- i.e., its second+-- argument:+--+-- >>> (mapped.argument %~ f) h x y+-- h x (f y)+--+-- @+-- 'argument' :: 'Setter' (b -> r) (a -> r) a b+-- @+argument :: Profunctor p => Setter (p b r) (p a r) a b+argument = sets lmap+{-# INLINE argument #-}++-- | Build an index-preserving 'Setter' from a map-like function.+-- -- Your supplied function @f@ is required to satisfy: -- -- @@@ -217,21 +263,50 @@ -- Equational reasoning: -- -- @--- 'sets' '.' 'over' ≡ 'id'--- 'over' '.' 'sets' ≡ 'id'+-- 'setting' '.' 'over' ≡ 'id'+-- 'over' '.' 'setting' ≡ 'id' -- @ -- -- Another way to view 'sets' is that it takes a \"semantic editor combinator\" -- and transforms it into a 'Setter'.-sets :: ((a -> b) -> s -> t) -> Setter s t a b-sets f g = tainted# (f (untainted# g))+--+-- @+-- 'setting' :: ((a -> b) -> s -> t) -> 'Setter' s t a b+-- @+setting :: ((a -> b) -> s -> t) -> IndexPreservingSetter s t a b+setting l pafb = cotabulate $ \ws -> pure $ l (\a -> untainted (corep pafb (a <$ ws))) (extract ws)+{-# INLINE setting #-}++-- | Build a 'Setter', 'IndexedSetter' or 'IndexPreservingSetter' depending on your choice of 'Profunctor'.+--+-- @+-- 'sets' :: ((a -> b) -> s -> t) -> 'Setter' s t a b+-- @+sets :: (Profunctor p, Profunctor q, Settable f) => (p a b -> q s t) -> Overloading p q f s t a b+sets f g = taintedDot (f (untaintedDot g)) {-# INLINE sets #-} +-- | Restore 'ASetter' to a full 'Setter'.+cloneSetter :: ASetter s t a b -> Setter s t a b+cloneSetter l afb = taintedDot $ runMutator #. l (Mutator #. untaintedDot afb)+{-# INLINE cloneSetter #-}++-- | Build an 'IndexPreservingSetter' from any 'Setter'.+cloneIndexPreservingSetter :: ASetter s t a b -> IndexPreservingSetter s t a b+cloneIndexPreservingSetter l pafb = cotabulate $ \ws ->+    taintedDot runMutator $ l (\a -> Mutator (untainted (corep pafb (a <$ ws)))) (extract ws)+{-# INLINE cloneIndexPreservingSetter #-}++-- | Clone an 'IndexedSetter'.+cloneIndexedSetter :: AnIndexedSetter i s t a b -> IndexedSetter i s t a b+cloneIndexedSetter l pafb = taintedDot (runMutator #. l (Indexed $ \i -> Mutator #. untaintedDot (indexed pafb i)))+{-# INLINE cloneIndexedSetter #-}+ ----------------------------------------------------------------------------- -- Using Setters ----------------------------------------------------------------------------- --- | Modify the target of a 'Control.Lens.Type.Lens' or all the targets of a 'Setter' or 'Control.Lens.Traversal.Traversal'+-- | Modify the target of a 'Lens' or all the targets of a 'Setter' or 'Traversal' -- with a function. -- -- @@@ -243,7 +318,9 @@ -- -- Given any valid 'Setter' @l@, you can also rely on the law: ----- @'over' l f . 'over' l g = 'over' l (f . g)@+-- @+-- 'over' l f '.' 'over' l g = 'over' l (f '.' g)+-- @ -- -- /e.g./ --@@ -265,21 +342,20 @@ -- >>> over _1 show (10,20) -- ("10",20) ----- @'over' :: 'Setter' s t a b -> (a -> b) -> s -> t@-over :: Setting s t a b -> (a -> b) -> s -> t-over l f = runMutator# (l (mutator# f))+-- @+-- 'over' :: 'Setter' s t a b -> (a -> b) -> s -> t+-- 'over' :: 'ASetter' s t a b -> (a -> b) -> s -> t+-- @+over :: Profunctor p => Setting p s t a b -> p a b -> s -> t+over l f = runMutator #. l (Mutator #. f) {-# INLINE over #-} --- | 'mapOf' is a deprecated alias for 'over'.-mapOf :: Setting s t a b -> (a -> b) -> s -> t-mapOf = over-{-# INLINE mapOf #-}-{-# DEPRECATED mapOf "Use `over`" #-}---- | Replace the target of a 'Control.Lens.Type.Lens' or all of the targets of a 'Setter'--- or 'Control.Lens.Traversal.Traversal' with a constant value.+-- | Replace the target of a 'Lens' or all of the targets of a 'Setter'+-- or 'Traversal' with a constant value. ----- @('<$') ≡ 'set' 'mapped'@+-- @+-- ('<$') ≡ 'set' 'mapped'+-- @ -- -- >>> set _2 "hello" (1,()) -- (1,"hello")@@ -292,17 +368,16 @@ -- -- @ -- 'set' :: 'Setter' s t a b    -> b -> s -> t--- 'set' :: 'Control.Lens.Iso.Iso' s t a b       -> b -> s -> t--- 'set' :: 'Control.Lens.Type.Lens' s t a b      -> b -> s -> t--- 'set' :: 'Control.Lens.Traversal.Traversal' s t a b -> b -> s -> t+-- 'set' :: 'Iso' s t a b       -> b -> s -> t+-- 'set' :: 'Lens' s t a b      -> b -> s -> t+-- 'set' :: 'Traversal' s t a b -> b -> s -> t -- @-set :: Setting s t a b -> b -> s -> t-set l b = runMutator# (l (\_ -> Mutator b))+set :: ASetter s t a b -> b -> s -> t+set l b = runMutator #. l (\_ -> Mutator b) {-# INLINE set #-} --- |--- Replace the target of a 'Control.Lens.Type.Lens' or all of the targets of a 'Control.Lens.Type.Simple' 'Setter'--- or 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' with a constant value, without changing its type.+-- | Replace the target of a 'Lens' or all of the targets of a 'Setter''+-- or 'Traversal' with a constant value, without changing its type. -- -- This is a type restricted version of 'set', which retains the type of the original. --@@ -319,23 +394,23 @@ -- relatively nice error message. -- -- @--- 'set'' :: 'Control.Lens.Type.Simple' 'Setter' s a    -> a -> s -> s--- 'set'' :: 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a       -> a -> s -> s--- 'set'' :: 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a      -> a -> s -> s--- 'set'' :: 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a -> a -> s -> s+-- 'set'' :: 'Setter'' s a    -> a -> s -> s+-- 'set'' :: 'Iso'' s a       -> a -> s -> s+-- 'set'' :: 'Lens'' s a      -> a -> s -> s+-- 'set'' :: 'Traversal'' s a -> a -> s -> s -- @-set' :: Setting s s a a -> a -> s -> s-set' l b = runMutator# (l (\_ -> Mutator b))+set' :: ASetter' s a -> a -> s -> s+set' l b = runMutator #. l (\_ -> Mutator b) {-# INLINE set' #-} --- | Modifies the target of a 'Control.Lens.Type.Lens' or all of the targets of a 'Setter' or--- 'Control.Lens.Traversal.Traversal' with a user supplied function.+-- | Modifies the target of a 'Lens' or all of the targets of a 'Setter' or+-- 'Traversal' with a user supplied function. ----- This is an infix version of 'over'+-- This is an infix version of 'over'. -- -- @ -- 'fmap' f ≡ 'mapped' '%~' f--- 'Data.Traversable.fmapDefault' f ≡ 'traverse' '%~' f+-- 'Data.Traversable.fmapDefault' f ≡ 'Data.Traversable.traverse' '%~' f -- @ -- -- >>> (a,b,c) & _3 %~ f@@ -358,20 +433,22 @@ -- -- @ -- ('%~') :: 'Setter' s t a b    -> (a -> b) -> s -> t--- ('%~') :: 'Control.Lens.Iso.Iso' s t a b       -> (a -> b) -> s -> t--- ('%~') :: 'Control.Lens.Type.Lens' s t a b      -> (a -> b) -> s -> t--- ('%~') :: 'Control.Lens.Traversal.Traversal' s t a b -> (a -> b) -> s -> t+-- ('%~') :: 'Iso' s t a b       -> (a -> b) -> s -> t+-- ('%~') :: 'Lens' s t a b      -> (a -> b) -> s -> t+-- ('%~') :: 'Traversal' s t a b -> (a -> b) -> s -> t -- @-(%~) :: Setting s t a b -> (a -> b) -> s -> t+(%~) :: Profunctor p => Setting p s t a b -> p a b -> s -> t (%~) = over {-# INLINE (%~) #-} --- | Replace the target of a 'Control.Lens.Type.Lens' or all of the targets of a 'Setter'--- or 'Control.Lens.Traversal.Traversal' with a constant value.+-- | Replace the target of a 'Lens' or all of the targets of a 'Setter'+-- or 'Traversal' with a constant value. ----- This is an infix version of 'set', provided for consistency with ('.=')+-- This is an infix version of 'set', provided for consistency with ('.='). ----- @f '<$' a ≡ 'mapped' '.~' f '$' a@+-- @+-- f '<$' a ≡ 'mapped' '.~' f '$' a+-- @ -- -- >>> (a,b,c,d) & _4 .~ e -- (a,b,c,e)@@ -384,17 +461,19 @@ -- -- @ -- ('.~') :: 'Setter' s t a b    -> b -> s -> t--- ('.~') :: 'Control.Lens.Iso.Iso' s t a b       -> b -> s -> t--- ('.~') :: 'Control.Lens.Type.Lens' s t a b      -> b -> s -> t--- ('.~') :: 'Control.Lens.Traversal.Traversal' s t a b -> b -> s -> t+-- ('.~') :: 'Iso' s t a b       -> b -> s -> t+-- ('.~') :: 'Lens' s t a b      -> b -> s -> t+-- ('.~') :: 'Traversal' s t a b -> b -> s -> t -- @-(.~) :: Setting s t a b -> b -> s -> t+(.~) :: ASetter s t a b -> b -> s -> t (.~) = set {-# INLINE (.~) #-} --- | Set the target of a 'Control.Lens.Type.Lens', 'Control.Lens.Traversal.Traversal' or 'Setter' to 'Just' a value.+-- | Set the target of a 'Lens', 'Traversal' or 'Setter' to 'Just' a value. ----- @l '?~' t ≡ 'set' l ('Just' t)@+-- @+-- l '?~' t ≡ 'set' l ('Just' t)+-- @ -- -- >>> Nothing & id ?~ a -- Just a@@ -404,17 +483,17 @@ -- -- @ -- ('?~') :: 'Setter' s t a ('Maybe' b)    -> b -> s -> t--- ('?~') :: 'Control.Lens.Iso.Iso' s t a ('Maybe' b)       -> b -> s -> t--- ('?~') :: 'Control.Lens.Type.Lens' s t a ('Maybe' b)      -> b -> s -> t--- ('?~') :: 'Control.Lens.Traversal.Traversal' s t a ('Maybe' b) -> b -> s -> t+-- ('?~') :: 'Iso' s t a ('Maybe' b)       -> b -> s -> t+-- ('?~') :: 'Lens' s t a ('Maybe' b)      -> b -> s -> t+-- ('?~') :: 'Traversal' s t a ('Maybe' b) -> b -> s -> t -- @-(?~) :: Setting s t a (Maybe b) -> b -> s -> t+(?~) :: ASetter s t a (Maybe b) -> b -> s -> t l ?~ b = set l (Just b) {-# INLINE (?~) #-} --- | Set with pass-through+-- | Set with pass-through. ----- This is mostly present for consistency, but may be useful for for chaining assignments+-- This is mostly present for consistency, but may be useful for for chaining assignments. -- -- If you do not need a copy of the intermediate result, then using @l '.~' t@ directly is a good idea. --@@ -429,17 +508,17 @@ -- -- @ -- ('<.~') :: 'Setter' s t a b    -> b -> s -> (b, t)--- ('<.~') :: 'Control.Lens.Iso.Iso' s t a b       -> b -> s -> (b, t)--- ('<.~') :: 'Control.Lens.Type.Lens' s t a b      -> b -> s -> (b, t)--- ('<.~') :: 'Control.Lens.Traversal.Traversal' s t a b -> b -> s -> (b, t)+-- ('<.~') :: 'Iso' s t a b       -> b -> s -> (b, t)+-- ('<.~') :: 'Lens' s t a b      -> b -> s -> (b, t)+-- ('<.~') :: 'Traversal' s t a b -> b -> s -> (b, t) -- @-(<.~) :: Setting s t a b -> b -> s -> (b, t)+(<.~) :: ASetter s t a b -> b -> s -> (b, t) l <.~ b = \s -> (b, set l b s) {-# INLINE (<.~) #-} --- | Set to 'Just' a value with pass-through+-- | Set to 'Just' a value with pass-through. ----- This is mostly present for consistency, but may be useful for for chaining assignments+-- This is mostly present for consistency, but may be useful for for chaining assignments. -- -- If you do not need a copy of the intermediate result, then using @l '?~' d@ directly is a good idea. --@@ -448,16 +527,16 @@ -- ("world",(42,fromList [("goodnight","gracie"),("hello","world")])) -- -- @--- ('<?~') :: 'Setter' s t a b    -> ('Maybe' b) -> s -> (b, t)--- ('<?~') :: 'Control.Lens.Iso.Iso' s t a ('Maybe' b)       -> b -> s -> (b, t)--- ('<?~') :: 'Control.Lens.Type.Lens' s t a ('Maybe' b)      -> b -> s -> (b, t)--- ('<?~') :: 'Control.Lens.Traversal.Traversal' s t a ('Maybe' b) -> b -> s -> (b, t)+-- ('<?~') :: 'Setter' s t a ('Maybe' b)    -> b -> s -> (b, t)+-- ('<?~') :: 'Iso' s t a ('Maybe' b)       -> b -> s -> (b, t)+-- ('<?~') :: 'Lens' s t a ('Maybe' b)      -> b -> s -> (b, t)+-- ('<?~') :: 'Traversal' s t a ('Maybe' b) -> b -> s -> (b, t) -- @-(<?~) :: Setting s t a (Maybe b) -> b -> s -> (b, t)+(<?~) :: ASetter s t a (Maybe b) -> b -> s -> (b, t) l <?~ b = \s -> (b, set l (Just b) s) {-# INLINE (<?~) #-} --- | Increment the target(s) of a numerically valued 'Control.Lens.Type.Lens', 'Setter' or 'Control.Lens.Traversal.Traversal'+-- | Increment the target(s) of a numerically valued 'Lens', 'Setter' or 'Traversal'. -- -- >>> (a,b) & _1 +~ c -- (a + c,b)@@ -472,16 +551,16 @@ -- [(a + e,b + e),(c + e,d + e)] -- -- @--- ('+~') :: Num a => 'Control.Lens.Type.Simple' 'Setter' s a -> a -> s -> s--- ('+~') :: Num a => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a -> a -> s -> s--- ('+~') :: Num a => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a -> a -> s -> s--- ('+~') :: Num a => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a -> a -> s -> s+-- ('+~') :: 'Num' a => 'Setter'' s a    -> a -> s -> s+-- ('+~') :: 'Num' a => 'Iso'' s a       -> a -> s -> s+-- ('+~') :: 'Num' a => 'Lens'' s a      -> a -> s -> s+-- ('+~') :: 'Num' a => 'Traversal'' s a -> a -> s -> s -- @-(+~) :: Num a => Setting s t a a -> a -> s -> t+(+~) :: Num a => ASetter s t a a -> a -> s -> t l +~ n = over l (+ n) {-# INLINE (+~) #-} --- | Multiply the target(s) of a numerically valued 'Control.Lens.Type.Lens', 'Control.Lens.Iso.Iso', 'Setter' or 'Control.Lens.Traversal.Traversal'+-- | Multiply the target(s) of a numerically valued 'Lens', 'Iso', 'Setter' or 'Traversal'. -- -- >>> (a,b) & _1 *~ c -- (a * c,b)@@ -496,16 +575,16 @@ -- Just 48 -- -- @--- ('*~') :: 'Num' a => 'Control.Lens.Type.Simple' 'Setter' s a -> a -> s -> s--- ('*~') :: 'Num' a => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a -> a -> s -> s--- ('*~') :: 'Num' a => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a -> a -> s -> s--- ('*~') :: 'Num' a => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a -> a -> s -> s+-- ('*~') :: 'Num' a => 'Setter'' s a    -> a -> s -> s+-- ('*~') :: 'Num' a => 'Iso'' s a       -> a -> s -> s+-- ('*~') :: 'Num' a => 'Lens'' s a      -> a -> s -> s+-- ('*~') :: 'Num' a => 'Traversal'' s a -> a -> s -> s -- @-(*~) :: Num a => Setting s t a a -> a -> s -> t+(*~) :: Num a => ASetter s t a a -> a -> s -> t l *~ n = over l (* n) {-# INLINE (*~) #-} --- | Decrement the target(s) of a numerically valued 'Control.Lens.Type.Lens', 'Control.Lens.Iso.Iso', 'Setter' or 'Control.Lens.Traversal.Traversal'+-- | Decrement the target(s) of a numerically valued 'Lens', 'Iso', 'Setter' or 'Traversal'. -- -- >>> (a,b) & _1 -~ c -- (a - c,b)@@ -520,16 +599,16 @@ -- [[3,4],[5,6]] -- -- @--- ('-~') :: 'Num' a => 'Control.Lens.Type.Simple' 'Setter' s a -> a -> s -> s--- ('-~') :: 'Num' a => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a -> a -> s -> s--- ('-~') :: 'Num' a => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a -> a -> s -> s--- ('-~') :: 'Num' a => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a -> a -> s -> s+-- ('-~') :: 'Num' a => 'Setter'' s a    -> a -> s -> s+-- ('-~') :: 'Num' a => 'Iso'' s a       -> a -> s -> s+-- ('-~') :: 'Num' a => 'Lens'' s a      -> a -> s -> s+-- ('-~') :: 'Num' a => 'Traversal'' s a -> a -> s -> s -- @-(-~) :: Num a => Setting s t a a -> a -> s -> t+(-~) :: Num a => ASetter s t a a -> a -> s -> t l -~ n = over l (subtract n) {-# INLINE (-~) #-} --- | Divide the target(s) of a numerically valued 'Control.Lens.Type.Lens', 'Control.Lens.Iso.Iso', 'Setter' or 'Control.Lens.Traversal.Traversal'+-- | Divide the target(s) of a numerically valued 'Lens', 'Iso', 'Setter' or 'Traversal'. -- -- >>> (a,b) & _1 //~ c -- (a / c,b)@@ -541,46 +620,47 @@ -- ("Hawaii",5.0) -- -- @--- ('//~') :: 'Fractional' a => 'Control.Lens.Type.Simple' 'Setter' s a -> a -> s -> s--- ('//~') :: 'Fractional' a => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a -> a -> s -> s--- ('//~') :: 'Fractional' a => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a -> a -> s -> s--- ('//~') :: 'Fractional' a => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a -> a -> s -> s+-- ('//~') :: 'Fractional' a => 'Setter'' s a    -> a -> s -> s+-- ('//~') :: 'Fractional' a => 'Iso'' s a       -> a -> s -> s+-- ('//~') :: 'Fractional' a => 'Lens'' s a      -> a -> s -> s+-- ('//~') :: 'Fractional' a => 'Traversal'' s a -> a -> s -> s -- @-(//~) :: Fractional s => Setting a b s s -> s -> a -> b+(//~) :: Fractional a => ASetter s t a a -> a -> s -> t l //~ n = over l (/ n)+{-# INLINE (//~) #-} --- | Raise the target(s) of a numerically valued 'Control.Lens.Type.Lens', 'Setter' or 'Control.Lens.Traversal.Traversal' to a non-negative integral power+-- | Raise the target(s) of a numerically valued 'Lens', 'Setter' or 'Traversal' to a non-negative integral power. -- -- >>> (1,3) & _2 ^~ 2 -- (1,9) -- -- @--- ('^~') :: ('Num' a, 'Integral' e) => 'Control.Lens.Type.Simple' 'Setter' s a -> e -> s -> s--- ('^~') :: ('Num' a, 'Integral' e) => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a -> e -> s -> s--- ('^~') :: ('Num' a, 'Integral' e) => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a -> e -> s -> s--- ('^~') :: ('Num' a, 'Integral' e) => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a -> e -> s -> s+-- ('^~') :: ('Num' a, 'Integral' e) => 'Setter'' s a    -> e -> s -> s+-- ('^~') :: ('Num' a, 'Integral' e) => 'Iso'' s a       -> e -> s -> s+-- ('^~') :: ('Num' a, 'Integral' e) => 'Lens'' s a      -> e -> s -> s+-- ('^~') :: ('Num' a, 'Integral' e) => 'Traversal'' s a -> e -> s -> s -- @-(^~) :: (Num a, Integral e) => Setting s t a a -> e -> s -> t+(^~) :: (Num a, Integral e) => ASetter s t a a -> e -> s -> t l ^~ n = over l (^ n) {-# INLINE (^~) #-} --- | Raise the target(s) of a fractionally valued 'Control.Lens.Type.Lens', 'Setter' or 'Control.Lens.Traversal.Traversal' to an integral power+-- | Raise the target(s) of a fractionally valued 'Lens', 'Setter' or 'Traversal' to an integral power. -- -- >>> (1,2) & _2 ^^~ (-1) -- (1,0.5) -- -- @--- ('^^~') :: ('Fractional' a, 'Integral' e) => 'Control.Lens.Type.Simple' 'Setter' s a -> e -> s -> s--- ('^^~') :: ('Fractional' a, 'Integral' e) => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a -> e -> s -> s--- ('^^~') :: ('Fractional' a, 'Integral' e) => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a -> e -> s -> s--- ('^^~') :: ('Fractional' a, 'Integral' e) => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a -> e -> s -> s+-- ('^^~') :: ('Fractional' a, 'Integral' e) => 'Setter'' s a    -> e -> s -> s+-- ('^^~') :: ('Fractional' a, 'Integral' e) => 'Iso'' s a       -> e -> s -> s+-- ('^^~') :: ('Fractional' a, 'Integral' e) => 'Lens'' s a      -> e -> s -> s+-- ('^^~') :: ('Fractional' a, 'Integral' e) => 'Traversal'' s a -> e -> s -> s -- @ ---(^^~) :: (Fractional a, Integral e) => Setting s t a a -> e -> s -> t+(^^~) :: (Fractional a, Integral e) => ASetter s t a a -> e -> s -> t l ^^~ n = over l (^^ n) {-# INLINE (^^~) #-} --- | Raise the target(s) of a floating-point valued 'Control.Lens.Type.Lens', 'Setter' or 'Control.Lens.Traversal.Traversal' to an arbitrary power.+-- | Raise the target(s) of a floating-point valued 'Lens', 'Setter' or 'Traversal' to an arbitrary power. -- -- >>> (a,b) & _1 **~ c -- (a**c,b)@@ -592,16 +672,16 @@ -- (1,31.54428070019754) -- -- @--- ('**~') :: 'Floating' a => 'Control.Lens.Type.Simple' 'Setter' s a -> a -> s -> s--- ('**~') :: 'Floating' a => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a -> a -> s -> s--- ('**~') :: 'Floating' a => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a -> a -> s -> s--- ('**~') :: 'Floating' a => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a -> a -> s -> s+-- ('**~') :: 'Floating' a => 'Setter'' s a    -> a -> s -> s+-- ('**~') :: 'Floating' a => 'Iso'' s a       -> a -> s -> s+-- ('**~') :: 'Floating' a => 'Lens'' s a      -> a -> s -> s+-- ('**~') :: 'Floating' a => 'Traversal'' s a -> a -> s -> s -- @-(**~) :: Floating a => Setting s t a a -> a -> s -> t+(**~) :: Floating a => ASetter s t a a -> a -> s -> t l **~ n = over l (** n) {-# INLINE (**~) #-} --- | Logically '||' the target(s) of a 'Bool'-valued 'Control.Lens.Type.Lens' or 'Setter'+-- | Logically '||' the target(s) of a 'Bool'-valued 'Lens' or 'Setter'. -- -- >>> both ||~ True $ (False,True) -- (True,True)@@ -610,16 +690,16 @@ -- (False,True) -- -- @--- ('||~') :: 'Control.Lens.Type.Simple' 'Setter' s 'Bool' -> 'Bool' -> s -> s--- ('||~') :: 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s 'Bool' -> 'Bool' -> s -> s--- ('||~') :: 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s 'Bool' -> 'Bool' -> s -> s--- ('||~') :: 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s 'Bool' -> 'Bool' -> s -> s+-- ('||~') :: 'Setter'' s 'Bool'    -> 'Bool' -> s -> s+-- ('||~') :: 'Iso'' s 'Bool'       -> 'Bool' -> s -> s+-- ('||~') :: 'Lens'' s 'Bool'      -> 'Bool' -> s -> s+-- ('||~') :: 'Traversal'' s 'Bool' -> 'Bool' -> s -> s -- @-(||~):: Setting s t Bool Bool -> Bool -> s -> t+(||~):: ASetter s t Bool Bool -> Bool -> s -> t l ||~ n = over l (|| n) {-# INLINE (||~) #-} --- | Logically '&&' the target(s) of a 'Bool'-valued 'Control.Lens.Type.Lens' or 'Setter'+-- | Logically '&&' the target(s) of a 'Bool'-valued 'Lens' or 'Setter'. -- -- >>> both &&~ True $ (False, True) -- (False,True)@@ -628,12 +708,12 @@ -- (False,False) -- -- @--- ('&&~') :: 'Control.Lens.Type.Simple' 'Setter' s 'Bool' -> 'Bool' -> s -> s--- ('&&~') :: 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s 'Bool' -> 'Bool' -> s -> s--- ('&&~') :: 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s 'Bool' -> 'Bool' -> s -> s--- ('&&~') :: 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s 'Bool' -> 'Bool' -> s -> s+-- ('&&~') :: 'Setter'' s 'Bool'    -> 'Bool' -> s -> s+-- ('&&~') :: 'Iso'' s 'Bool'       -> 'Bool' -> s -> s+-- ('&&~') :: 'Lens'' s 'Bool'      -> 'Bool' -> s -> s+-- ('&&~') :: 'Traversal'' s 'Bool' -> 'Bool' -> s -> s -- @-(&&~) :: Setting s t Bool Bool -> Bool -> s -> t+(&&~) :: ASetter s t Bool Bool -> Bool -> s -> t l &&~ n = over l (&& n) {-# INLINE (&&~) #-} @@ -641,7 +721,7 @@ -- Using Setters with State ------------------------------------------------------------------------------ --- | Replace the target of a 'Control.Lens.Type.Lens' or all of the targets of a 'Setter' or 'Control.Lens.Traversal.Traversal' in our monadic+-- | Replace the target of a 'Lens' or all of the targets of a 'Setter' or 'Traversal' in our monadic -- state with a new value, irrespective of the old. -- -- This is an alias for ('.=').@@ -653,17 +733,18 @@ -- (c,c) -- -- @--- 'assign' :: 'MonadState' s m => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a       -> a -> m ()--- 'assign' :: 'MonadState' s m => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a      -> a -> m ()--- 'assign' :: 'MonadState' s m => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a -> a -> m ()--- 'assign' :: 'MonadState' s m => 'Control.Lens.Type.Simple' 'Setter' s a    -> a -> m ()+-- 'assign' :: 'MonadState' s m => 'Iso'' s a       -> a -> m ()+-- 'assign' :: 'MonadState' s m => 'Lens'' s a      -> a -> m ()+-- 'assign' :: 'MonadState' s m => 'Traversal'' s a -> a -> m ()+-- 'assign' :: 'MonadState' s m => 'Setter'' s a    -> a -> m () -- @-assign :: MonadState s m => Setting s s a b -> b -> m ()+assign :: MonadState s m => ASetter s s a b -> b -> m () assign l b = State.modify (set l b) {-# INLINE assign #-} --- | Replace the target of a 'Control.Lens.Type.Lens' or all of the targets of a 'Setter' or 'Control.Lens.Traversal.Traversal' in our monadic--- state with a new value, irrespective of the old.+-- | Replace the target of a 'Lens' or all of the targets of a 'Setter'+-- or 'Traversal' in our monadic state with a new value, irrespective of the+-- old. -- -- This is an infix version of 'assign'. --@@ -674,18 +755,18 @@ -- (c,c) -- -- @--- ('.=') :: 'MonadState' s m => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a       -> a -> m ()--- ('.=') :: 'MonadState' s m => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a      -> a -> m ()--- ('.=') :: 'MonadState' s m => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a -> a -> m ()--- ('.=') :: 'MonadState' s m => 'Control.Lens.Type.Simple' 'Setter' s a    -> a -> m ()+-- ('.=') :: 'MonadState' s m => 'Iso'' s a       -> a -> m ()+-- ('.=') :: 'MonadState' s m => 'Lens'' s a      -> a -> m ()+-- ('.=') :: 'MonadState' s m => 'Traversal'' s a -> a -> m ()+-- ('.=') :: 'MonadState' s m => 'Setter'' s a    -> a -> m () -- @ -- -- "It puts the state in the monad or it gets the hose again."-(.=) :: MonadState s m => Setting s s a b -> b -> m ()+(.=) :: MonadState s m => ASetter s s a b -> b -> m () l .= b = State.modify (l .~ b) {-# INLINE (.=) #-} --- | Map over the target of a 'Control.Lens.Type.Lens' or all of the targets of a 'Setter' or 'Control.Lens.Traversal.Traversal' in our monadic state.+-- | Map over the target of a 'Lens' or all of the targets of a 'Setter' or 'Traversal' in our monadic state. -- -- >>> execState (do _1 %= f;_2 %= g) (a,b) -- (f a,g b)@@ -694,16 +775,20 @@ -- (f a,f b) -- -- @--- ('%=') :: 'MonadState' s m => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a       -> (a -> a) -> m ()--- ('%=') :: 'MonadState' s m => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a      -> (a -> a) -> m ()--- ('%=') :: 'MonadState' s m => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a -> (a -> a) -> m ()--- ('%=') :: 'MonadState' s m => 'Control.Lens.Type.Simple' 'Setter' s a    -> (a -> a) -> m ()+-- ('%=') :: 'MonadState' s m => 'Iso'' s a       -> (a -> a) -> m ()+-- ('%=') :: 'MonadState' s m => 'Lens'' s a      -> (a -> a) -> m ()+-- ('%=') :: 'MonadState' s m => 'Traversal'' s a -> (a -> a) -> m ()+-- ('%=') :: 'MonadState' s m => 'Setter'' s a    -> (a -> a) -> m () -- @-(%=) :: MonadState s m => Setting s s a b -> (a -> b) -> m ()+--+-- @+-- ('%=') :: 'MonadState' s m => 'ASetter' s s a b -> (a -> b) -> m ()+-- @+(%=) :: (Profunctor p, MonadState s m) => Setting p s s a b -> p a b -> m () l %= f = State.modify (l %~ f) {-# INLINE (%=) #-} --- | Replace the target of a 'Control.Lens.Type.Lens' or all of the targets of a 'Setter' or 'Control.Lens.Traversal.Traversal' in our monadic+-- | Replace the target of a 'Lens' or all of the targets of a 'Setter' or 'Traversal' in our monadic -- state with 'Just' a new value, irrespective of the old. -- -- >>> execState (do at 1 ?= a; at 2 ?= b) Map.empty@@ -713,24 +798,24 @@ -- (Just b,Just c) -- -- @--- ('?=') :: 'MonadState' s m => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s ('Maybe' a)       -> a -> m ()--- ('?=') :: 'MonadState' s m => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s ('Maybe' a)      -> a -> m ()--- ('?=') :: 'MonadState' s m => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s ('Maybe' a) -> a -> m ()--- ('?=') :: 'MonadState' s m => 'Control.Lens.Type.Simple' 'Setter' s ('Maybe' a)    -> a -> m ()+-- ('?=') :: 'MonadState' s m => 'Iso'' s ('Maybe' a)       -> a -> m ()+-- ('?=') :: 'MonadState' s m => 'Lens'' s ('Maybe' a)      -> a -> m ()+-- ('?=') :: 'MonadState' s m => 'Traversal'' s ('Maybe' a) -> a -> m ()+-- ('?=') :: 'MonadState' s m => 'Setter'' s ('Maybe' a)    -> a -> m () -- @-(?=) :: MonadState s m => Setting s s a (Maybe b) -> b -> m ()+(?=) :: MonadState s m => ASetter s s a (Maybe b) -> b -> m () l ?= b = State.modify (l ?~ b) {-# INLINE (?=) #-} --- | Modify the target(s) of a 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens', 'Control.Lens.Iso.Iso', 'Setter' or 'Control.Lens.Traversal.Traversal' by adding a value+-- | Modify the target(s) of a 'Lens'', 'Iso', 'Setter' or 'Traversal' by adding a value. -- -- Example: -- -- @--- fresh :: MonadState Int m => m Int--- fresh = do+-- 'fresh' :: 'MonadState' 'Int' m => m 'Int'+-- 'fresh' = do --   'id' '+=' 1---   'use' 'id'+--   'Control.Lens.Getter.use' 'id' -- @ -- -- >>> execState (do _1 += c; _2 += d) (a,b)@@ -740,139 +825,139 @@ -- (fromList [(1,10),(2,100)],"hello") -- -- @--- ('+=') :: ('MonadState' s m, 'Num' a) => 'Control.Lens.Type.Simple' 'Setter' s a -> a -> m ()--- ('+=') :: ('MonadState' s m, 'Num' a) => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a -> a -> m ()--- ('+=') :: ('MonadState' s m, 'Num' a) => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a -> a -> m ()--- ('+=') :: ('MonadState' s m, 'Num' a) => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a -> a -> m ()+-- ('+=') :: ('MonadState' s m, 'Num' a) => 'Setter'' s a    -> a -> m ()+-- ('+=') :: ('MonadState' s m, 'Num' a) => 'Iso'' s a       -> a -> m ()+-- ('+=') :: ('MonadState' s m, 'Num' a) => 'Lens'' s a      -> a -> m ()+-- ('+=') :: ('MonadState' s m, 'Num' a) => 'Traversal'' s a -> a -> m () -- @-(+=) :: (MonadState s m, Num a) => SimpleSetting s a -> a -> m ()+(+=) :: (MonadState s m, Num a) => ASetter' s a -> a -> m () l += b = State.modify (l +~ b) {-# INLINE (+=) #-} --- | Modify the target(s) of a 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens', 'Control.Lens.Iso.Iso', 'Setter' or 'Control.Lens.Traversal.Traversal' by subtracting a value+-- | Modify the target(s) of a 'Lens'', 'Iso', 'Setter' or 'Traversal' by subtracting a value. -- -- >>> execState (do _1 -= c; _2 -= d) (a,b) -- (a - c,b - d) -- -- @--- ('-=') :: ('MonadState' s m, 'Num' a) => 'Control.Lens.Type.Simple' 'Setter' s a -> a -> m ()--- ('-=') :: ('MonadState' s m, 'Num' a) => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a -> a -> m ()--- ('-=') :: ('MonadState' s m, 'Num' a) => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a -> a -> m ()--- ('-=') :: ('MonadState' s m, 'Num' a) => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a -> a -> m ()+-- ('-=') :: ('MonadState' s m, 'Num' a) => 'Setter'' s a    -> a -> m ()+-- ('-=') :: ('MonadState' s m, 'Num' a) => 'Iso'' s a       -> a -> m ()+-- ('-=') :: ('MonadState' s m, 'Num' a) => 'Lens'' s a      -> a -> m ()+-- ('-=') :: ('MonadState' s m, 'Num' a) => 'Traversal'' s a -> a -> m () -- @-(-=) :: (MonadState s m, Num a) => SimpleSetting s a -> a -> m ()+(-=) :: (MonadState s m, Num a) => ASetter' s a -> a -> m () l -= b = State.modify (l -~ b) {-# INLINE (-=) #-} --- | Modify the target(s) of a 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens', 'Control.Lens.Iso.Iso', 'Setter' or 'Control.Lens.Traversal.Traversal' by multiplying by value.+-- | Modify the target(s) of a 'Lens'', 'Iso', 'Setter' or 'Traversal' by multiplying by value. -- -- >>> execState (do _1 *= c; _2 *= d) (a,b) -- (a * c,b * d) -- -- @--- ('*=') :: ('MonadState' s m, 'Num' a) => 'Control.Lens.Type.Simple' 'Setter' s a -> a -> m ()--- ('*=') :: ('MonadState' s m, 'Num' a) => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a -> a -> m ()--- ('*=') :: ('MonadState' s m, 'Num' a) => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a -> a -> m ()--- ('*=') :: ('MonadState' s m, 'Num' a) => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a -> a -> m ()+-- ('*=') :: ('MonadState' s m, 'Num' a) => 'Setter'' s a    -> a -> m ()+-- ('*=') :: ('MonadState' s m, 'Num' a) => 'Iso'' s a       -> a -> m ()+-- ('*=') :: ('MonadState' s m, 'Num' a) => 'Lens'' s a      -> a -> m ()+-- ('*=') :: ('MonadState' s m, 'Num' a) => 'Traversal'' s a -> a -> m () -- @-(*=) :: (MonadState s m, Num a) => SimpleSetting s a -> a -> m ()+(*=) :: (MonadState s m, Num a) => ASetter' s a -> a -> m () l *= b = State.modify (l *~ b) {-# INLINE (*=) #-} --- | Modify the target(s) of a 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens', 'Control.Lens.Iso.Iso', 'Setter' or 'Control.Lens.Traversal.Traversal' by dividing by a value.+-- | Modify the target(s) of a 'Lens'', 'Iso', 'Setter' or 'Traversal' by dividing by a value. -- -- >>> execState (do _1 //= c; _2 //= d) (a,b) -- (a / c,b / d) -- -- @--- ('//=') :: ('MonadState' s m, 'Fractional' a) => 'Control.Lens.Type.Simple' 'Setter' s a -> a -> m ()--- ('//=') :: ('MonadState' s m, 'Fractional' a) => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a -> a -> m ()--- ('//=') :: ('MonadState' s m, 'Fractional' a) => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a -> a -> m ()--- ('//=') :: ('MonadState' s m, 'Fractional' a) => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a -> a -> m ()+-- ('//=') :: ('MonadState' s m, 'Fractional' a) => 'Setter'' s a    -> a -> m ()+-- ('//=') :: ('MonadState' s m, 'Fractional' a) => 'Iso'' s a       -> a -> m ()+-- ('//=') :: ('MonadState' s m, 'Fractional' a) => 'Lens'' s a      -> a -> m ()+-- ('//=') :: ('MonadState' s m, 'Fractional' a) => 'Traversal'' s a -> a -> m () -- @-(//=) :: (MonadState s m, Fractional a) => SimpleSetting s a -> a -> m ()+(//=) :: (MonadState s m, Fractional a) => ASetter' s a -> a -> m () l //= a = State.modify (l //~ a) {-# INLINE (//=) #-} --- | Raise the target(s) of a numerically valued 'Control.Lens.Type.Lens', 'Setter' or 'Control.Lens.Traversal.Traversal' to a non-negative integral power.+-- | Raise the target(s) of a numerically valued 'Lens', 'Setter' or 'Traversal' to a non-negative integral power. -- -- @--- ('^=') ::  ('MonadState' s m, 'Num' a, 'Integral' e) => 'Control.Lens.Type.Simple' 'Setter' s a -> e -> m ()--- ('^=') ::  ('MonadState' s m, 'Num' a, 'Integral' e) => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a -> e -> m ()--- ('^=') ::  ('MonadState' s m, 'Num' a, 'Integral' e) => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a -> e -> m ()--- ('^=') ::  ('MonadState' s m, 'Num' a, 'Integral' e) => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a -> e -> m ()+-- ('^=') ::  ('MonadState' s m, 'Num' a, 'Integral' e) => 'Setter'' s a    -> e -> m ()+-- ('^=') ::  ('MonadState' s m, 'Num' a, 'Integral' e) => 'Iso'' s a       -> e -> m ()+-- ('^=') ::  ('MonadState' s m, 'Num' a, 'Integral' e) => 'Lens'' s a      -> e -> m ()+-- ('^=') ::  ('MonadState' s m, 'Num' a, 'Integral' e) => 'Traversal'' s a -> e -> m () -- @-(^=) :: (MonadState s m, Num a, Integral e) => SimpleSetting s a -> e -> m ()+(^=) :: (MonadState s m, Num a, Integral e) => ASetter' s a -> e -> m () l ^= e = State.modify (l ^~ e) {-# INLINE (^=) #-} --- | Raise the target(s) of a numerically valued 'Control.Lens.Type.Lens', 'Setter' or 'Control.Lens.Traversal.Traversal' to an integral power.+-- | Raise the target(s) of a numerically valued 'Lens', 'Setter' or 'Traversal' to an integral power. -- -- @--- ('^^=') ::  ('MonadState' s m, 'Fractional' a, 'Integral' e) => 'Control.Lens.Type.Simple' 'Setter' s a -> e -> m ()--- ('^^=') ::  ('MonadState' s m, 'Fractional' a, 'Integral' e) => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a -> e -> m ()--- ('^^=') ::  ('MonadState' s m, 'Fractional' a, 'Integral' e) => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a -> e -> m ()--- ('^^=') ::  ('MonadState' s m, 'Fractional' a, 'Integral' e) => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a -> e -> m ()+-- ('^^=') ::  ('MonadState' s m, 'Fractional' a, 'Integral' e) => 'Setter'' s a    -> e -> m ()+-- ('^^=') ::  ('MonadState' s m, 'Fractional' a, 'Integral' e) => 'Iso'' s a       -> e -> m ()+-- ('^^=') ::  ('MonadState' s m, 'Fractional' a, 'Integral' e) => 'Lens'' s a      -> e -> m ()+-- ('^^=') ::  ('MonadState' s m, 'Fractional' a, 'Integral' e) => 'Traversal'' s a -> e -> m () -- @-(^^=) :: (MonadState s m, Fractional a, Integral e) => SimpleSetting s a -> e -> m ()+(^^=) :: (MonadState s m, Fractional a, Integral e) => ASetter' s a -> e -> m () l ^^= e = State.modify (l ^^~ e) {-# INLINE (^^=) #-} --- | Raise the target(s) of a numerically valued 'Control.Lens.Type.Lens', 'Setter' or 'Control.Lens.Traversal.Traversal' to an arbitrary power+-- | Raise the target(s) of a numerically valued 'Lens', 'Setter' or 'Traversal' to an arbitrary power -- -- >>> execState (do _1 **= c; _2 **= d) (a,b) -- (a**c,b**d) -- -- @--- ('**=') ::  ('MonadState' s m, 'Floating' a) => 'Control.Lens.Type.Simple' 'Setter' s a -> a -> m ()--- ('**=') ::  ('MonadState' s m, 'Floating' a) => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a -> a -> m ()--- ('**=') ::  ('MonadState' s m, 'Floating' a) => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a -> a -> m ()--- ('**=') ::  ('MonadState' s m, 'Floating' a) => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a -> a -> m ()+-- ('**=') ::  ('MonadState' s m, 'Floating' a) => 'Setter'' s a    -> a -> m ()+-- ('**=') ::  ('MonadState' s m, 'Floating' a) => 'Iso'' s a       -> a -> m ()+-- ('**=') ::  ('MonadState' s m, 'Floating' a) => 'Lens'' s a      -> a -> m ()+-- ('**=') ::  ('MonadState' s m, 'Floating' a) => 'Traversal'' s a -> a -> m () -- @-(**=) :: (MonadState s m, Floating a) => SimpleSetting s a -> a -> m ()+(**=) :: (MonadState s m, Floating a) => ASetter' s a -> a -> m () l **= a = State.modify (l **~ a) {-# INLINE (**=) #-} --- | Modify the target(s) of a 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens', 'Control.Lens.Iso.Iso', 'Setter' or 'Control.Lens.Traversal.Traversal' by taking their logical '&&' with a value+-- | Modify the target(s) of a 'Lens'', 'Iso', 'Setter' or 'Traversal' by taking their logical '&&' with a value. -- -- >>> execState (do _1 &&= True; _2 &&= False; _3 &&= True; _4 &&= False) (True,True,False,False) -- (True,False,False,False) -- -- @--- ('&&=') :: 'MonadState' s m => 'Control.Lens.Type.Simple' 'Setter' s 'Bool' -> 'Bool' -> m ()--- ('&&=') :: 'MonadState' s m => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s 'Bool' -> 'Bool' -> m ()--- ('&&=') :: 'MonadState' s m => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s 'Bool' -> 'Bool' -> m ()--- ('&&=') :: 'MonadState' s m => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s 'Bool' -> 'Bool' -> m ()+-- ('&&=') :: 'MonadState' s m => 'Setter'' s 'Bool'    -> 'Bool' -> m ()+-- ('&&=') :: 'MonadState' s m => 'Iso'' s 'Bool'       -> 'Bool' -> m ()+-- ('&&=') :: 'MonadState' s m => 'Lens'' s 'Bool'      -> 'Bool' -> m ()+-- ('&&=') :: 'MonadState' s m => 'Traversal'' s 'Bool' -> 'Bool' -> m () -- @-(&&=):: MonadState s m => SimpleSetting s Bool -> Bool -> m ()+(&&=):: MonadState s m => ASetter' s Bool -> Bool -> m () l &&= b = State.modify (l &&~ b) {-# INLINE (&&=) #-} --- | Modify the target(s) of a 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens', 'Iso, 'Setter' or 'Control.Lens.Traversal.Traversal' by taking their logical '||' with a value+-- | Modify the target(s) of a 'Lens'', 'Iso, 'Setter' or 'Traversal' by taking their logical '||' with a value. -- -- >>> execState (do _1 ||= True; _2 ||= False; _3 ||= True; _4 ||= False) (True,True,False,False) -- (True,True,True,False) -- -- @--- ('||=') :: 'MonadState' s m => 'Control.Lens.Type.Simple' 'Setter' s 'Bool' -> 'Bool' -> m ()--- ('||=') :: 'MonadState' s m => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s 'Bool' -> 'Bool' -> m ()--- ('||=') :: 'MonadState' s m => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s 'Bool' -> 'Bool' -> m ()--- ('||=') :: 'MonadState' s m => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s 'Bool' -> 'Bool' -> m ()+-- ('||=') :: 'MonadState' s m => 'Setter'' s 'Bool'    -> 'Bool' -> m ()+-- ('||=') :: 'MonadState' s m => 'Iso'' s 'Bool'       -> 'Bool' -> m ()+-- ('||=') :: 'MonadState' s m => 'Lens'' s 'Bool'      -> 'Bool' -> m ()+-- ('||=') :: 'MonadState' s m => 'Traversal'' s 'Bool' -> 'Bool' -> m () -- @-(||=) :: MonadState s m => SimpleSetting s Bool -> Bool -> m ()+(||=) :: MonadState s m => ASetter' s Bool -> Bool -> m () l ||= b = State.modify (l ||~ b) {-# INLINE (||=) #-} --- | Run a monadic action, and set all of the targets of a 'Control.Lens.Type.Lens', 'Setter' or 'Control.Lens.Traversal.Traversal' to its result.+-- | Run a monadic action, and set all of the targets of a 'Lens', 'Setter' or 'Traversal' to its result. -- -- @--- ('<~') :: 'MonadState' s m => 'Control.Lens.Iso.Iso' s s a b       -> m b -> m ()--- ('<~') :: 'MonadState' s m => 'Control.Lens.Type.Lens' s s a b      -> m b -> m ()--- ('<~') :: 'MonadState' s m => 'Control.Lens.Traversal.Traversal' s s a b -> m b -> m ()+-- ('<~') :: 'MonadState' s m => 'Iso' s s a b       -> m b -> m ()+-- ('<~') :: 'MonadState' s m => 'Lens' s s a b      -> m b -> m ()+-- ('<~') :: 'MonadState' s m => 'Traversal' s s a b -> m b -> m () -- ('<~') :: 'MonadState' s m => 'Setter' s s a b    -> m b -> m () -- @ ----- As a reasonable mnemonic, this lets you store the result of a monadic action in a lens rather than+-- As a reasonable mnemonic, this lets you store the result of a monadic action in a 'Lens' rather than -- in a local variable. -- -- @@@ -887,26 +972,28 @@ --    ... -- @ ----- will store the result in a 'Control.Lens.Type.Lens', 'Setter', or 'Control.Lens.Traversal.Traversal'.-(<~) :: MonadState s m => Setting s s a b -> m b -> m ()+-- will store the result in a 'Lens', 'Setter', or 'Traversal'.+(<~) :: MonadState s m => ASetter s s a b -> m b -> m () l <~ mb = mb >>= (l .=) {-# INLINE (<~) #-}  -- | Set with pass-through ----- This is useful for chaining assignment without round-tripping through your monad stack.+-- This is useful for chaining assignment without round-tripping through your 'Monad' stack. ----- @do x <- '_2' <.= ninety_nine_bottles_of_beer_on_the_wall@+-- @+-- do x <- 'Control.Lens.Tuple._2' '<.=' ninety_nine_bottles_of_beer_on_the_wall+-- @ ----- If you do not need a copy of the intermediate result, then using @l .= d@ will avoid unused binding warnings+-- If you do not need a copy of the intermediate result, then using @l '.=' d@ will avoid unused binding warnings. -- -- @--- ('<.=') :: 'MonadState' s m => 'Setter' s s a b -> b -> m b--- ('<.=') :: 'MonadState' s m => 'Control.Lens.Iso.Iso' s s a b -> b -> m b--- ('<.=') :: 'MonadState' s m => 'Control.Lens.Type.Lens' s s a b -> b -> m b--- ('<.=') :: 'MonadState' s m => 'Control.Lens.Traversal.Traversal' s s a b -> b -> m b+-- ('<.=') :: 'MonadState' s m => 'Setter' s s a b    -> b -> m b+-- ('<.=') :: 'MonadState' s m => 'Iso' s s a b       -> b -> m b+-- ('<.=') :: 'MonadState' s m => 'Lens' s s a b      -> b -> m b+-- ('<.=') :: 'MonadState' s m => 'Traversal' s s a b -> b -> m b -- @-(<.=) :: MonadState s m => Setting s s a b -> b -> m b+(<.=) :: MonadState s m => ASetter s s a b -> b -> m b l <.= b = do   l .= b   return b@@ -914,19 +1001,21 @@  -- | Set 'Just' a value with pass-through ----- This is useful for chaining assignment without round-tripping through your monad stack.+-- This is useful for chaining assignment without round-tripping through your 'Monad' stack. ----- @do x <- at "foo" <?= ninety_nine_bottles_of_beer_on_the_wall@+-- @+-- do x <- 'Control.Lens.At.at' "foo" '<?=' ninety_nine_bottles_of_beer_on_the_wall+-- @ ----- If you do not need a copy of the intermediate result, then using @l ?= d@ will avoid unused binding warnings+-- If you do not need a copy of the intermediate result, then using @l '?=' d@ will avoid unused binding warnings. -- -- @--- ('<?=') :: 'MonadState' s m => 'Setter' s s a ('Maybe' b) -> b -> m b--- ('<?=') :: 'MonadState' s m => 'Control.Lens.Iso.Iso' s s a ('Maybe' b) -> b -> m b--- ('<?=') :: 'MonadState' s m => 'Control.Lens.Type.Lens' s s a ('Maybe' b) -> b -> m b--- ('<?=') :: 'MonadState' s m => 'Control.Lens.Traversal.Traversal' s s a ('Maybe' b) -> b -> m b+-- ('<?=') :: 'MonadState' s m => 'Setter' s s a ('Maybe' b)    -> b -> m b+-- ('<?=') :: 'MonadState' s m => 'Iso' s s a ('Maybe' b)       -> b -> m b+-- ('<?=') :: 'MonadState' s m => 'Lens' s s a ('Maybe' b)      -> b -> m b+-- ('<?=') :: 'MonadState' s m => 'Traversal' s s a ('Maybe' b) -> b -> m b -- @-(<?=) :: MonadState s m => Setting s s a (Maybe b) -> b -> m b+(<?=) :: MonadState s m => ASetter s s a (Maybe b) -> b -> m b l <?= b = do   l ?= b   return b@@ -944,16 +1033,16 @@ -- ("hello!!!","world!!!") -- -- @--- ('<>~') :: 'Monoid' a => 'Setter' s t a a -> a -> s -> t--- ('<>~') :: 'Monoid' a => 'Iso' s t a a -> a -> s -> t--- ('<>~') :: 'Monoid' a => 'Lens' s t a a -> a -> s -> t+-- ('<>~') :: 'Monoid' a => 'Setter' s t a a    -> a -> s -> t+-- ('<>~') :: 'Monoid' a => 'Iso' s t a a       -> a -> s -> t+-- ('<>~') :: 'Monoid' a => 'Lens' s t a a      -> a -> s -> t -- ('<>~') :: 'Monoid' a => 'Traversal' s t a a -> a -> s -> t -- @-(<>~) :: Monoid a => Setting s t a a -> a -> s -> t+(<>~) :: Monoid a => ASetter s t a a -> a -> s -> t l <>~ n = over l (`mappend` n) {-# INLINE (<>~) #-} --- | Modify the target(s) of a 'Control.Lens.Type.Simple' 'Lens', 'Iso', 'Setter' or 'Traversal' by 'mappend'ing a value.+-- | Modify the target(s) of a 'Lens'', 'Iso', 'Setter' or 'Traversal' by 'mappend'ing a value. -- -- >>> execState (do _1 <>= Sum c; _2 <>= Product d) (Sum a,Product b) -- (Sum {getSum = a + c},Product {getProduct = b * d})@@ -962,18 +1051,163 @@ -- ("hello!!!","world!!!") -- -- @--- ('<>=') :: ('MonadState' s m, 'Monoid' a) => 'Control.Lens.Type.Simple' 'Setter' s a -> a -> m ()--- ('<>=') :: ('MonadState' s m, 'Monoid' a) => 'Control.Lens.Type.Simple' 'Iso' s a -> a -> m ()--- ('<>=') :: ('MonadState' s m, 'Monoid' a) => 'Control.Lens.Type.Simple' 'Lens' s a -> a -> m ()--- ('<>=') :: ('MonadState' s m, 'Monoid' a) => 'Control.Lens.Type.Simple' 'Traversal' s a -> a -> m ()+-- ('<>=') :: ('MonadState' s m, 'Monoid' a) => 'Setter'' s a -> a -> m ()+-- ('<>=') :: ('MonadState' s m, 'Monoid' a) => 'Iso'' s a -> a -> m ()+-- ('<>=') :: ('MonadState' s m, 'Monoid' a) => 'Lens'' s a -> a -> m ()+-- ('<>=') :: ('MonadState' s m, 'Monoid' a) => 'Traversal'' s a -> a -> m () -- @-(<>=) :: (MonadState s m, Monoid a) => SimpleSetting s a -> a -> m ()+(<>=) :: (MonadState s m, Monoid a) => ASetter' s a -> a -> m () l <>= a = State.modify (l <>~ a) {-# INLINE (<>=) #-} --- | Reify a setter so it can be stored safely in a container.-newtype ReifiedSetter s t a b = ReifySetter { reflectSetter :: Setter s t a b }+-----------------------------------------------------------------------------+-- Writer Operations+---------------------------------------------------------------------------- --- | @type 'SimpleReifiedSetter' = 'Control.Lens.Type.Simple' 'ReifiedSetter'@-type SimpleReifiedSetter s a = ReifiedSetter s s a a+-- | Write to a fragment of a larger 'Writer' format.+scribe :: (MonadWriter t m, Monoid s) => ASetter s t a b -> b -> m ()+scribe l b = tell (set l b mempty)+{-# INLINE scribe #-} +-- | This is a generalization of 'pass' that alows you to modify just a+-- portion of the resulting 'MonadWriter'.+passing :: MonadWriter w m => Setter w w u v -> m (a, u -> v) -> m a+passing l m = pass $ do+  (a, uv) <- m+  return (a, over l uv)+{-# INLINE passing #-}++-- | This is a generalization of 'pass' that alows you to modify just a+-- portion of the resulting 'MonadWriter' with access to the index of an+-- 'IndexedSetter'.+ipassing :: MonadWriter w m => IndexedSetter i w w u v -> m (a, i -> u -> v) -> m a+ipassing l m = pass $ do+  (a, uv) <- m+  return (a, iover l uv)+{-# INLINE ipassing #-}++-- | This is a generalization of 'censor' that alows you to 'censor' just a+-- portion of the resulting 'MonadWriter'.+censoring :: MonadWriter w m => Setter w w u v -> (u -> v) -> m a -> m a+censoring l uv = censor (over l uv)+{-# INLINE censoring #-}++-- | This is a generalization of 'censor' that alows you to 'censor' just a+-- portion of the resulting 'MonadWriter', with access to the index of an+-- 'IndexedSetter'.+icensoring :: MonadWriter w m => IndexedSetter i w w u v -> (i -> u -> v) -> m a -> m a+icensoring l uv = censor (iover l uv)+{-# INLINE icensoring #-}++-----------------------------------------------------------------------------+-- Indexed Setters+----------------------------------------------------------------------------+++-- | Map with index. This is an alias for 'imapOf'.+--+-- When you do not need access to the index, then 'over' is more liberal in what it can accept.+--+-- @+-- 'over' l ≡ 'iover' l '.' 'const'+-- 'iover' l ≡ 'over' l '.' 'Indexed'+-- @+--+-- @+-- 'iover' :: 'IndexedSetter' i s t a b    -> (i -> a -> b) -> s -> t+-- 'iover' :: 'IndexedLens' i s t a b      -> (i -> a -> b) -> s -> t+-- 'iover' :: 'IndexedTraversal' i s t a b -> (i -> a -> b) -> s -> t+-- @+iover :: AnIndexedSetter i s t a b -> (i -> a -> b) -> s -> t+iover l = over l .# Indexed+{-# INLINE iover #-}++-- | Build an 'IndexedSetter' from an 'Control.Lens.Indexed.imap'-like function.+--+-- Your supplied function @f@ is required to satisfy:+--+-- @+-- f 'id' ≡ 'id'+-- f g '.' f h ≡ f (g '.' h)+-- @+--+-- Equational reasoning:+--+-- @+-- 'isets' '.' 'iover' ≡ 'id'+-- 'iover' '.' 'isets' ≡ 'id'+-- @+--+-- Another way to view 'sets' is that it takes a \"semantic editor combinator\"+-- and transforms it into a 'Setter'.+isets :: ((i -> a -> b) -> s -> t) -> IndexedSetter i s t a b+isets f = sets (f . indexed)+{-# INLINE isets #-}++-- | Adjust every target of an 'IndexedSetter', 'IndexedLens' or 'IndexedTraversal'+-- with access to the index.+--+-- @+-- ('%@~') ≡ 'imapOf'+-- @+--+-- When you do not need access to the index then ('%@~') is more liberal in what it can accept.+--+-- @+-- l '%~' f ≡ l '%@~' 'const' f+-- @+--+-- @+-- ('%@~') :: 'IndexedSetter' i s t a b    -> (i -> a -> b) -> s -> t+-- ('%@~') :: 'IndexedLens' i s t a b      -> (i -> a -> b) -> s -> t+-- ('%@~') :: 'IndexedTraversal' i s t a b -> (i -> a -> b) -> s -> t+-- @+(%@~) :: AnIndexedSetter i s t a b -> (i -> a -> b) -> s -> t+l %@~ f = l %~ Indexed f+{-# INLINE (%@~) #-}++-- | Adjust every target in the current state of an 'IndexedSetter', 'IndexedLens' or 'IndexedTraversal'+-- with access to the index.+--+-- When you do not need access to the index then ('%=') is more liberal in what it can accept.+--+-- @+-- l '%=' f ≡ l '%@=' 'const' f+-- @+--+-- @+-- ('%@=') :: 'MonadState' s m => 'IndexedSetter' i s s a b    -> (i -> a -> b) -> m ()+-- ('%@=') :: 'MonadState' s m => 'IndexedLens' i s s a b      -> (i -> a -> b) -> m ()+-- ('%@=') :: 'MonadState' s m => 'IndexedTraversal' i s t a b -> (i -> a -> b) -> m ()+-- @+(%@=) :: MonadState s m => AnIndexedSetter i s s a b -> (i -> a -> b) -> m ()+l %@= f = State.modify (l %@~ f)+{-# INLINE (%@=) #-}++------------------------------------------------------------------------------+-- Deprecated+------------------------------------------------------------------------------++-- | 'mapOf' is a deprecated alias for 'over'.+mapOf :: Profunctor p => Setting p s t a b -> p a b -> s -> t+mapOf = over+{-# INLINE mapOf #-}+{-# DEPRECATED mapOf "Use `over`" #-}++-- | Map with index. (Deprecated alias for 'iover').+--+-- When you do not need access to the index, then 'mapOf' is more liberal in what it can accept.+--+-- @+-- 'mapOf' l ≡ 'imapOf' l '.' 'const'+-- @+--+-- @+-- 'imapOf' :: 'IndexedSetter' i s t a b    -> (i -> a -> b) -> s -> t+-- 'imapOf' :: 'IndexedLens' i s t a b      -> (i -> a -> b) -> s -> t+-- 'imapOf' :: 'IndexedTraversal' i s t a b -> (i -> a -> b) -> s -> t+-- @+imapOf :: AnIndexedSetter i s t a b -> (i -> a -> b) -> s -> t+imapOf = iover+{-# INLINE imapOf #-}+{-# DEPRECATED imapOf "Use `iover`" #-}
src/Control/Lens/Simple.hs view
@@ -1,36 +1,69 @@ {-# LANGUAGE Rank2Types #-}-{-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE TypeOperators #-} ----------------------------------------------------------------------------- -- | -- Module      :  Control.Lens.Simple--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com>--- Stability   :  provisional--- Portability :  Rank2Types------ Infix type operators for simple lenses and traversals.+-- Stability   :  experimental+-- Portability :  non-portable ----- These type aliases are not re-exported from @Control.Lens@.-----------------------------------------------------------------------------+-- Deprecated names for simple lenses, etc.+-----------------------------------------------------------------------------+module Control.Lens.Simple where -module Control.Lens.Simple-  ( (:->)-  , (:=>)-  , (:<->)-  ) where+import Control.Lens.Reified+import Control.Lens.Setter+import Control.Lens.Type -import Control.Applicative-import Control.Lens.Iso+------------------------------------------------------------------------------+-- Deprecated+------------------------------------------------------------------------------ -infixr 0 :=>, :->, :<->+-- | Deprecated. Use 'Lens''.+type SimpleLens s a = Lens s s a a+{-# DEPRECATED SimpleLens "use Lens'" #-} --- | This is a commonly used infix alias for a @'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens'@.-type s :-> a = forall f. Functor f => (a -> f a) -> s -> f s+-- | Deprecated. Use 'ReifiedLens''.+type SimpleReifiedLens s a = Lens s s a a+{-# DEPRECATED SimpleReifiedLens "use Lens'" #-} --- | This is a commonly-used infix alias for a @'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal'@.-type s :=> a = forall f. Applicative f => (a -> f a) -> s -> f s+-- | Deprecated. Use 'Traversal''.+type SimpleTraversal s a = Traversal s s a a+{-# DEPRECATED SimpleTraversal "use Traversal'" #-} --- | This is a commonly-used infix alias for a @'Control.Lens.Type.Simple' 'Iso'@-type s :<-> a = Iso s s a a+-- | Deprecated. Use 'ReifiedTraversal''.+type SimpleReifiedTraversal s a = ReifiedTraversal s s a a+{-# DEPRECATED SimpleReifiedTraversal "use ReifiedTraversal'" #-}++-- | Deprecated. Use 'IndexedTraversal''.+type SimpleIndexedTraversal i s a = IndexedTraversal i s s a a+{-# DEPRECATED SimpleIndexedTraversal "use IndexedTraversal'" #-}++-- | Deprecated. Use 'ReifiedIndexedTraversal''.+type SimpleReifiedIndexedTraversal i s a = ReifiedIndexedTraversal i s s a a+{-# DEPRECATED SimpleReifiedIndexedTraversal "use ReifiedIndexedTraversal'" #-}++-- | Deprecated. Use 'Setter''.+type SimpleSetter s a = Setter s s a a+{-# DEPRECATED SimpleSetter "use Setter'" #-}++-- | Deprecated. Use 'ReifiedSetter''.+type SimpleReifiedSetter s a = ReifiedSetter s s a a+{-# DEPRECATED SimpleReifiedSetter "use ReifiedSetter'" #-}++-- | Deprecated. Use 'IndexedSetter''.+type SimpleIndexedSetter i s a = IndexedSetter i s s a a+{-# DEPRECATED SimpleIndexedSetter "use IndexedSetter'" #-}++-- | Deprecated. Use 'ReifiedIndexedSetter''.+type SimpleReifiedIndexedSetter i s a = ReifiedIndexedSetter i s s a a+{-# DEPRECATED SimpleReifiedIndexedSetter "use ReifiedIndexedSetter'" #-}++-- | Deprecated. Use 'Iso''.+type SimpleIso s a = Iso s s a a+{-# DEPRECATED SimpleIso "use Iso'" #-}++-- | Deprecated. Use 'Prism''.+type SimplePrism s a = Prism s s a a+{-# DEPRECATED SimplePrism "use Prism'" #-}
src/Control/Lens/TH.hs view
@@ -1,21 +1,21 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE FunctionalDependencies #-} #ifdef TRUSTWORTHY {-# LANGUAGE Trustworthy #-} #endif --- in case we're being loaded from ghci #ifndef MIN_VERSION_template_haskell #define MIN_VERSION_template_haskell(x,y,z) (defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 706) #endif ----------------------------------------------------------------------------- -- | -- Module      :  Control.Lens.TH--- Copyright   :  (C) 2012 Edward Kmett, Michael Sloan+-- Copyright   :  (C) 2012-13 Edward Kmett, Michael Sloan -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  experimental--- Portability :  TemplateHaskell+-- Portability :  non-portable -- ----------------------------------------------------------------------------- module Control.Lens.TH@@ -25,10 +25,17 @@   , makeClassy, makeClassyFor   , makeIso   , makePrisms+  , makeWrapped+  , makeFields   -- * Configuring Lenses   , makeLensesWith+  , makeFieldsWith   , defaultRules+  , defaultFieldRules+  , camelCaseFields+  , underscoreFields   , LensRules(LensRules)+  , FieldRules(FieldRules)   , lensRules   , classyRules   , isoRules@@ -54,31 +61,35 @@ #if !(MIN_VERSION_template_haskell(2,7,0)) import Control.Monad (ap) #endif+import Control.Lens.At import Control.Lens.Combinators import Control.Lens.Fold import Control.Lens.Getter-import Control.Lens.IndexedLens import Control.Lens.Iso+import Control.Lens.Lens import Control.Lens.Prism import Control.Lens.Setter import Control.Lens.Tuple import Control.Lens.Traversal-import Control.Lens.Type-import Data.Char (toLower)+import Control.Lens.Wrapped+import Data.Char (toLower, toUpper, isUpper) import Data.Either (lefts) import Data.Foldable hiding (concat) import Data.Function (on) import Data.List as List import Data.Map as Map hiding (toList,map,filter)-import Data.Maybe (isNothing,isJust,catMaybes,fromJust,fromMaybe)+import Data.Maybe as Maybe (isNothing,isJust,catMaybes,fromJust,mapMaybe) import Data.Ord (comparing) import Data.Set as Set hiding (toList,map,filter) import Data.Set.Lens import Data.Traversable hiding (mapM) import Language.Haskell.TH+import Language.Haskell.TH.Syntax import Language.Haskell.TH.Lens --- | Flags for lens construction+{-# ANN module "HLint: ignore Use foldl" #-}++-- | Flags for 'Lens' construction data LensFlag   = SimpleLenses   | PartialLenses@@ -93,60 +104,62 @@   | GenerateSignatures   deriving (Eq,Ord,Show,Read) --- | Only Generate valid 'Simple' 'Lens' lenses.-simpleLenses      :: Simple Lens LensRules Bool+-- | Only Generate valid 'Control.Lens.Type.Simple' lenses.+simpleLenses      :: Lens' LensRules Bool simpleLenses       = lensFlags.contains SimpleLenses  -- | Enables the generation of partial lenses, generating runtime errors for--- every constructor that does not have a valid definition for the lens. This+-- every constructor that does not have a valid definition for the 'Lens'. This -- occurs when the constructor lacks the field, or has multiple fields mapped--- to the same lens.-partialLenses     :: Simple Lens LensRules Bool+-- to the same 'Lens'.+partialLenses     :: Lens' LensRules Bool partialLenses      = lensFlags.contains PartialLenses --- | In the situations that a lens would be partial, when 'partialLenses' is--- used, this flag instead causes traversals to be generated.  Only one can be+-- | In the situations that a 'Lens' would be partial, when 'partialLenses' is+-- used, this flag instead causes traversals to be generated. Only one can be -- used, and if neither are, then compile-time errors are generated.-buildTraversals   :: Simple Lens LensRules Bool+buildTraversals   :: Lens' LensRules Bool buildTraversals    = lensFlags.contains BuildTraversals  -- | Handle singleton constructors specially.-handleSingletons  :: Simple Lens LensRules Bool+handleSingletons  :: Lens' LensRules Bool handleSingletons   = lensFlags.contains HandleSingletons --- | When building a singleton 'Iso' (or 'Lens') for a record constructor, build both--- the 'Iso' (or 'Lens') for the record and the one for the field.-singletonAndField :: Simple Lens LensRules Bool+-- | When building a singleton 'Iso' (or 'Lens') for a record constructor, build+-- both the 'Iso' (or 'Lens') for the record and the one for the field.+singletonAndField :: Lens' LensRules Bool singletonAndField  = lensFlags.contains SingletonAndField  -- | Use 'Iso' for singleton constructors.-singletonIso      :: Simple Lens LensRules Bool+singletonIso      :: Lens' LensRules Bool singletonIso       = lensFlags.contains SingletonIso  -- | Expect a single constructor, single field newtype or data type.-singletonRequired :: Simple Lens LensRules Bool+singletonRequired :: Lens' LensRules Bool singletonRequired  = lensFlags.contains SingletonRequired --- | Create the class if the constructor is simple and the 'lensClass' rule matches.-createClass       :: Simple Lens LensRules Bool+-- | Create the class if the constructor is 'Control.Lens.Type.Simple' and the 'lensClass' rule matches.+createClass       :: Lens' LensRules Bool createClass        = lensFlags.contains CreateClass --- | Create the instance if the constructor is simple and the 'lensClass' rule matches.-createInstance    :: Simple Lens LensRules Bool+-- | Create the instance if the constructor is 'Control.Lens.Type.Simple' and the 'lensClass' rule matches.+createInstance    :: Lens' LensRules Bool createInstance     = lensFlags.contains CreateInstance  -- | Die if the 'lensClass' fails to match.-classRequired     :: Simple Lens LensRules Bool+classRequired     :: Lens' LensRules Bool classRequired      = lensFlags.contains ClassRequired --- | Indicate whether or not to supply the signatures for the generated lenses.+-- | Indicate whether or not to supply the signatures for the generated+-- lenses. ----- Disabling this can be useful if you want to provide a more restricted type signature--- or if you want to supply hand-written haddocks.-generateSignatures :: Simple Lens LensRules Bool+-- Disabling this can be useful if you want to provide a more restricted type+-- signature or if you want to supply hand-written haddocks.+generateSignatures :: Lens' LensRules Bool generateSignatures = lensFlags.contains GenerateSignatures --- | This configuration describes the options we'll be using to make isomorphisms or lenses.+-- | This configuration describes the options we'll be using to make+-- isomorphisms or lenses. data LensRules = LensRules   { _lensIso   :: String -> Maybe String   , _lensField :: String -> Maybe String@@ -154,30 +167,31 @@   , _lensFlags :: Set LensFlag   } --- | Lens to access the convention for naming top level isomorphisms in our lens rules.+-- | 'Lens'' to access the convention for naming top level isomorphisms in our+-- 'LensRules'. -- -- Defaults to lowercasing the first letter of the constructor.-lensIso :: Simple Lens LensRules (String -> Maybe String)+lensIso :: Lens' LensRules (String -> Maybe String) lensIso f (LensRules i n c o) = f i <&> \i' -> LensRules i' n c o --- | Lens to access the convention for naming fields in our lens rules.+-- | 'Lens'' to access the convention for naming fields in our 'LensRules'. -- -- Defaults to stripping the _ off of the field name, lowercasing the name, and -- rejecting the field if it doesn't start with an '_'.-lensField :: Simple Lens LensRules (String -> Maybe String)+lensField :: Lens' LensRules (String -> Maybe String) lensField f (LensRules i n c o) = f n <&> \n' -> LensRules i n' c o  -- | Retrieve options such as the name of the class and method to put in it to -- build a class around monomorphic data types.-lensClass :: Simple Lens LensRules (String -> Maybe (String, String))+lensClass :: Lens' LensRules (String -> Maybe (String, String)) lensClass f (LensRules i n c o) = f c <&> \c' -> LensRules i n c' o  -- | Retrieve options such as the name of the class and method to put in it to -- build a class around monomorphic data types.-lensFlags :: Simple Lens LensRules (Set LensFlag)+lensFlags :: Lens' LensRules (Set LensFlag) lensFlags f (LensRules i n c o) = f o <&> LensRules i n c --- | Default lens rules+-- | Default 'LensRules'. defaultRules :: LensRules defaultRules = LensRules mLowerName fld (const Nothing) $     Set.fromList [SingletonIso, SingletonAndField, CreateClass, CreateInstance, BuildTraversals, GenerateSignatures]@@ -199,7 +213,7 @@   & partialLenses    .~ False   & buildTraversals  .~ True --- | Rules for making lenses and traversals that precompose another lens.+-- | Rules for making lenses and traversals that precompose another 'Lens'. classyRules :: LensRules classyRules = defaultRules   & lensIso .~ const Nothing@@ -213,7 +227,7 @@     classy n@(a:as) = Just ("Has" ++ n, toLower a:as)     classy _ = Nothing --- | Rules for making an isomorphism from a data type+-- | Rules for making an isomorphism from a data type. isoRules :: LensRules isoRules = defaultRules   & handleSingletons  .~ True@@ -222,11 +236,14 @@  -- | Build lenses (and traversals) with a sensible default configuration. ----- > makeLenses = makeLensesWith lensRules+-- @+-- 'makeLenses' = 'makeLensesWith' 'lensRules'+-- @ makeLenses :: Name -> Q [Dec] makeLenses = makeLensesWith lensRules --- | Make lenses and traversals for a type, and create a class when the type has no arguments.+-- | Make lenses and traversals for a type, and create a class when the+-- type has no arguments. -- -- /e.g./ --@@ -239,53 +256,64 @@ -- -- @ -- class HasFoo t where---   foo :: 'Simple' 'Lens' t Foo+--   foo :: 'Control.Lens.Type.Simple' 'Lens' t Foo -- instance HasFoo Foo where foo = 'id'--- fooX, fooY :: HasFoo t => 'Simple' 'Lens' t 'Int'+-- fooX, fooY :: HasFoo t => 'Control.Lens.Type.Simple' 'Lens' t 'Int' -- @ ----- > makeClassy = makeLensesWith classyRules+-- @+-- 'makeClassy' = 'makeLensesWith' 'classyRules'+-- @ makeClassy :: Name -> Q [Dec] makeClassy = makeLensesWith classyRules  -- | Make a top level isomorphism injecting /into/ the type. ----- The supplied name is required to be for a type with a single constructor that has a single argument+-- The supplied name is required to be for a type with a single constructor+-- that has a single argument. -- -- /e.g./ -- -- @--- newtype List a = List [a]--- makeIso ''List+-- newtype 'List' a = 'List' [a]+-- 'makeIso' ''List -- @ -- -- will create -- -- @--- list :: Iso [a] [b] ('List' a) ('List' b)+-- 'list' :: 'Iso' [a] [b] ('List' a) ('List' b) -- @ ----- > makeIso = makeLensesWith isoRules+-- @+-- 'makeIso' = 'makeLensesWith' 'isoRules'+-- @ makeIso :: Name -> Q [Dec] makeIso = makeLensesWith isoRules --- | Derive lenses and traversals, specifying explicit pairings of @(fieldName, lensName)@.+-- | Derive lenses and traversals, specifying explicit pairings+-- of @(fieldName, lensName)@. ----- If you map multiple names to the same label, and it is present in the same constructor then this will generate a 'Traversal'.+-- If you map multiple names to the same label, and it is present in the same+-- constructor then this will generate a 'Traversal'. -- -- /e.g./ ----- > makeLensesFor [("_foo", "fooLens"), ("baz", "lbaz")] ''Foo--- > makeLensesFor [("_barX", "bar"), ("_barY", "bar)] ''Bar+-- @+-- 'makeLensesFor' [(\"_foo\", \"fooLens\"), (\"baz\", \"lbaz\")] ''Foo+-- 'makeLensesFor' [(\"_barX\", \"bar\"), (\"_barY\", \"bar\")] ''Bar+-- @ makeLensesFor :: [(String, String)] -> Name -> Q [Dec] makeLensesFor fields = makeLensesWith $ lensRules & lensField .~ (`Prelude.lookup` fields) --- | Derive lenses and traversals, using a named wrapper class, and specifying--- explicit pairings of @(fieldName, traversalName)@.+-- | Derive lenses and traversals, using a named wrapper class, and+-- specifying explicit pairings of @(fieldName, traversalName)@. -- -- Example usage: ----- > makeClassyFor "HasFoo" "foo" [("_foo", "fooLens"), ("bar", "lbar")] ''Foo+-- @+-- 'makeClassyFor' \"HasFoo\" \"foo\" [(\"_foo\", \"fooLens\"), (\"bar\", \"lbar\")] ''Foo+-- @ makeClassyFor :: String -> String -> [(String, String)] -> Name -> Q [Dec] makeClassyFor clsName funName fields = makeLensesWith $ classyRules   & lensClass .~ const (Just (clsName,funName))@@ -296,8 +324,8 @@ makeLensesWith cfg nm = do     inf <- reify nm     case inf of-      (TyConI decl) -> case deNewtype decl of-        (DataD ctx tyConName args cons _) -> case cons of+      TyConI decl -> case deNewtype decl of+        DataD ctx tyConName args cons _ -> case cons of           [NormalC dataConName [(    _,ty)]]             | cfg^.handleSingletons  -> makeIsoLenses cfg ctx tyConName args dataConName Nothing ty           [RecC    dataConName [(fld,_,ty)]]@@ -307,6 +335,7 @@         _ -> fail "makeLensesWith: Unsupported data type"       _ -> fail "makeLensesWith: Expected the name of a data type or newtype" +-- | Generate a 'Prism' for each constructor of a data type. makePrisms :: Name -> Q [Dec] makePrisms nm = do     inf <- reify nm@@ -321,7 +350,7 @@ -- Internal TH Implementation ----------------------------------------------------------------------------- --- | Transform @NewtypeD@s declarations to @DataD@s+-- | Transform @NewtypeD@s declarations to @DataD@s. deNewtype :: Dec -> Dec deNewtype (NewtypeD ctx tyConName args c d) = DataD ctx tyConName args [c] d deNewtype d = d@@ -332,59 +361,55 @@   where     conTypeVars = map (Set.fromList . toListOf typeVars) cons     canModifyTypeVar = (`Set.member` typeVarsOnlyInOneCon) . view name-    typeVarsOnlyInOneCon =-      Set.fromList . concat . filter ((== 1) . length) .-      List.group . List.sort . concat $-      map toList conTypeVars+    typeVarsOnlyInOneCon = Set.fromList . concat . filter (\xs -> length xs == 1) .  List.group . List.sort $ conTypeVars >>= toList  makePrismForCon :: [Pred] -> Name -> [TyVarBndr] -> (TyVarBndr -> Bool) -> [Con] -> Con -> Q [Dec]-makePrismForCon ctx tyConName args canModifyTypeVar allCons con =-    return-    [ SigD resName .-      ForallT+makePrismForCon ctx tyConName args canModifyTypeVar allCons con = do+    remitterName <- newName "remitter"+    reviewerName <- newName "reviewer"+    xName <- newName "x"+    let resName = mkName $ '_': nameBase dataConName+    varNames <- for [0..length fieldTypes -1] $ \i -> newName ('x' : show i)+    altArgsList <- forM (view name <$> filter isAltArg args) $ \arg ->+      (,) arg <$> newName (nameBase arg)+    let altArgs = Map.fromList altArgsList+        hitClause =+          clause [conP dataConName (fmap varP varNames)]+          (normalB $ appE (conE 'Right) $ toTupleE $ varE <$> varNames) []+        otherCons = filter (/= con) allCons+        missClauses+          | List.null otherCons   = []+          | Map.null altArgs = [clause [varP xName] (normalB (appE (conE 'Left) (varE xName))) []]+          | otherwise        = reviewerIdClause <$> otherCons+    Prelude.sequence [+      sigD resName . forallT         (args ++ (PlainTV <$> Map.elems altArgs))-        (List.nub (ctx ++ substTypeVars altArgs ctx)) $-      List.foldl1 AppT-      [ ConT ''Prism-      , List.foldl AppT (ConT tyConName) (VarT . view name <$> args)-      , List.foldl AppT (ConT tyConName) (VarT . view name <$> substTypeVars altArgs args)-      , toTupleT fieldTypes-      , toTupleT $ substTypeVars altArgs fieldTypes-      ]-    , FunD resName-      [ Clause []-        (NormalB (List.foldl1 AppE [VarE 'prism, VarE remiterName, VarE reviewerName]))-        [remiter, reviewer]+        (return $ List.nub (ctx ++ substTypeVars altArgs ctx)) $+         if altArgsList == [] then+          conT ''Prism' `appsT`+            [ appsT (conT tyConName) $ varT . view name <$> args+            , toTupleT $ pure <$> fieldTypes+            ]+         else+          conT ''Prism `appsT`+            [ appsT (conT tyConName) $ varT . view name <$> args+            , appsT (conT tyConName) $ varT . view name <$> substTypeVars altArgs args+            , toTupleT $ pure <$> fieldTypes+            , toTupleT $ pure <$> substTypeVars altArgs fieldTypes+            ]+      , funD resName+        [ clause []+          (normalB (appsE [varE 'prism, varE remitterName, varE reviewerName]))+          [ funD remitterName+            [ clause [toTupleP (varP <$> varNames)] (normalB (appsE (conE dataConName : fmap varE varNames))) [] ]+          , funD reviewerName $ hitClause : missClauses+          ]+        ]       ]-    ]   where     (dataConName, fieldTypes) = ctrNameAndFieldTypes con-    resName =-      mkName .-      fromMaybe (error ("bad constructor name: " ++ show dataConName)) . mLowerName $-      nameBase dataConName-    altArgs = Map.fromList . map (mkAltArg . view name) $ filter isAltArg args-    isAltArg arg = canModifyTypeVar arg && Set.member (arg ^. name) conArgs-    conArgs = Set.fromList $ toListOf typeVars fieldTypes-    mkAltArg arg = (arg, mkName (nameBase arg ++ "'"))-    reviewerName = mkName "reviewer"-    reviewer = FunD reviewerName $ hitClause : missClauses-    hitClause =-      Clause [ConP dataConName (VarP <$> varNames)]-      ((NormalB . AppE (ConE 'Right) . toTupleE) (VarE <$> varNames)) []-    missClauses-      | Map.null altArgs =-        [Clause [VarP xName] (NormalB (AppE (ConE 'Left) (VarE xName))) []]-      | otherwise =-        reviewerIdClause <$> filter (/= con) allCons-    varNames = map (mkName . ('x' :) . show) [0 .. length fieldTypes - 1]-    xName = mkName "x"-    remiterName = mkName "remiter"-    remiter =-      FunD remiterName-      [ Clause [toTupleP (VarP <$> varNames)]-        (NormalB (List.foldl AppE (ConE dataConName) (VarE <$> varNames))) []-      ]+    conArgs = setOf typeVars fieldTypes+    isAltArg arg = canModifyTypeVar arg && conArgs^.contains(arg^.name)  ctrNameAndFieldTypes :: Con -> (Name, [Type]) ctrNameAndFieldTypes (NormalC n ts) = (n, snd <$> ts)@@ -392,29 +417,31 @@ ctrNameAndFieldTypes (InfixC l n r) = (n, [snd l, snd r]) ctrNameAndFieldTypes (ForallC _ _ c) = ctrNameAndFieldTypes c --- When a prism can change type variables it needs to pattern match on all+-- When a 'Prism' can change type variables it needs to pattern match on all -- other data constructors and rebuild the data so it will have the new type.-reviewerIdClause :: Con -> Clause-reviewerIdClause con =-    Clause [ConP dataConName (VarP <$> varNames)]-    ((NormalB . AppE (ConE 'Left)) (List.foldl AppE (ConE dataConName) (VarE <$> varNames))) []-  where-    (dataConName, fieldTypes) = ctrNameAndFieldTypes con-    varNames = map (mkName . ('x' :) . show) [0 .. length fieldTypes - 1]+reviewerIdClause :: Con -> ClauseQ+reviewerIdClause con = do+  let (dataConName, fieldTypes) = ctrNameAndFieldTypes con+  varNames <- for [0 .. length fieldTypes - 1] $ \i ->+                newName ('x' : show i)+  clause [conP dataConName (fmap varP varNames)]+         (normalB $ appE (conE 'Left) $ appsE (conE dataConName : fmap varE varNames))+         [] -toTupleT :: [Type] -> Type+toTupleT :: [TypeQ] -> TypeQ toTupleT [x] = x-toTupleT xs = List.foldl AppT (TupleT (length xs)) xs+toTupleT xs = appsT (tupleT (length xs)) xs -toTupleE :: [Exp] -> Exp+toTupleE :: [ExpQ] -> ExpQ toTupleE [x] = x-toTupleE xs = TupE xs+toTupleE xs = tupE xs -toTupleP :: [Pat] -> Pat+toTupleP :: [PatQ] -> PatQ toTupleP [x] = x-toTupleP xs = TupP xs+toTupleP xs = tupP xs --- | Given a set of names, build a map from those names to a set of fresh names based on them.+-- | Given a set of names, build a map from those names to a set of fresh names+-- based on them. freshMap :: Set Name -> Q (Map Name Name) freshMap ns = Map.fromList <$> for (toList ns) (\ n -> (,) n <$> newName (nameBase n)) @@ -478,11 +505,15 @@       lensOnly = not $ cfg^.singletonIso       isoCon   | lensOnly  = ConT ''Lens                | otherwise = ConT ''Iso+      isoCon'  | lensOnly  = ConT ''Lens'+               | otherwise = ConT ''Iso'       makeBody | lensOnly  = makeLensBody                | otherwise = makeIsoBody   isoDecls <- flip (maybe (return [])) maybeIsoName $ \isoName -> do-    let decl = SigD isoName $ quantified $ isoCon `apps`-          if cfg^.simpleLenses then [aty,aty,cty,cty] else [aty,bty,cty,dty]+    let decl = SigD isoName $ quantified $+          if cfg^.simpleLenses || Map.null m+          then isoCon' `apps` [aty,cty]+          else isoCon `apps` [aty,bty,cty,dty]     body <- makeBody isoName dataConName makeIsoFrom makeIsoTo #ifndef INLINING     return $ if cfg^.generateSignatures then [decl, body] else [body]@@ -493,9 +524,10 @@   accessorDecls <- case mkName <$> (maybeFieldName >>= view lensField cfg . nameBase) of     jfn@(Just lensName)       | (jfn /= maybeIsoName) && (isNothing maybeIsoName || cfg^.singletonAndField) -> do-      let decl = SigD lensName $ quantified $ isoCon `apps`-                   if cfg^.simpleLenses then [cty,cty,aty,aty]-                                        else [cty,dty,aty,bty]+      let decl = SigD lensName $ quantified $+            if cfg^.simpleLenses || Map.null m+            then isoCon' `apps` [cty,aty]+            else isoCon `apps` [cty,dty,aty,bty]       body <- makeBody lensName dataConName makeIsoTo makeIsoFrom #ifndef INLINING       return $ if cfg^.generateSignatures then [decl, body] else [body]@@ -613,11 +645,13 @@             else "The following constructors failed this criterion for the " ++ pprint lensName ++ " lens:"           ] ++ map showCon conList -    --TODO: consider detecting simpleLenses, and generating signatures involving "Simple"?-    let decl = SigD lensName-             . ForallT tvs' qs-             . apps (ConT (if isTraversal then ''Traversal else ''Lens))-             $ if cfg^.simpleLenses || isJust maybeClassName then [aty,aty,cty,cty] else [aty,bty,cty,dty]+    let decl = SigD lensName $ ForallT tvs' qs vars+          where+          vars+            | aty == bty && cty == dty || cfg^.simpleLenses || isJust maybeClassName+               = apps (ConT (if isTraversal then ''Traversal' else ''Lens')) [aty,cty]+            | otherwise+               = apps (ConT (if isTraversal then ''Traversal else ''Lens)) [aty,bty,cty,dty]      body <- makeFieldLensBody isTraversal lensName conList maybeMethodName #ifndef INLINING@@ -637,7 +671,7 @@       Prelude.sequence $         filter (\_ -> cfg^.createClass) [           classD (return []) clsName (PlainTV t : tyArgs) (if List.null tyArgs then [] else [FunDep [t] (view name <$> tyArgs)]) (-            sigD methodName (appsT (conT ''Lens) [varT t, varT t, appliedCon, appliedCon]) :+            sigD methodName (appsT (conT ''Lens') [varT t, appliedCon]) :             map return defs)]         ++ filter (\_ -> cfg^.createInstance) [           instanceD (return []) ((conT clsName `appT` appliedCon) `appsT` varArgs) [@@ -648,7 +682,7 @@             ]]         ++ filter (\_ -> not $ cfg^.createClass) (map return defs) --- | Gets @[(lens name, (constructor name, field name, type))]@ from a record constructor+-- | Gets @[(lens name, (constructor name, field name, type))]@ from a record constructor. getLensFields :: (String -> Maybe String) -> Con -> Q [(Name, (Name, Name, Type))] getLensFields f (RecC cn fs)   = return . catMaybes@@ -664,6 +698,45 @@ unifyTypes :: [TyVarBndr] -> [Type] -> Q ([TyVarBndr], Type) unifyTypes tvs tys = return (tvs, head tys) +-- | Build 'Wrapped' instance for a given newtype+makeWrapped :: Name -> DecsQ+makeWrapped nm = do+  inf <- reify nm+  case inf of+    TyConI decl ->+      case deNewtype decl of+        DataD _ tyConName args [con] _ -> makeWrappedInstance tyConName args con+        _                              -> fail "makeWrapped: Unsupported data type"+    _ -> fail "makeWrapped: Expected the name of a newtype or datatype"++makeWrappedInstance :: Name -> [TyVarBndr] -> Con -> DecsQ+makeWrappedInstance tyConName tyArgs con = do+  let tyNames = view name <$> tyArgs++  tyNameRemap <- makeNameRemap tyNames++  (newtypeConName, fieldType) <- case ctrNameAndFieldTypes con of+    (a,[b]) -> return (a,b)+    _       -> fail "makeWrappedInstance: Constructor must have a single field"++  let outer1 = conT tyConName `appsT` fmap varT tyNames+      inner1 = return fieldType++      outer2 = conT tyConName `appsT` fmap (varT . snd) tyNameRemap+      inner2 = return $ substTypeVars (Map.fromList tyNameRemap) fieldType++  dec <- instanceD (cxt [])+             (conT ''Wrapped `appsT` [inner1, inner2, outer1, outer2])+             [makeIsoBody 'wrapped newtypeConName makeIsoFrom makeIsoTo]++  return [dec]+  where+  -- Return list to preserve order, convert to Map later+  makeNameRemap tyNames+    = for tyNames $ \ tyName -> do+        tyName1 <- newName (show tyName)+        return (tyName, tyName1)+ #if !(MIN_VERSION_template_haskell(2,7,0)) -- | The orphan instance for old versions is bad, but programming without 'Applicative' is worse. instance Applicative Q where@@ -690,3 +763,111 @@ #endif  #endif++data FieldRules = FieldRules+    { _getPrefix          :: String -> Maybe String+    , _rawLensNaming      :: String -> String+    , _niceLensNaming     :: String -> Maybe String+    , _classNaming        :: String -> Maybe String+    }++data Field = Field+    { _fieldName          :: Name+    , _fieldLensPrefix    :: String+    , _fieldLensName      :: Name+    , _fieldClassName     :: Name+    , _fieldClassLensName :: Name+    }++unqualify :: String -> String+unqualify = tail . dropWhile (/= '.')++overHead :: (a -> a) -> [a] -> [a]+overHead _ []     = []+overHead f (x:xs) = f x : xs++-- | Field rules for fields in the form @ _prefix_fieldname @+underscoreFields :: FieldRules+underscoreFields = FieldRules prefix rawLens niceLens classNaming+  where+    prefix ('_':xs) | '_' `List.elem` xs = Just (takeWhile (/= '_') xs)+    prefix _                             = Nothing+    rawLens     x = x ++ "_lens"+    niceLens    x = prefix   x <&> \n -> drop (length n + 2) n+    classNaming x = niceLens x <&> ("Has_" ++)++-- | Field rules for fields in the form @ prefixFieldname @+camelCaseFields :: FieldRules+camelCaseFields = FieldRules prefix rawLens niceLens classNaming+  where+    sep x = case break isUpper x of+        (p, s) | List.null p || List.null s -> Nothing+               | otherwise                  -> Just (p,s)+    prefix      x = do ('_':xs,_) <- sep x; return xs+    rawLens     x = x ++ "Lens"+    niceLens    x = overHead toLower . snd <$> sep x+    classNaming x = niceLens x <&> \ (n:ns) -> "Has" ++ toUpper n : ns++verboseLenses :: FieldRules -> Name -> Q [Dec]+verboseLenses c src = do+    TyConI (DataD _ _ _ [RecC _ rs] _) <- reify src+    flip makeLensesFor src+        $ mkFields c rs+        & map (\(Field n _ l _ _) -> (show n, show l))++mkFields :: FieldRules -> [VarStrictType] -> [Field]+mkFields (FieldRules prefix' raw' nice' clas') rs+    = Maybe.mapMaybe namer rs+    & List.groupBy (on (==) _fieldLensPrefix)+    & (\ gs -> case gs of +        x:_ -> x+        _   -> [])+  where+    namer (n', _, _) = do+        let field   = unqualify (show n')+            rawlens = mkName (raw' field)+        prefix <- prefix' field+        nice   <- mkName <$> nice' field+        clas   <- mkName <$> clas' field+        return (Field (mkName field) prefix rawlens clas nice)++hasClassAndInstance :: FieldRules -> Name -> Q [Dec]+hasClassAndInstance cfg src = do+    TyConI (DataD _ _ _ [RecC _ rs] _) <- reify src+    fmap concat . forM (mkFields cfg rs) $ \(Field field _ fullLensName className lensName) -> do+        classHas <- classD+            (return [])+            className+            [ PlainTV c, PlainTV e ]+            [ FunDep [c] [e] ]+            [ sigD lensName (appsT (conT ''Lens') [varT c, varT e])]++        VarI _ (AppT _ fieldType) _ _ <-  reify field++        instanceHas <- instanceD+            (return [])+            (conT className `appsT` [conT src, return fieldType])+            [+#ifdef INLINING+              inlinePragma lensName,+#endif+              funD lensName [ clause [] (normalB (global fullLensName)) [] ]+            ]++        classAlreadyExists <- isJust `fmap` lookupTypeName (show className)+        return (if classAlreadyExists then [instanceHas] else [classHas, instanceHas])++    where c = mkName "c"+          e = mkName "e"++-- | Make fields with the specified 'FieldRules'.+makeFieldsWith :: FieldRules -> Name -> Q [Dec]+makeFieldsWith c n = liftA2 (++) (verboseLenses c n) (hasClassAndInstance c n)++-- | @ makeFields = 'makeFieldsWith' 'defaultFieldRules' @+makeFields :: Name -> Q [Dec]+makeFields = makeFieldsWith defaultFieldRules++-- | @ defaultFieldRules = 'camelCaseFields' @+defaultFieldRules :: FieldRules+defaultFieldRules = camelCaseFields
src/Control/Lens/Traversal.hs view
@@ -1,47 +1,57 @@ {-# LANGUAGE CPP #-}-{-# LANGUAGE MagicHash #-}+{-# LANGUAGE GADTs #-} {-# LANGUAGE Rank2Types #-}-{-# LANGUAGE TypeOperators #-} {-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE LiberalTypeSynonyms #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE ScopedTypeVariables #-}+ #ifdef TRUSTWORTHY {-# LANGUAGE Trustworthy #-} #endif -#ifndef MIN_VERSION_mtl-#define MIN_VERSION_mtl(x,y,z) 1+#ifndef MIN_VERSION_containers+#define MIN_VERSION_containers(x,y,z) 1 #endif- ----------------------------------------------------------------------------- -- | -- Module      :  Control.Lens.Traversal--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  provisional -- Portability :  Rank2Types -- -- A @'Traversal' s t a b@ is a generalization of 'traverse' from--- 'Traversable'. It allows you to traverse over a structure and change out--- its contents with monadic or applicative side-effects. Starting from+-- 'Traversable'. It allows you to 'traverse' over a structure and change out+-- its contents with monadic or 'Applicative' side-effects. Starting from ----- @'traverse' :: ('Traversable' t, 'Applicative' f) => (a -> f b) -> t a -> f (t b)@+-- @+-- 'traverse' :: ('Traversable' t, 'Applicative' f) => (a -> f b) -> t a -> f (t b)+-- @ -- -- we monomorphize the contents and result to obtain ----- @type 'Traversal' s t a b = forall f. 'Applicative' f => (a -> f b) -> s -> f t@+-- @+-- type 'Traversal' s t a b = forall f. 'Applicative' f => (a -> f b) -> s -> f t+-- @ ----- While a 'Traversal' isn't quite a 'Fold', it _can_ be used for 'Getting'--- like a 'Fold', because given a 'Monoid' @m@, we have an 'Applicative'+-- While a 'Traversal' isn't quite a 'Fold', it _can_ be used for+-- 'Control.Lens.Getter.Getting' like a 'Fold', because given a+-- 'Data.Monoid.Monoid' @m@, we have an 'Applicative' -- for @('Const' m)@. Everything you know how to do with a 'Traversable' -- container, you can with with a 'Traversal', and here we provide -- combinators that generalize the usual 'Traversable' operations. ---------------------------------------------------------------------------- module Control.Lens.Traversal   (-  -- * Lenses-    Traversal+  -- * Traversals+    Traversal, Traversal'+  , IndexedTraversal, IndexedTraversal'+  , ATraversal, ATraversal'+  , AnIndexedTraversal, AnIndexedTraversal'+  , Traversing, Traversing'    -- * Traversing and Lensing   , traverseOf, forOf, sequenceAOf@@ -50,14 +60,16 @@   , mapAccumLOf, mapAccumROf   , scanr1Of, scanl1Of +  -- * Monomorphic Traversals+  , cloneTraversal+  , cloneIndexPreservingTraversal+  , cloneIndexedTraversal+   -- * Parts and Holes-  , partsOf-  , partsOf'-  , unsafePartsOf-  , unsafePartsOf'+  , partsOf, partsOf'+  , unsafePartsOf, unsafePartsOf'   , holesOf-  , singular-  , unsafeSingular+  , singular, unsafeSingular    -- * Common Traversals   , Traversable(traverse)@@ -65,101 +77,147 @@   , beside   , taking   , dropping-  , loci +  -- * Indexed Traversals -  -- * Cloning Traversals-  , cloneTraversal-  , ReifiedTraversal(..)+  -- ** Common+  , ignored+  , TraverseMin(..)+  , TraverseMax(..)+  , traversed+  , traversed64+  , elementOf+  , element+  , elementsOf+  , elements -  -- * Simple-  , SimpleTraversal-  , SimpleReifiedTraversal+  -- ** Combinators+  , ipartsOf+  , ipartsOf'+  , iunsafePartsOf+  , iunsafePartsOf'+  , itraverseOf+  , iforOf+  , imapMOf+  , iforMOf+  , imapAccumROf+  , imapAccumLOf -  -- * Exposed Implementation Details+  -- * Implementation Details   , Bazaar(..)+  , Bazaar'+  , loci   ) where -import Control.Applicative              as Applicative+import Control.Applicative as Applicative import Control.Applicative.Backwards+import Control.Category+import Control.Comonad import Control.Lens.Combinators import Control.Lens.Fold-import Control.Lens.Internal-import Control.Lens.Internal.Combinators+import Control.Lens.Internal.Context+import Control.Lens.Internal.Bazaar+import Control.Lens.Internal.Indexed import Control.Lens.Type-import Control.Monad.State.Class        as State-import Control.Monad.Trans.State.Lazy   as Lazy+import Control.Monad.Trans.State.Lazy+import Data.Functor.Compose+import Data.Int+import Data.IntMap as IntMap+import Data.Map as Map import Data.Traversable-+import Data.Tuple (swap)+import Data.Profunctor+import Data.Profunctor.Rep+import Data.Profunctor.Unsafe+import Prelude hiding ((.),id)  -- $setup -- >>> import Control.Lens+-- >>> import Control.DeepSeq (NFData (..), force)+-- >>> import Control.Exception (evaluate)+-- >>> import Data.Maybe (fromMaybe)+-- >>> import System.Timeout (timeout)+-- >>> let timingOut :: NFData a => a -> IO a; timingOut = fmap (fromMaybe (error "timeout")) . timeout (5*10^6) . evaluate . force  ------------------------------------------------------------------------------ -- Traversals ------------------------------------------------------------------------------ --- | A 'Traversal' can be used directly as a 'Control.Lens.Setter.Setter' or a 'Fold' (but not as a 'Lens') and provides--- the ability to both read and update multiple fields, subject to some relatively weak 'Traversal' laws.------ These have also been known as multilenses, but they have the signature and spirit of+-- | When you see this as an argument to a function, it expects a 'Traversal'.+type ATraversal s t a b = LensLike (Bazaar (->) a b) s t a b++-- | @+-- type 'ATraversal'' = 'Simple' 'ATraversal'+-- @+type ATraversal' s a = ATraversal s s a a++-- | When you see this as an argument to a function, it expects an 'IndexedTraversal'.+type AnIndexedTraversal i s t a b = Over (Indexed i) (Bazaar (Indexed i) a b) s t a b++-- | @+-- type 'AnIndexedTraversal'' = 'Simple' ('AnIndexedTraversal' i)+-- @+type AnIndexedTraversal' i s a = AnIndexedTraversal i s s a a++-- | When you see this as an argument to a function, it expects ----- @'traverse' :: 'Traversable' f => 'Traversal' (f a) (f b) a b@+--  * to be indexed if @p@ is an instance of 'Indexed' i, ----- and the more evocative name suggests their application.+--  * to be unindexed if @p@ is @(->)@, ----- Most of the time the 'Traversal' you will want to use is just 'traverse', but you can also pass any--- 'Lens' or 'Control.Lens.Iso.Iso' as a 'Traversal', and composition of a 'Traversal' (or 'Lens' or 'Control.Lens.Iso.Iso') with a 'Traversal' (or 'Lens' or 'Control.Lens.Iso.Iso')--- using (.) forms a valid 'Traversal'.+--  * a 'Traversal' if @f@ is 'Applicative', ----- The laws for a Traversal @t@ follow from the laws for Traversable as stated in \"The Essence of the Iterator Pattern\".+--  * a 'Getter' if  @f@ is only 'Gettable', ----- @--- t 'pure' ≡ 'pure'--- 'fmap' (t f) '.' t g ≡ 'Data.Functor.Compose.getCompose' '.' t ('Data.Functor.Compose.Compose' '.' 'fmap' f '.' g)--- @+--  * a 'Lens' if @p@ is only a 'Functor', ----- One consequence of this requirement is that a 'Traversal' needs to leave the same number of elements as a--- candidate for subsequent 'Traversal' that it started with. Another testament to the strength of these laws--- is that the caveat expressed in section 5.5 of the \"Essence of the Iterator Pattern\" about exotic--- 'Traversable' instances that 'traverse' the same entry multiple times was actually already ruled out by the--- second law in that same paper!-type Traversal s t a b = forall f. Applicative f => (a -> f b) -> s -> f t+--  * a 'Fold' if 'f' is 'Gettable' and 'Applicative'.+type Traversing p f s t a b = Over p (BazaarT p f a b) s t a b --- | @type SimpleTraversal = 'Simple' 'Traversal'@-type SimpleTraversal s a = Traversal s s a a+-- | @+-- type 'Traversing'' f = 'Simple' ('Traversing' f)+-- @+type Traversing' p f s a = Traversing p f s s a a  -------------------------- -- Traversal Combinators -------------------------- --- |--- Map each element of a structure targeted by a Lens or Traversal,+-- | Map each element of a structure targeted by a 'Lens' or 'Traversal', -- evaluate these actions from left to right, and collect the results. -- -- This function is only provided for consistency, 'id' is strictly more general. ----- @'traverseOf' ≡ 'id'@+-- @+-- 'traverseOf' ≡ 'id'+-- 'itraverseOf' l ≡ 'traverseOf' l '.' 'Indexed'+-- @ --+-- -- This yields the obvious law: ----- @'traverse' ≡ 'traverseOf' 'traverse'@+-- @+-- 'traverse' ≡ 'traverseOf' 'traverse'+-- @ -- -- @--- 'traverseOf' :: 'Control.Lens.Iso.Iso' s t a b       -> (a -> f b) -> s -> f t+-- 'traverseOf' :: 'Iso' s t a b       -> (a -> f b) -> s -> f t -- 'traverseOf' :: 'Lens' s t a b      -> (a -> f b) -> s -> f t -- 'traverseOf' :: 'Traversal' s t a b -> (a -> f b) -> s -> f t -- @-traverseOf :: LensLike f s t a b -> (a -> f b) -> s -> f t+traverseOf :: Over p f s t a b -> p a (f b) -> s -> f t traverseOf = id {-# INLINE traverseOf #-}  -- | A version of 'traverseOf' with the arguments flipped, such that: ----- @'forOf' l ≡ 'flip' ('traverseOf' l)@+-- @+-- 'forOf' l ≡ 'flip' ('traverseOf' l)+-- @ -- -- @ -- 'for' ≡ 'forOf' 'traverse'+-- 'Control.Lens.Indexed.ifor' l s ≡ 'for' l s '.' 'Indexed' -- @ -- -- This function is only provided for consistency, 'flip' is strictly more general.@@ -169,25 +227,24 @@ -- @ -- -- @--- 'forOf' :: 'Control.Lens.Iso.Iso' s t a b -> s -> (a -> f b) -> f t+-- 'forOf' :: 'Iso' s t a b -> s -> (a -> f b) -> f t -- 'forOf' :: 'Lens' s t a b -> s -> (a -> f b) -> f t -- 'forOf' :: 'Traversal' s t a b -> s -> (a -> f b) -> f t -- @-forOf :: LensLike f s t a b -> s -> (a -> f b) -> f t+forOf :: Over p f s t a b -> s -> p a (f b) -> f t forOf = flip {-# INLINE forOf #-} --- |--- Evaluate each action in the structure from left to right, and collect+-- | Evaluate each action in the structure from left to right, and collect -- the results. -- -- @ -- 'sequenceA' ≡ 'sequenceAOf' 'traverse' ≡ 'traverse' 'id'--- 'sequenceAOf' l ≡ 'traverseOf' l id ≡ l id+-- 'sequenceAOf' l ≡ 'traverseOf' l 'id' ≡ l 'id' -- @ -- -- @--- 'sequenceAOf' ::                  'Control.Lens.Iso.Iso' s t (f b) b       -> s -> f t+-- 'sequenceAOf' ::                  'Iso' s t (f b) b       -> s -> f t -- 'sequenceAOf' ::                  'Lens' s t (f b) b      -> s -> f t -- 'sequenceAOf' :: 'Applicative' f => 'Traversal' s t (f b) b -> s -> f t -- @@@ -195,57 +252,64 @@ sequenceAOf l = l id {-# INLINE sequenceAOf #-} --- | Map each element of a structure targeted by a lens to a monadic action,+-- | Map each element of a structure targeted by a 'Lens' to a monadic action, -- evaluate these actions from left to right, and collect the results. ----- @'mapM' ≡ 'mapMOf' 'traverse'@+-- @+-- 'mapM' ≡ 'mapMOf' 'traverse'+-- 'imapMOf' l ≡ 'forM' l '.' 'Indexed'+-- @ -- -- @--- 'mapMOf' ::            'Control.Lens.Iso.Iso' s t a b       -> (a -> m b) -> s -> m t+-- 'mapMOf' ::            'Iso' s t a b       -> (a -> m b) -> s -> m t -- 'mapMOf' ::            'Lens' s t a b      -> (a -> m b) -> s -> m t -- 'mapMOf' :: 'Monad' m => 'Traversal' 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 l cmd = unwrapMonad# (l (wrapMonad# cmd))+mapMOf :: Profunctor p => Over p (WrappedMonad m) s t a b -> p a (m b) -> s -> m t+mapMOf l cmd = unwrapMonad #. l (WrapMonad #. cmd) {-# INLINE mapMOf #-}  -- | 'forMOf' is a flipped version of 'mapMOf', consistent with the definition of 'forM'.+-- -- @ -- 'forM' ≡ 'forMOf' 'traverse' -- 'forMOf' l ≡ 'flip' ('mapMOf' l)+-- 'iforMOf' l s ≡ 'forM' l s '.' 'Indexed' -- @ -- -- @--- 'forMOf' ::            'Control.Lens.Iso.Iso' s t a b       -> s -> (a -> m b) -> m t+-- 'forMOf' ::            'Iso' s t a b       -> s -> (a -> m b) -> m t -- 'forMOf' ::            'Lens' s t a b      -> s -> (a -> m b) -> m t -- 'forMOf' :: 'Monad' m => 'Traversal' 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 l a cmd = unwrapMonad (l (wrapMonad# cmd) a)+forMOf :: Profunctor p => Over p (WrappedMonad m) s t a b -> s -> p a (m b) -> m t+forMOf l a cmd = unwrapMonad (l (WrapMonad #. cmd) a) {-# INLINE forMOf #-} --- | Sequence the (monadic) effects targeted by a lens in a container from left to right.+-- | Sequence the (monadic) effects targeted by a 'Lens' in a container from left to right. -- -- @ -- 'sequence' ≡ 'sequenceOf' 'traverse'--- 'sequenceOf' l ≡ 'mapMOf' l id--- 'sequenceOf' l ≡ 'unwrapMonad' . l 'WrapMonad'+-- 'sequenceOf' l ≡ 'mapMOf' l 'id'+-- 'sequenceOf' l ≡ 'unwrapMonad' '.' l 'WrapMonad' -- @ -- -- @--- 'sequenceOf' ::            'Control.Lens.Iso.Iso' s t (m b) b       -> s -> m t+-- 'sequenceOf' ::            'Iso' s t (m b) b       -> s -> m t -- 'sequenceOf' ::            'Lens' s t (m b) b      -> s -> m t -- 'sequenceOf' :: 'Monad' m => 'Traversal' s t (m b) b -> s -> m t -- @ sequenceOf :: LensLike (WrappedMonad m) s t (m b) b -> s -> m t-sequenceOf l = unwrapMonad# (l WrapMonad)+sequenceOf l = unwrapMonad #. l WrapMonad {-# INLINE sequenceOf #-}  -- | This generalizes 'Data.List.transpose' to an arbitrary 'Traversal'. -- -- Note: 'Data.List.transpose' handles ragged inputs more intelligently, but for non-ragged inputs: ----- @'Data.List.transpose' ≡ 'transposeOf' 'traverse'@+-- @+-- 'Data.List.transpose' ≡ 'transposeOf' 'traverse'+-- @ -- -- >>> transposeOf traverse [[1,2,3],[4,5,6]] -- [[1,4],[2,5],[3,6]]@@ -253,59 +317,71 @@ -- Since every 'Lens' is a 'Traversal', we can use this as a form of -- monadic strength as well: ----- @'transposeOf' '_2' :: (b, [a]) -> [(b, a)]@+-- @+-- 'transposeOf' 'Control.Lens.Tuple._2' :: (b, [a]) -> [(b, a)]+-- @ transposeOf :: LensLike ZipList s t [a] a -> s -> [t]-transposeOf l = getZipList# (l ZipList)+transposeOf l = getZipList #. l ZipList {-# INLINE transposeOf #-}  -- | This generalizes 'Data.Traversable.mapAccumR' to an arbitrary 'Traversal'. ----- @'mapAccumR' ≡ 'mapAccumROf' 'traverse'@+-- @+-- 'mapAccumR' ≡ 'mapAccumROf' 'traverse'+-- @ ----- 'mapAccumROf' accumulates state from right to left.+-- 'mapAccumROf' accumulates 'State' from right to left. -- -- @--- 'mapAccumROf' :: 'Control.Lens.Iso.Iso' s t a b       -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)+-- 'mapAccumROf' :: 'Iso' s t a b       -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t) -- 'mapAccumROf' :: 'Lens' s t a b      -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t) -- 'mapAccumROf' :: 'Traversal' s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t) -- @-mapAccumROf :: LensLike (Backwards (Lazy.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 :: Conjoined p => Over p (Backwards (State acc)) s t a b -> p acc (a -> (acc, b)) -> acc -> s -> (acc, t) mapAccumROf = mapAccumLOf . backwards {-# INLINE mapAccumROf #-}  -- | This generalizes 'Data.Traversable.mapAccumL' to an arbitrary 'Traversal'. ----- @'mapAccumL' ≡ 'mapAccumLOf' 'traverse'@+-- @+-- 'mapAccumL' ≡ 'mapAccumLOf' 'traverse'+-- @ ----- 'mapAccumLOf' accumulates state from left to right.+-- 'mapAccumLOf' accumulates 'State' from left to right. -- -- @--- 'mapAccumLOf' :: 'Control.Lens.Iso.Iso' s t a b       -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)+-- 'mapAccumLOf' :: 'Iso' s t a b       -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t) -- 'mapAccumLOf' :: 'Lens' s t a b      -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t) -- 'mapAccumLOf' :: 'Traversal' s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t) -- @-mapAccumLOf :: LensLike (Lazy.State acc) s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)-#if MIN_VERSION_mtl(2,1,1)-mapAccumLOf l f acc0 s = swap (Lazy.runState (l (\a -> State.state (\acc -> swap (f acc a))) s) acc0)-#else-mapAccumLOf l f acc0 s = swap (Lazy.runState (l (\a -> do (r,s') <- State.gets (\acc -> swap (f acc a)); State.put s'; return r) s) acc0)-#endif+--+-- @+-- 'mapAccumLOf' :: 'LensLike' ('State' acc) s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)+-- 'mapAccumLOf' l f acc0 s = 'swap' ('runState' (l (\a -> 'state' (\acc -> 'swap' (f acc a))) s) acc0)+-- @+--+mapAccumLOf :: Conjoined p => Over p (State acc) s t a b -> p acc (a -> (acc, b)) -> acc -> s -> (acc, t)+mapAccumLOf l f acc0 s = swap (runState (l g s) acc0) where+   g = cotabulate $ \wa -> state $ \acc -> swap (corep f (acc <$ wa) (extract wa))+-- This would be much cleaner if the argument order for the function was swapped. {-# INLINE mapAccumLOf #-} -swap :: (a,b) -> (b,a)-swap (a,b) = (b,a)-{-# INLINE swap #-}- -- | This permits the use of 'scanr1' over an arbitrary 'Traversal' or 'Lens'. ----- @'scanr1' ≡ 'scanr1Of' 'traverse'@+-- @+-- 'scanr1' ≡ 'scanr1Of' 'traverse'+-- @ -- -- @--- 'scanr1Of' :: 'Control.Lens.Iso.Iso' s t a a       -> (a -> a -> a) -> s -> t+-- 'scanr1Of' :: 'Iso' s t a a       -> (a -> a -> a) -> s -> t -- 'scanr1Of' :: 'Lens' s t a a      -> (a -> a -> a) -> s -> t -- 'scanr1Of' :: 'Traversal' s t a a -> (a -> a -> a) -> s -> t -- @-scanr1Of :: LensLike (Backwards (Lazy.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 l f = snd . mapAccumROf l step Nothing where   step Nothing a  = (Just a, a)   step (Just s) a = (Just r, r) where r = f a s@@ -313,59 +389,74 @@  -- | This permits the use of 'scanl1' over an arbitrary 'Traversal' or 'Lens'. ----- @'scanl1' ≡ 'scanl1Of' 'traverse'@+-- @+-- 'scanl1' ≡ 'scanl1Of' 'traverse'+-- @ -- -- @--- 'scanr1Of' :: 'Control.Lens.Iso.Iso' s t a a       -> (a -> a -> a) -> s -> t--- 'scanr1Of' :: 'Lens' s t a a      -> (a -> a -> a) -> s -> t--- 'scanr1Of' :: 'Traversal' s t a a -> (a -> a -> a) -> s -> t+-- 'scanl1Of' :: 'Iso' s t a a       -> (a -> a -> a) -> s -> t+-- 'scanl1Of' :: 'Lens' s t a a      -> (a -> a -> a) -> s -> t+-- 'scanl1Of' :: 'Traversal' s t a a -> (a -> a -> a) -> s -> t -- @-scanl1Of :: LensLike (Lazy.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 l f = snd . mapAccumLOf l step Nothing where   step Nothing a  = (Just a, a)   step (Just s) a = (Just r, r) where r = f s a {-# INLINE scanl1Of #-}  -- | This 'Traversal' allows you to 'traverse' the individual stores in a 'Bazaar'.-loci :: Traversal (Bazaar a c s) (Bazaar b c s) a b-loci f w = traverse f (ins w) <&> \xs -> Bazaar $ \g -> traverse g xs <&> unsafeOuts w--+loci :: Traversal (Bazaar (->) a c s) (Bazaar (->) b c s) a b+loci f w = getCompose (runBazaar w (Compose #. fmap sell . f))+{-# INLINE loci #-}  ------------------------------------------------------------------------------- -- Parts and Holes ------------------------------------------------------------------------------- --- | 'partsOf' turns a 'Traversal' into a 'Lens' that resembles an early version of the @uniplate@ (or @biplate@) type.+-- | 'partsOf' turns a 'Traversal' into a 'Lens' that resembles an early version of the 'Data.Data.Lens.uniplate' (or 'Data.Data.Lens.biplate') type. -- -- /Note:/ You should really try to maintain the invariant of the number of children in the list. -- -- Any extras will be lost. If you do not supply enough, then the remainder will come from the original structure. ----- So technically, this is only a lens if you do not change the number of results it returns.+-- So technically, this is only a 'Lens' if you do not change the number of results it returns. ----- When applied to a 'Fold' the result is merely a 'Control.Lens.Getter.Getter'.+-- When applied to a 'Fold' the result is merely a 'Getter'. -- -- @--- 'partsOf' :: 'Simple' 'Control.Lens.Iso.Iso' s a       -> 'Simple' 'Lens' s [a]--- 'partsOf' :: 'Simple' 'Lens' s a      -> 'Simple' 'Lens' s [a]--- 'partsOf' :: 'Simple' 'Traversal' s a -> 'Simple' 'Lens' s [a]--- 'partsOf' :: 'Fold' s a             -> 'Control.Lens.Getter.Getter' s [a]--- 'partsOf' :: 'Control.Lens.Getter.Getter' s a           -> 'Control.Lens.Getter.Getter' s [a]+-- 'partsOf' :: 'Iso'' s a       -> 'Lens'' s [a]+-- 'partsOf' :: 'Lens'' s a      -> 'Lens'' s [a]+-- 'partsOf' :: 'Traversal'' s a -> 'Lens'' s [a]+-- 'partsOf' :: 'Fold' s a       -> 'Getter' s [a]+-- 'partsOf' :: 'Getter' s a     -> 'Getter' s [a] -- @-partsOf :: Functor f => LensLike (BazaarT a a f) s t a a -> LensLike f s t [a] [a]-partsOf l f s = outsT b <$> f (insT b) where b = l sellT s+partsOf :: Functor f => Traversing (->) f s t a a -> LensLike f s t [a] [a]+partsOf l f s = outs b <$> f (ins b) where b = l sell s {-# INLINE partsOf #-} +-- | An indexed version of 'partsOf' that receives the entire list of indices as its index.+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 l f s = outs b <$> indexed f (is :: [i]) as where+  (is,as) = unzip (pins b)+  b = l sell s+{-# INLINE ipartsOf #-}+ -- | A type-restricted version of 'partsOf' that can only be used with a 'Traversal'.-partsOf' :: LensLike (Bazaar a a) s t a a -> Lens s t [a] [a]+partsOf' :: ATraversal s t a a -> Lens s t [a] [a] partsOf' l f s = outs b <$> f (ins b) where b = l sell s {-# INLINE partsOf' #-} --- | 'unsafePartsOf' turns a 'Traversal' into a @uniplate@ (or @biplate@) family.+-- | A type-restricted version of 'ipartsOf' that can only be used with an 'IndexedTraversal'.+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' l f s = outs b <$> indexed f (is :: [i]) as where+  (is,as) = unzip (pins b)+  b = l sell s+{-# INLINE ipartsOf' #-}++-- | 'unsafePartsOf' turns a 'Traversal' into a 'Data.Data.Lens.uniplate' (or 'Data.Data.Lens.biplate') family. -- -- If you do not need the types of @s@ and @t@ to be different, it is recommended that--- you use 'partsOf'+-- you use 'partsOf'. -- -- It is generally safer to traverse with the 'Bazaar' rather than use this -- combinator. However, it is sometimes convenient.@@ -373,124 +464,132 @@ -- This is unsafe because if you don't supply at least as many @b@'s as you were -- given @a@'s, then the reconstruction of @t@ /will/ result in an error! ----- When applied to a 'Fold' the result is merely a 'Control.Lens.Getter.Getter' (and becomes safe).+-- When applied to a 'Fold' the result is merely a 'Getter' (and becomes safe). -- -- @--- 'unsafePartsOf' :: 'Control.Lens.Iso.Iso' s t a b       -> 'Lens' s t [a] [b]+-- 'unsafePartsOf' :: 'Iso' s t a b       -> 'Lens' s t [a] [b] -- 'unsafePartsOf' :: 'Lens' s t a b      -> 'Lens' s t [a] [b] -- 'unsafePartsOf' :: 'Traversal' s t a b -> 'Lens' s t [a] [b]--- 'unsafePartsOf' :: 'Fold' s a          -> 'Control.Lens.Getter.Getter' s [a]--- 'unsafePartsOf' :: 'Control.Lens.Getter.Getter' s a        -> 'Control.Lens.Getter.Getter' s [a]+-- 'unsafePartsOf' :: 'Fold' s a          -> 'Getter' s [a]+-- 'unsafePartsOf' :: 'Getter' s a        -> 'Getter' s [a] -- @-unsafePartsOf :: Functor f => LensLike (BazaarT a b f) s t a b -> LensLike f s t [a] [b]-unsafePartsOf l f s = unsafeOutsT b <$> f (insT b) where b = l sellT s+unsafePartsOf :: Functor f => Traversing (->) f s t a b -> LensLike f s t [a] [b]+unsafePartsOf l f s = unsafeOuts b <$> f (ins b) where b = l sell s {-# INLINE unsafePartsOf #-} -unsafePartsOf' :: LensLike (Bazaar a b) s t a b -> Lens s t [a] [b]+-- | An indexed version of 'unsafePartsOf' that receives the entire list of indices as its index.+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 l f s = unsafeOuts b <$> indexed f (is :: [i]) as where+  (is,as) = unzip (pins b)+  b = l sell s+{-# INLINE iunsafePartsOf #-}++unsafePartsOf' :: ATraversal s t a b -> Lens s t [a] [b] unsafePartsOf' l f s = unsafeOuts b <$> f (ins b) where b = l sell s {-# INLINE unsafePartsOf' #-} --- | The one-level version of 'contextsOf'. This extracts a list of the immediate children according to a given 'Traversal' as editable contexts.+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' l f s = unsafeOuts b <$> indexed f (is :: [i]) as where+  (is,as) = unzip (pins b)+  b = l sell s+{-# INLINE iunsafePartsOf' #-}++-- | The one-level version of 'Control.Lens.Plated.contextsOf'. This extracts a list of the immediate children according to a given 'Traversal' as editable contexts. ----- Given a context you can use 'pos' to see the values, 'peek' at what the structure would be like with an edited result, or simply 'extract' the original structure.+-- Given a context you can use 'Control.Comonad.Store.Class.pos' to see the values, 'Control.Comonad.Store.Class.peek' at what the structure would be like with an edited result, or simply 'extract' the original structure. -- -- @--- propChildren l x = 'childrenOf' l x '==' 'map' 'pos' ('holesOf' l x)--- propId l x = 'all' ('==' x) [extract w | w <- 'holesOf' l x]+-- propChildren l x = childrenOf l x '==' 'map' 'Control.Comonad.Store.Class.pos' ('holesOf' l x)+-- propId l x = 'all' ('==' x) ['extract' w | w <- 'holesOf' l x] -- @ -- -- @--- 'holesOf' :: 'Simple' 'Iso' s a       -> s -> ['Context' a a s]--- 'holesOf' :: 'Simple' 'Lens' s a      -> s -> ['Context' a a s]--- 'holesOf' :: 'Simple' 'Traversal' s a -> s -> ['Context' a a s]+-- 'holesOf' :: 'Iso'' s a                -> s -> ['Pretext'' (->) a s]+-- 'holesOf' :: 'Lens'' s a               -> s -> ['Pretext'' (->) a s]+-- 'holesOf' :: 'Traversal'' s a          -> s -> ['Pretext'' (->) a s]+-- 'holesOf' :: 'IndexedLens'' i s a      -> s -> ['Pretext'' ('Indexed' i) a s]+-- 'holesOf' :: 'IndexedTraversal'' i s a -> s -> ['Pretext'' ('Indexed' i) a s] -- @-holesOf :: LensLike (Bazaar a a) s t a a -> s -> [Context a a t]-holesOf l a = f (ins b) (outs b) where-  b = l sell a-  f []     _ = []-  f (x:xs) g = Context (g . (:xs)) x : f xs (g . (x:))+holesOf :: Conjoined p => Over p (Bazaar p a a) s t a a -> s -> [Pretext p a a t]+holesOf l s = f (pins b) (unsafeOuts b) where+  b = l sell s+  f [] _ = []+  f (wx:xs) g = Pretext (\wxfy -> g . (:Prelude.map extract xs) <$> corep wxfy wx) : f xs (g . (extract wx:)) {-# INLINE holesOf #-}  -- | This converts a 'Traversal' that you \"know\" will target one or more elements to a 'Lens'. It can--- also be used to transform a non-empty 'Fold' into a 'Control.Lens.Getter.Getter' or a non-empty 'Control.Lens.Action.MonadicFold' into an--- 'Control.Lens.Action.Action'.+-- also be used to transform a non-empty 'Fold' into a 'Getter' or a non-empty 'MonadicFold' into an+-- 'Action'. ----- The resulting 'Lens', 'Control.Lens.Getter.Getter', or 'Control.Lens.Action.Action' will be partial if the supplied traversal returns+-- The resulting 'Lens', 'Getter', or 'Action' will be partial if the supplied 'Traversal' returns -- no results. -- -- @--- 'singular' :: 'Traversal' s t a a -> 'Lens' s t a a--- 'singular' :: 'Fold' s a          -> 'Control.Lens.Getter.Getter' s a--- 'singular' :: 'Control.Lens.Action.MonadicFold' m s a -> 'Control.Lens.Action.Action' m s a+-- 'singular' :: 'Traversal' s t a a          -> 'Lens' s t a a+-- 'singular' :: 'Fold' s a                   -> 'Getter' s a+-- 'singular' :: 'MonadicFold' m s a          -> 'Action' m s a+-- 'singular' :: 'IndexedTraversal' i s t a a -> 'IndexedLens' i s t a a+-- 'singular' :: 'IndexedFold' i s a          -> 'IndexedGetter' i s a+-- 'singular' :: 'IndexedMonadicFold' i m s a -> 'IndexedAction' i m s a -- @-singular :: Functor f => LensLike (BazaarT a a f) s t a a -> LensLike f s t a a-singular l f = partsOf l $ \xs -> case xs of-  (a:as) -> (:as) <$> f a-  []     -> [] <$ f (error "singular: empty traversal")+singular :: (Conjoined p, Functor f)+         => Over p (BazaarT p f a a) s t a a+         -> Over p f s t a a+singular l pafb s = case pins b of+  (w:ws) -> unsafeOuts b . (:Prelude.map extract ws) <$> corep pafb w+  []     -> unsafeOuts b . return                    <$> corep pafb (error "singular: empty traversal")+  where b = l sell s+{-# INLINE singular #-}  -- | This converts a 'Traversal' that you \"know\" will target only one element to a 'Lens'. It can also be--- used to transform a 'Fold' into a 'Control.Lens.Getter.Getter' or a 'Control.Lens.Action.MonadicFold' into an 'Control.Lens.Action.Action'.+-- used to transform a 'Fold' into a 'Getter' or a 'MonadicFold' into an 'Action'. ----- The resulting 'Lens', 'Control.Lens.Getter.Getter', or 'Control.Lens.Action.Action' will be partial if the Traversal targets nothing+-- The resulting 'Lens', 'Getter', or 'Action' will be partial if the 'Traversal' targets nothing -- or more than one element. -- -- @--- 'unsafeSingular' :: 'Traversal' s t a b -> 'Lens' s t a b--- 'unsafeSingular' :: 'Fold' s a          -> 'Control.Lens.Getter.Getter' s a--- 'unsafeSingular' :: 'Control.Lens.Action.MonadicFold' m s a -> 'Control.Lens.Action.Action' m s a+-- 'unsafeSingular' :: 'Traversal' s t a b          -> 'Lens' s t a b+-- 'unsafeSingular' :: 'Fold' s a                   -> 'Getter' s a+-- 'unsafeSingular' :: 'MonadicFold' m s a          -> 'Action' m s a+-- 'unsafeSingular' :: 'IndexedTraversal' i s t a b -> 'IndexedLens' i s t a b+-- 'unsafeSingular' :: 'IndexedFold' i s a          -> 'IndexedGetter' i s a+-- 'unsafeSingular' :: 'IndexedMonadicFold' i m s a -> 'IndexedAction' i m s a -- @-unsafeSingular :: Functor f => LensLike (BazaarT a b f) s t a b -> LensLike f s t a b-unsafeSingular l f = unsafePartsOf l $ \xs -> case xs of-  [a] -> return <$> f a+unsafeSingular :: (Conjoined p, Functor f)+               => Over p (BazaarT p f a b) s t a b+               -> Over p f s t a b+unsafeSingular l pafb s = case pins b of+  [w] -> unsafeOuts b . return <$> corep pafb w   []  -> error "unsafeSingular: empty traversal"   _   -> error "unsafeSingular: traversing multiple results"+  where b = l sell s+{-# INLINE unsafeSingular #-}  ------------------------------------------------------------------------------ -- Internal functions used by 'partsOf', 'holesOf', etc. -------------------------------------------------------------------------------ins :: Bazaar a b t -> [a]++ins :: Bizarre (->) w => w a b t -> [a] ins = toListOf bazaar {-# INLINE ins #-} -outs :: Bazaar a a t -> [a] -> t-#if MIN_VERSION_mtl(2,1,1)-outs = evalState . bazaar (\oldVal -> State.state (unconsWithDefault oldVal))-#else-outs = evalState . bazaar (\oldVal -> do (r,s) <- State.gets (unconsWithDefault oldVal); State.put s; return r)-#endif-{-# INLINE outs #-}+pins :: (Bizarre p w, Corepresentable p) => w a b t -> [Corep p a]+pins = getConst #. bazaar (cotabulate $ \ra -> Const [ra])+{-# INLINE pins #-} +parr :: (Profunctor p, Category p) => (a -> b) -> p a b+parr f = lmap f id+{-# INLINE parr #-} -unsafeOuts :: Bazaar a b t -> [b] -> t-#if MIN_VERSION_mtl(2,1,1)-unsafeOuts = evalState . bazaar (\_ -> State.state (unconsWithDefault fakeVal))-#else-unsafeOuts = evalState . bazaar (\_-> do (r,s) <- State.gets (unconsWithDefault fakeVal); State.put s; return r)-#endif+outs :: (Bizarre p w, Category p) => w a a t -> [a] -> t+outs = evalState `rmap` bazaar (parr (state . unconsWithDefault))+{-# INLINE outs #-}++unsafeOuts :: (Bizarre p w, Corepresentable p) => w a b t -> [b] -> t+unsafeOuts = evalState `rmap` bazaar (cotabulate (\_ -> state (unconsWithDefault fakeVal)))   where fakeVal = error "unsafePartsOf': not enough elements were supplied" {-# INLINE unsafeOuts #-} -insT :: BazaarT a b f t -> [a]-insT = toListOf bazaarT-{-# INLINE insT #-}--outsT :: BazaarT a a f t -> [a] -> t-#if MIN_VERSION_mtl(2,1,1)-outsT = evalState . bazaarT (\oldVal -> State.state (unconsWithDefault oldVal))-#else-outsT = evalState . bazaarT (\oldVal -> do (r,s) <- State.gets (unconsWithDefault oldVal); State.put s; return r)-#endif-{-# INLINE outsT #-}--unsafeOutsT :: BazaarT a b f t -> [b] -> t-#if MIN_VERSION_mtl(2,1,1)-unsafeOutsT = evalState . bazaarT (\_ -> State.state (unconsWithDefault fakeVal))-#else-unsafeOutsT = evalState . bazaarT (\_-> do (r,s) <- State.gets (unconsWithDefault fakeVal); State.put s; return r)-#endif-  where fakeVal = error "unsafePartsOf: not enough elements were supplied"-{-# INLINE unsafeOutsT #-}- unconsWithDefault :: a -> [a] -> (a,[a]) unconsWithDefault d []     = (d,[]) unconsWithDefault _ (x:xs) = (x,xs)@@ -514,40 +613,107 @@ both f ~(a,a') = (,) <$> f a <*> f a' {-# INLINE both #-} --- | Apply a different 'Traversal' or 'Control.Lens.Fold.Fold' to each side of a tuple.+-- | Apply a different 'Traversal' or 'Fold' to each side of a tuple. --+-- @+-- 'beside' :: 'Traversal' s t a b                -> 'Traversal' s' t' a b                -> 'Traversal' (s,s') (t,t') a b+-- 'beside' :: 'Lens' s t a b                     -> 'Lens' s' t' a b                     -> 'Traversal' (s,s') (t,t') a b+-- 'beside' :: 'Fold' s a                         -> 'Fold' s' a                          -> 'Fold' (s,s') a+-- 'beside' :: 'Getter' s a                       -> 'Getter' s' a                        -> 'Traversal' (s,s') a+-- 'beside' :: 'Action' m s a                     -> 'Action' m s' a                      -> 'MonadicFold' m (s,s') a+-- 'beside' :: 'MonadicFold' m s a                -> 'MonadicFold' m s' a                 -> 'MonadicFold' m (s,s') a+-- @+--+-- @+-- 'beside' :: 'IndexedTraversal' i s t a b       -> 'IndexedTraversal' i s' t' a b       -> 'IndexedTraversal' i (s,s') (t,t') a b+-- 'beside' :: 'IndexedLens' i s t a b            -> 'IndexedLens' i s' t' a b            -> 'IndexedTraversal' i (s,s') (t,t') a b+-- 'beside' :: 'IndexedFold' i s a                -> 'IndexedFold' i s' a                 -> 'IndexedFold' i (s,s') a+-- 'beside' :: 'IndexedGetter' i s a              -> 'IndexedGetter' i s' a               -> 'IndexedTraversal' i (s,s') a+-- 'beside' :: 'IndexedAction' i m s a            -> 'IndexedAction' i m s' a             -> 'IndexedMonadicFold' i m (s,s') a+-- 'beside' :: 'IndexedMonadicFold' i m s a       -> 'IndexedMonadicFold' i m s' a        -> 'IndexedMonadicFold' i m (s,s') a+-- @+--+-- @+-- 'beside' :: 'IndexPreservingTraversal' s t a b -> 'IndexPreservingTraversal' s' t' a b -> 'IndexPreservingTraversal' (s,s') (t,t') a b+-- 'beside' :: 'IndexPreservingLens' s t a b      -> 'IndexPreservingLens' s' t' a b      -> 'IndexPreservingTraversal' (s,s') (t,t') a b+-- 'beside' :: 'IndexPreservingFold' s a          -> 'IndexPreservingFold' s' a           -> 'IndexPreservingFold' (s,s') a+-- 'beside' :: 'IndexPreservingGetter' s a        -> 'IndexPreservingGetter' s' a         -> 'IndexPreservingTraversal' (s,s') a+-- 'beside' :: 'IndexPreservingAction' m s a      -> 'IndexPreservingAction' m s' a       -> 'IndexPreservingMonadicFold' m (s,s') a+-- 'beside' :: 'IndexPreservingMonadicFold' m s a -> 'IndexPreservingMonadicFold' m s' a  -> 'IndexPreservingMonadicFold' m (s,s') a+-- @+-- -- >>> ("hello",["world","!!!"])^..beside id traverse -- ["hello","world","!!!"]-beside :: Applicative f => LensLike f s t a b -> LensLike f s' t' a b -> LensLike f (s,s') (t,t') a b-beside l r f ~(s,s') = (,) <$> l f s <*> r f s'+beside :: (Representable q, Applicative (Rep q), Applicative f)+       => Overloading p q f s t a b+       -> Overloading p q f s' t' a b+       -> Overloading p q f (s,s') (t,t') a b+beside l r f = tabulate $ \ ~(s,s') -> liftA2 (,) <$> rep (l f) s <*> rep (r f) s' {-# INLINE beside #-} --- | Visit the first /n/ targets of a 'Traversal', 'Fold', 'Control.Lens.Getter.Getter' or 'Lens'.+-- | Visit the first /n/ targets of a 'Traversal', 'Fold', 'Getter' or 'Lens'. -- -- >>> [("hello","world"),("!!!","!!!")]^.. taking 2 (traverse.both) -- ["hello","world"] ----- >>> [1..] ^.. taking 3 traverse+-- >>> timingOut $ [1..] ^.. taking 3 traverse -- [1,2,3] -- -- >>> over (taking 5 traverse) succ "hello world" -- "ifmmp world"-taking :: Applicative f => Int -> SimpleLensLike (BazaarT a a f) s a -> SimpleLensLike f s a-taking n l f s = outsT b <$> traverse f (take n $ insT b) where b = l sellT s+--+-- @+-- 'taking' :: 'Int' -> 'Traversal'' s a                   -> 'Traversal'' s a+-- 'taking' :: 'Int' -> 'Lens'' s a                        -> 'Traversal'' s a+-- 'taking' :: 'Int' -> 'Iso'' s a                         -> 'Traversal'' s a+-- 'taking' :: 'Int' -> 'Prism'' s a                       -> 'Traversal'' s a+-- 'taking' :: 'Int' -> 'Getter' s a                       -> 'Fold' s a+-- 'taking' :: 'Int' -> 'Fold' s a                         -> 'Fold' s a+-- 'taking' :: 'Int' -> 'Action' m s a                     -> 'MonadicFold' m s a+-- 'taking' :: 'Int' -> 'MonadicFold' m s a                -> 'MonadicFold' m s a+-- 'taking' :: 'Int' -> 'IndexedTraversal'' i s a          -> 'IndexedTraversal'' i s a+-- 'taking' :: 'Int' -> 'IndexedLens'' i s a               -> 'IndexedTraversal'' i s a+-- 'taking' :: 'Int' -> 'IndexedGetter' i s a              -> 'IndexedFold' i s a+-- 'taking' :: 'Int' -> 'IndexedFold' i s a                -> 'IndexedFold' i s a+-- 'taking' :: 'Int' -> 'IndexedAction' i m s a            -> 'IndexedMonadicFold' i m s a+-- 'taking' :: 'Int' -> 'IndexedMonadicFold' i m s a       -> 'IndexedMonadicFold' i m s a+-- @+taking :: (Conjoined p, Applicative f)+        => Int+       -> Over p (BazaarT p f a a) s t a a+       -> Over p f s t a a+taking n l pafb s = outs b <$> traverse (corep pafb) (take n $ pins b) where b = l sell s {-# INLINE taking #-} --- | Visit all but the first /n/ targets of a 'Traversal', 'Fold', 'Control.Lens.Getter.Getter' or 'Lens'.+-- | Visit all but the first /n/ targets of a 'Traversal', 'Fold', 'Getter' or 'Lens'. -- -- >>> ("hello","world") ^? dropping 1 both -- Just "world" -- -- Dropping works on infinite traversals as well: ----- >>> [1..]^? dropping 1 folded+-- >>> [1..] ^? dropping 1 folded -- Just 2-dropping :: Applicative f => Int -> SimpleLensLike (Indexing f) s a -> SimpleLensLike f s a-dropping n l f s = case runIndexing (l (\a -> Indexing $ \i -> i `seq` (if i >= n then f a else pure a, i + 1)) s) 0 of-  (r, _) -> r+--+-- @+-- 'dropping' :: 'Int' -> 'Traversal'' s a                   -> 'Traversal'' s a+-- 'dropping' :: 'Int' -> 'Lens'' s a                        -> 'Traversal'' s a+-- 'dropping' :: 'Int' -> 'Iso'' s a                         -> 'Traversal'' s a+-- 'dropping' :: 'Int' -> 'Prism'' s a                       -> 'Traversal'' s a+-- 'dropping' :: 'Int' -> 'Getter' s a                       -> 'Fold' s a+-- 'dropping' :: 'Int' -> 'Fold' s a                         -> 'Fold' s a+-- 'dropping' :: 'Int' -> 'Action' m s a                     -> 'MonadicFold' m s a+-- 'dropping' :: 'Int' -> 'MonadicFold' m s a                -> 'MonadicFold' m s a+-- 'dropping' :: 'Int' -> 'IndexedTraversal'' i s a          -> 'IndexedTraversal'' i s a+-- 'dropping' :: 'Int' -> 'IndexedLens'' i s a               -> 'IndexedTraversal'' i s a+-- 'dropping' :: 'Int' -> 'IndexedGetter' i s a              -> 'IndexedFold' i s a+-- 'dropping' :: 'Int' -> 'IndexedFold' i s a                -> 'IndexedFold' i s a+-- 'dropping' :: 'Int' -> 'IndexedAction' i m s a            -> 'IndexedMonadicFold' i m s a+-- 'dropping' :: 'Int' -> 'IndexedMonadicFold' i m s a       -> 'IndexedMonadicFold' i m s a+-- @+dropping :: (Conjoined p, Applicative f) => Int -> Over p (Indexing f) s t a a -> Over p f s t a a+dropping n l pafb s = snd $ runIndexing (l paifb s) 0 where+  paifb = cotabulate $ \wa -> Indexing $ \i -> let i' = i + 1 in i' `seq` (i', if i < n then pure (extract wa) else corep pafb wa) {-# INLINE dropping #-}  ------------------------------------------------------------------------------@@ -557,28 +723,265 @@ -- | A 'Traversal' is completely characterized by its behavior on a 'Bazaar'. -- -- Cloning a 'Traversal' is one way to make sure you aren't given--- something weaker, such as a 'Control.Lens.Traversal.Fold' and can be+-- something weaker, such as a 'Fold' and can be -- used as a way to pass around traversals that have to be monomorphic in @f@. -- -- Note: This only accepts a proper 'Traversal' (or 'Lens'). To clone a 'Lens'--- as such, use 'cloneLens'+-- as such, use 'Control.Lens.Lens.cloneLens'. ----- Note: It is usually better to 'ReifyTraversal' and use 'reflectTraversal'--- than to 'cloneTraversal'. The former can execute at full speed, while the--- latter needs to round trip through the 'Bazaar'.+-- Note: It is usually better to use 'Control.Lens.Reified.ReifiedTraversal' and+-- 'Control.Lens.Reified.reflectTraversal' than to 'cloneTraversal'. The+-- former can execute at full speed, while the latter needs to round trip through+-- the 'Bazaar'. -- -- >>> let foo l a = (view (cloneTraversal l) a, set (cloneTraversal l) 10 a) -- >>> foo both ("hello","world") -- ("helloworld",(10,10)) ----- @'cloneTraversal' :: 'LensLike' ('Bazaar' a b) s t a b -> 'Traversal' s t a b@-cloneTraversal :: Applicative f => ((a -> Bazaar a b b) -> s -> Bazaar a b t) -> (a -> f b) -> s -> f t+-- @+-- 'cloneTraversal' :: 'LensLike' ('Bazaar' a b) s t a b -> 'Traversal' s t a b+-- @+cloneTraversal :: ATraversal s t a b -> Traversal s t a b cloneTraversal l f = bazaar f . l sell {-# INLINE cloneTraversal #-} --- | A form of 'Traversal' that can be stored monomorphically in a container.-data ReifiedTraversal s t a b = ReifyTraversal { reflectTraversal :: Traversal s t a b }+-- | Clone a 'Traversal' yielding an 'IndexPreservingTraversal' that passes through+-- whatever index it is composed with.+cloneIndexPreservingTraversal :: ATraversal s t a b -> IndexPreservingTraversal s t a b+cloneIndexPreservingTraversal l pafb = cotabulate $ \ws -> runBazaar (l sell (extract ws)) $ \a -> corep pafb (a <$ ws)+{-# INLINE cloneIndexPreservingTraversal #-} --- | @type SimpleReifiedTraversal = 'Simple' 'ReifiedTraversal'@-type SimpleReifiedTraversal s a = ReifiedTraversal s s a a+-- | Clone an 'IndexedTraversal' yielding an 'IndexedTraversal' with the same index.+cloneIndexedTraversal :: AnIndexedTraversal i s t a b -> IndexedTraversal i s t a b+cloneIndexedTraversal l f = bazaar (Indexed (indexed f)) . l sell+{-# INLINE cloneIndexedTraversal #-} +------------------------------------------------------------------------------+-- Indexed Traversals+------------------------------------------------------------------------------++-- | Traversal with an index.+--+-- /NB:/ When you don't need access to the index then you can just apply your 'IndexedTraversal'+-- directly as a function!+--+-- @+-- 'itraverseOf' ≡ 'Control.Lens.Indexed.withIndex'+-- 'Control.Lens.Traversal.traverseOf' l = 'itraverseOf' l '.' 'const' = 'id'+-- @+--+-- @+-- 'itraverseOf' :: 'IndexedLens' i s t a b      -> (i -> a -> f b) -> s -> f t+-- 'itraverseOf' :: 'IndexedTraversal' i s t a b -> (i -> a -> f b) -> s -> f t+-- @+itraverseOf :: (Indexed i a (f b) -> s -> f t) -> (i -> a -> f b) -> s -> f t+itraverseOf l = l .# Indexed+{-# INLINE itraverseOf #-}++-- | Traverse with an index (and the arguments flipped).+--+-- @+-- 'Control.Lens.Traversal.forOf' l a ≡ 'iforOf' l a '.' 'const'+-- 'iforOf' ≡ 'flip' '.' 'itraverseOf'+-- @+--+-- @+-- 'iforOf' :: 'IndexedLens' i s t a b      -> s -> (i -> a -> f b) -> f t+-- 'iforOf' :: 'IndexedTraversal' i s t a b -> s -> (i -> a -> f b) -> f t+-- @+iforOf :: (Indexed i a (f b) -> s -> f t) -> s -> (i -> a -> f b) -> f t+iforOf = flip . itraverseOf+{-# INLINE iforOf #-}++-- | Map each element of a structure targeted by a 'Lens' to a monadic action,+-- evaluate these actions from left to right, and collect the results, with access+-- its position.+--+-- When you don't need access to the index 'mapMOf' is more liberal in what it can accept.+--+-- @+-- 'Control.Lens.Traversal.mapMOf' l ≡ 'imapMOf' l '.' 'const'+-- @+--+-- @+-- 'imapMOf' :: 'Monad' m => 'IndexedLens'      i s t a b -> (i -> a -> m b) -> s -> m t+-- 'imapMOf' :: 'Monad' m => 'IndexedTraversal' i s t a b -> (i -> a -> m b) -> s -> m t+-- @+imapMOf :: (Indexed i a (WrappedMonad m b) -> s -> WrappedMonad m t) -> (i -> a -> m b) -> s -> m t+imapMOf l = mapMOf l .# Indexed+{-# INLINE imapMOf #-}++-- | Map each element of a structure targeted by a 'Lens' to a monadic action,+-- evaluate these actions from left to right, and collect the results, with access+-- its position (and the arguments flipped).+--+-- @+-- 'Control.Lens.Traversal.forMOf' l a ≡ 'iforMOf' l a '.' 'const'+-- 'iforMOf' ≡ 'flip' '.' 'imapMOf'+-- @+--+-- @+-- 'iforMOf' :: 'Monad' m => 'IndexedLens' i s t a b      -> s -> (i -> a -> m b) -> m t+-- 'iforMOf' :: 'Monad' m => 'IndexedTraversal' i s t a b -> 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 = flip . imapMOf+{-# INLINE iforMOf #-}++-- | Generalizes 'Data.Traversable.mapAccumR' to an arbitrary 'IndexedTraversal' with access to the index.+--+-- 'imapAccumROf' accumulates state from right to left.+--+-- @+-- 'Control.Lens.Traversal.mapAccumROf' l ≡ 'imapAccumROf' l '.' 'const'+-- @+--+-- @+-- 'imapAccumROf' :: 'IndexedLens' i s t a b      -> (i -> acc -> a -> (acc, b)) -> acc -> s -> (acc, t)+-- 'imapAccumROf' :: 'IndexedTraversal' i 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 l = mapAccumROf l .# Indexed+{-# INLINE imapAccumROf #-}++-- | Generalizes 'Data.Traversable.mapAccumL' to an arbitrary 'IndexedTraversal' with access to the index.+--+-- 'imapAccumLOf' accumulates state from left to right.+--+-- @+-- 'Control.Lens.Traversal.mapAccumLOf' l ≡ 'imapAccumLOf' l '.' 'const'+-- @+--+-- @+-- 'imapAccumLOf' :: 'IndexedLens' i s t a b      -> (i -> acc -> a -> (acc, b)) -> acc -> s -> (acc, t)+-- 'imapAccumLOf' :: 'IndexedTraversal' i 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 l = mapAccumLOf l .# Indexed+{-# INLINE imapAccumLOf #-}++------------------------------------------------------------------------------+-- Common Indexed Traversals+------------------------------------------------------------------------------++-- | Traverse any 'Traversable' container. This is an 'IndexedTraversal' that is indexed by ordinal position.+traversed :: Traversable f => IndexedTraversal Int (f a) (f b) a b+traversed = conjoined traverse (indexing traverse)+{-# INLINE traversed #-}++-- | Traverse any 'Traversable' container. This is an 'IndexedTraversal' that is indexed by ordinal position.+traversed64 :: Traversable f => IndexedTraversal Int64 (f a) (f b) a b+traversed64 = conjoined traverse (indexing64 traverse)+{-# INLINE traversed64 #-}++-- | This is the trivial empty 'Traversal'.+--+-- @+-- 'ignored' :: 'IndexedTraversal' i s s a b+-- @+--+-- @+-- 'ignored' ≡ 'const' 'pure'+-- @+ignored :: Applicative f => pafb -> s -> f s+ignored _ = pure+{-# INLINE ignored #-}++-- | Allows 'IndexedTraversal' the value at the smallest index.+class Ord k => TraverseMin k m | m -> k where+  -- | 'IndexedTraversal' of the element with the smallest index.+  traverseMin :: IndexedTraversal' k (m v) v++instance TraverseMin Int IntMap where+  traverseMin f m = case IntMap.minViewWithKey m of+#if MIN_VERSION_containers(0,5,0)+    Just ((k,a), _) -> indexed f k a <&> \v -> IntMap.updateMin (const (Just v)) m+#else+    Just ((k,a), _) -> indexed f k a <&> \v -> IntMap.updateMin (const v) m+#endif+    Nothing     -> pure m+  {-# INLINE traverseMin #-}++instance Ord k => TraverseMin k (Map k) where+  traverseMin f m = case Map.minViewWithKey m of+    Just ((k, a), _) -> indexed f k a <&> \v -> Map.updateMin (const (Just v)) m+    Nothing          -> pure m+  {-# INLINE traverseMin #-}++-- | Allows 'IndexedTraversal' of the value at the largest index.+class Ord k => TraverseMax k m | m -> k where+  -- | 'IndexedTraversal' of the element at the largest index.+  traverseMax :: IndexedTraversal' k (m v) v++instance TraverseMax Int IntMap where+  traverseMax f m = case IntMap.maxViewWithKey m of+#if MIN_VERSION_containers(0,5,0)+    Just ((k,a), _) -> indexed f k a <&> \v -> IntMap.updateMax (const (Just v)) m+#else+    Just ((k,a), _) -> indexed f k a <&> \v -> IntMap.updateMax (const v) m+#endif+    Nothing     -> pure m+  {-# INLINE traverseMax #-}++instance Ord k => TraverseMax k (Map k) where+  traverseMax f m = case Map.maxViewWithKey m of+    Just ((k, a), _) -> indexed f k a <&> \v -> Map.updateMax (const (Just v)) m+    Nothing          -> pure m+  {-# INLINE traverseMax #-}++-- | Traverse the /nth/ element 'elementOf' a 'Traversal', 'Lens' or+-- 'Iso' if it exists.+--+-- >>> [[1],[3,4]] & elementOf (traverse.traverse) 1 .~ 5+-- [[1],[5,4]]+--+-- >>> [[1],[3,4]] ^? elementOf (folded.folded) 1+-- Just 3+--+-- >>> timingOut $ ['a'..] ^?! elementOf folded 5+-- 'f'+--+-- >>> timingOut $ take 10 $ elementOf traverse 3 .~ 16 $ [0..]+-- [0,1,2,16,4,5,6,7,8,9]+--+-- @+-- 'elementOf' :: 'Traversal'' s a -> 'Int' -> 'IndexedTraversal'' 'Int' s a+-- 'elementOf' :: 'Fold' s a       -> 'Int' -> 'IndexedFold' 'Int' s a+-- @+elementOf :: Applicative f+          => LensLike (Indexing f) s t a a+          -> Int+          -> IndexedLensLike Int f s t a a+elementOf l p = elementsOf l (p ==)+{-# INLINE elementOf #-}++-- | Traverse the /nth/ element of a 'Traversable' container.+--+-- @+-- 'element' ≡ 'elementOf' 'traverse'+-- @+element :: Traversable t => Int -> IndexedTraversal' Int (t a) a+element = elementOf traverse+{-# INLINE element #-}++-- | Traverse (or fold) selected elements of a 'Traversal' (or 'Fold') where their ordinal positions match a predicate.+--+-- @+-- 'elementsOf' :: 'Traversal'' s a -> ('Int' -> 'Bool') -> 'IndexedTraversal'' 'Int' s a+-- 'elementsOf' :: 'Fold' s a       -> ('Int' -> 'Bool') -> 'IndexedFold' 'Int' s a+-- @+elementsOf :: Applicative f+           => LensLike (Indexing f) s t a a+           -> (Int -> Bool)+           -> IndexedLensLike Int f s t a a+elementsOf l p iafb s = snd $ runIndexing (l (\a -> Indexing (\i -> i `seq` (i + 1, if p i then indexed iafb i a else pure a))) s) 0+{-# INLINE elementsOf #-}++-- | Traverse elements of a 'Traversable' container where their ordinal positions matches a predicate.+--+-- @+-- 'elements' ≡ 'elementsOf' 'traverse'+-- @+elements :: Traversable t => (Int -> Bool) -> IndexedTraversal' Int (t a) a+elements = elementsOf traverse+{-# INLINE elements #-}
src/Control/Lens/Tuple.hs view
@@ -1,9 +1,10 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE Rank2Types #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE FunctionalDependencies #-}+{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE UndecidableInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FunctionalDependencies #-} #ifdef TRUSTWORTHY {-# LANGUAGE Trustworthy #-} #endif@@ -11,7 +12,7 @@ ------------------------------------------------------------------------------- -- | -- Module      :  Control.Lens.Tuple--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  provisional@@ -32,8 +33,11 @@   , Field9(..)   ) where +import Control.Applicative import Control.Lens.Combinators+import Control.Lens.Indexed import Control.Lens.Type+import Data.Functor.Identity  -- $setup -- >>> import Control.Lens@@ -55,56 +59,61 @@   -- hello   -- ((),"world")   ---  -- This can also be used on larger tuples as well+  -- This can also be used on larger tuples as well:   --   -- >>> _1 +~ 41 $ (1,2,3,4,5)   -- (42,2,3,4,5)   --   -- @-  -- _1 :: 'Lens' (a,b) (a',b) a a'-  -- _1 :: 'Lens' (a,b,c) (a',b,c) a a'-  -- _1 :: 'Lens' (a,b,c,d) (a',b,c,d) a a'+  -- '_1' :: 'Lens' (a,b) (a',b) a a'+  -- '_1' :: 'Lens' (a,b,c) (a',b,c) a a'+  -- '_1' :: 'Lens' (a,b,c,d) (a',b,c,d) a a'   -- ...-  -- _1 :: 'Lens' (a,c,d,e,f,g,h,i) (a',b,c,d,e,f,g,h,i) a a'+  -- '_1' :: 'Lens' (a,c,d,e,f,g,h,i) (a',b,c,d,e,f,g,h,i) a a'   -- @-  _1 :: Lens s t a b+  _1 :: IndexedLens Int s t a b --- | @'_1' k ~(a,b) = (\a' -> (a',b)) '<$>' k a@+instance Field1 (Identity a) (Identity b) a b where+  _1 f (Identity a) = Identity <$> indexed f (0 :: Int) a++-- | @+-- '_1' k ~(a,b) = (\\a' -> (a',b)) 'Data.Functor.<$>' k a+-- @ instance Field1 (a,b) (a',b) a a' where-  _1 k ~(a,b) = k a <&> \a' -> (a',b)+  _1 k ~(a,b) = indexed k (0 :: Int) a <&> \a' -> (a',b)   {-# INLINE _1 #-}  instance Field1 (a,b,c) (a',b,c) a a' where-  _1 k ~(a,b,c) = k a <&> \a' -> (a',b,c)+  _1 k ~(a,b,c) = indexed k (0 :: Int) a <&> \a' -> (a',b,c)   {-# INLINE _1 #-}  instance Field1 (a,b,c,d) (a',b,c,d) a a' where-  _1 k ~(a,b,c,d) = k a <&> \a' -> (a',b,c,d)+  _1 k ~(a,b,c,d) = indexed k (0 :: Int) a <&> \a' -> (a',b,c,d)   {-# INLINE _1 #-}  instance Field1 (a,b,c,d,e) (a',b,c,d,e) a a' where-  _1 k ~(a,b,c,d,e) = k a <&> \a' -> (a',b,c,d,e)+  _1 k ~(a,b,c,d,e) = indexed k (0 :: Int) a <&> \a' -> (a',b,c,d,e)   {-# INLINE _1 #-}  instance Field1 (a,b,c,d,e,f) (a',b,c,d,e,f) a a' where-  _1 k ~(a,b,c,d,e,f) = k a <&> \a' -> (a',b,c,d,e,f)+  _1 k ~(a,b,c,d,e,f) = indexed k (0 :: Int) a <&> \a' -> (a',b,c,d,e,f)   {-# INLINE _1 #-}  instance Field1 (a,b,c,d,e,f,g) (a',b,c,d,e,f,g) a a' where-  _1 k ~(a,b,c,d,e,f,g) = k a <&> \a' -> (a',b,c,d,e,f,g)+  _1 k ~(a,b,c,d,e,f,g) = indexed k (0 :: Int) a <&> \a' -> (a',b,c,d,e,f,g)   {-# INLINE _1 #-}  instance Field1 (a,b,c,d,e,f,g,h) (a',b,c,d,e,f,g,h) a a' where-  _1 k ~(a,b,c,d,e,f,g,h) = k a <&> \a' -> (a',b,c,d,e,f,g,h)+  _1 k ~(a,b,c,d,e,f,g,h) = indexed k (0 :: Int) a <&> \a' -> (a',b,c,d,e,f,g,h)   {-# INLINE _1 #-}  instance Field1 (a,b,c,d,e,f,g,h,i) (a',b,c,d,e,f,g,h,i) a a' where-  _1 k ~(a,b,c,d,e,f,g,h,i) = k a <&> \a' -> (a',b,c,d,e,f,g,h,i)+  _1 k ~(a,b,c,d,e,f,g,h,i) = indexed k (0 :: Int) a <&> \a' -> (a',b,c,d,e,f,g,h,i)   {-# INLINE _1 #-} --- | Provides access to the 2nd field of a tuple+-- | Provides access to the 2nd field of a tuple. class Field2 s t a b | s -> a, t -> b, s b -> t, t a -> s where-  -- | Access the 2nd field of a tuple+  -- | Access the 2nd field of a tuple.   --   -- >>> _2 .~ "hello" $ (1,(),3,4)   -- (1,"hello",3,4)@@ -118,187 +127,189 @@   --   -- @   -- 'Control.Lens.Fold.anyOf' '_2' :: (s -> 'Bool') -> (a, s) -> 'Bool'-  -- 'Data.Traversable.traverse' '.' '_2' :: ('Applicative' f, 'Data.Traversable.Traversable' t) => (a -> f b) -> t (s, a) -> f (t (s, b))+  -- 'Data.Traversable.traverse' '.' '_2' :: ('Control.Applicative.Applicative' f, 'Data.Traversable.Traversable' t) => (a -> f b) -> t (s, a) -> f (t (s, b))   -- 'Control.Lens.Fold.foldMapOf' ('Data.Traversable.traverse' '.' '_2') :: ('Data.Traversable.Traversable' t, 'Data.Monoid.Monoid' m) => (s -> m) -> t (b, s) -> m   -- @-  _2 :: Lens s t a b+  _2 :: IndexedLens Int s t a b --- | @'_2' k ~(a,b) = (\b' -> (a,b')) '<$>' k b@+-- | @+-- '_2' k ~(a,b) = (\\b' -> (a,b')) 'Data.Functor.<$>' k b+-- @ instance Field2 (a,b) (a,b') b b' where-  _2 k ~(a,b) = k b <&> \b' -> (a,b')+  _2 k ~(a,b) = indexed k (1 :: Int) b <&> \b' -> (a,b')   {-# INLINE _2 #-}  instance Field2 (a,b,c) (a,b',c) b b' where-  _2 k ~(a,b,c) = k b <&> \b' -> (a,b',c)+  _2 k ~(a,b,c) = indexed k (1 :: Int) b <&> \b' -> (a,b',c)   {-# INLINE _2 #-}  instance Field2 (a,b,c,d) (a,b',c,d) b b' where-  _2 k ~(a,b,c,d) = k b <&> \b' -> (a,b',c,d)+  _2 k ~(a,b,c,d) = indexed k (1 :: Int) b <&> \b' -> (a,b',c,d)   {-# INLINE _2 #-}  instance Field2 (a,b,c,d,e) (a,b',c,d,e) b b' where-  _2 k ~(a,b,c,d,e) = k b <&> \b' -> (a,b',c,d,e)+  _2 k ~(a,b,c,d,e) = indexed k (1 :: Int) b <&> \b' -> (a,b',c,d,e)   {-# INLINE _2 #-}  instance Field2 (a,b,c,d,e,f) (a,b',c,d,e,f) b b' where-  _2 k ~(a,b,c,d,e,f) = k b <&> \b' -> (a,b',c,d,e,f)+  _2 k ~(a,b,c,d,e,f) = indexed k (1 :: Int) b <&> \b' -> (a,b',c,d,e,f)   {-# INLINE _2 #-}  instance Field2 (a,b,c,d,e,f,g) (a,b',c,d,e,f,g) b b' where-  _2 k ~(a,b,c,d,e,f,g) = k b <&> \b' -> (a,b',c,d,e,f,g)+  _2 k ~(a,b,c,d,e,f,g) = indexed k (1 :: Int) b <&> \b' -> (a,b',c,d,e,f,g)   {-# INLINE _2 #-}  instance Field2 (a,b,c,d,e,f,g,h) (a,b',c,d,e,f,g,h) b b' where-  _2 k ~(a,b,c,d,e,f,g,h) = k b <&> \b' -> (a,b',c,d,e,f,g,h)+  _2 k ~(a,b,c,d,e,f,g,h) = indexed k (1 :: Int) b <&> \b' -> (a,b',c,d,e,f,g,h)   {-# INLINE _2 #-}  instance Field2 (a,b,c,d,e,f,g,h,i) (a,b',c,d,e,f,g,h,i) b b' where-  _2 k ~(a,b,c,d,e,f,g,h,i) = k b <&> \b' -> (a,b',c,d,e,f,g,h,i)+  _2 k ~(a,b,c,d,e,f,g,h,i) = indexed k (1 :: Int) b <&> \b' -> (a,b',c,d,e,f,g,h,i)   {-# INLINE _2 #-} --- | Provides access to the 3rd field of a tuple+-- | Provides access to the 3rd field of a tuple. class Field3 s t a b | s -> a, t -> b, s b -> t, t a -> s where-  -- | Access the 3rd field of a tuple-  _3 :: Lens s t a b+  -- | Access the 3rd field of a tuple.+  _3 :: IndexedLens Int s t a b  instance Field3 (a,b,c) (a,b,c') c c' where-  _3 k ~(a,b,c) = k c <&> \c' -> (a,b,c')+  _3 k ~(a,b,c) = indexed k (2 :: Int) c <&> \c' -> (a,b,c')   {-# INLINE _3 #-}  instance Field3 (a,b,c,d) (a,b,c',d) c c' where-  _3 k ~(a,b,c,d) = k c <&> \c' -> (a,b,c',d)+  _3 k ~(a,b,c,d) = indexed k (2 :: Int) c <&> \c' -> (a,b,c',d)   {-# INLINE _3 #-}  instance Field3 (a,b,c,d,e) (a,b,c',d,e) c c' where-  _3 k ~(a,b,c,d,e) = k c <&> \c' -> (a,b,c',d,e)+  _3 k ~(a,b,c,d,e) = indexed k (2 :: Int) c <&> \c' -> (a,b,c',d,e)   {-# INLINE _3 #-}  instance Field3 (a,b,c,d,e,f) (a,b,c',d,e,f) c c' where-  _3 k ~(a,b,c,d,e,f) = k c <&> \c' -> (a,b,c',d,e,f)+  _3 k ~(a,b,c,d,e,f) = indexed k (2 :: Int) c <&> \c' -> (a,b,c',d,e,f)   {-# INLINE _3 #-}  instance Field3 (a,b,c,d,e,f,g) (a,b,c',d,e,f,g) c c' where-  _3 k ~(a,b,c,d,e,f,g) = k c <&> \c' -> (a,b,c',d,e,f,g)+  _3 k ~(a,b,c,d,e,f,g) = indexed k (2 :: Int) c <&> \c' -> (a,b,c',d,e,f,g)   {-# INLINE _3 #-}  instance Field3 (a,b,c,d,e,f,g,h) (a,b,c',d,e,f,g,h) c c' where-  _3 k ~(a,b,c,d,e,f,g,h) = k c <&> \c' -> (a,b,c',d,e,f,g,h)+  _3 k ~(a,b,c,d,e,f,g,h) = indexed k (2 :: Int) c <&> \c' -> (a,b,c',d,e,f,g,h)   {-# INLINE _3 #-}  instance Field3 (a,b,c,d,e,f,g,h,i) (a,b,c',d,e,f,g,h,i) c c' where-  _3 k ~(a,b,c,d,e,f,g,h,i) = k c <&> \c' -> (a,b,c',d,e,f,g,h,i)+  _3 k ~(a,b,c,d,e,f,g,h,i) = indexed k (2 :: Int) c <&> \c' -> (a,b,c',d,e,f,g,h,i)   {-# INLINE _3 #-} --- | Provide access to the 4th field of a tuple+-- | Provide access to the 4th field of a tuple. class Field4 s t a b | s -> a, t -> b, s b -> t, t a -> s where-  -- | Access the 4th field of a tuple-  _4 :: Lens s t a b+  -- | Access the 4th field of a tuple.+  _4 :: IndexedLens Int s t a b  instance Field4 (a,b,c,d) (a,b,c,d') d d' where-  _4 k ~(a,b,c,d) = k d <&> \d' -> (a,b,c,d')+  _4 k ~(a,b,c,d) = indexed k (3 :: Int) d <&> \d' -> (a,b,c,d')   {-# INLINE _4 #-}  instance Field4 (a,b,c,d,e) (a,b,c,d',e) d d' where-  _4 k ~(a,b,c,d,e) = k d <&> \d' -> (a,b,c,d',e)+  _4 k ~(a,b,c,d,e) = indexed k (3 :: Int) d <&> \d' -> (a,b,c,d',e)   {-# INLINE _4 #-}  instance Field4 (a,b,c,d,e,f) (a,b,c,d',e,f) d d' where-  _4 k ~(a,b,c,d,e,f) = k d <&> \d' -> (a,b,c,d',e,f)+  _4 k ~(a,b,c,d,e,f) = indexed k (3 :: Int) d <&> \d' -> (a,b,c,d',e,f)   {-# INLINE _4 #-}  instance Field4 (a,b,c,d,e,f,g) (a,b,c,d',e,f,g) d d' where-  _4 k ~(a,b,c,d,e,f,g) = k d <&> \d' -> (a,b,c,d',e,f,g)+  _4 k ~(a,b,c,d,e,f,g) = indexed k (3 :: Int) d <&> \d' -> (a,b,c,d',e,f,g)   {-# INLINE _4 #-}  instance Field4 (a,b,c,d,e,f,g,h) (a,b,c,d',e,f,g,h) d d' where-  _4 k ~(a,b,c,d,e,f,g,h) = k d <&> \d' -> (a,b,c,d',e,f,g,h)+  _4 k ~(a,b,c,d,e,f,g,h) = indexed k (3 :: Int) d <&> \d' -> (a,b,c,d',e,f,g,h)   {-# INLINE _4 #-}  instance Field4 (a,b,c,d,e,f,g,h,i) (a,b,c,d',e,f,g,h,i) d d' where-  _4 k ~(a,b,c,d,e,f,g,h,i) = k d <&> \d' -> (a,b,c,d',e,f,g,h,i)+  _4 k ~(a,b,c,d,e,f,g,h,i) = indexed k (3 :: Int) d <&> \d' -> (a,b,c,d',e,f,g,h,i)   {-# INLINE _4 #-} --- | Provides access to the 5th field of a tuple+-- | Provides access to the 5th field of a tuple. class Field5 s t a b | s -> a, t -> b, s b -> t, t a -> s where-  -- | Access the 5th field of a tuple-  _5 :: Lens s t a b+  -- | Access the 5th field of a tuple.+  _5 :: IndexedLens Int s t a b  instance Field5 (a,b,c,d,e) (a,b,c,d,e') e e' where-  _5 k ~(a,b,c,d,e) = k e <&> \e' -> (a,b,c,d,e')+  _5 k ~(a,b,c,d,e) = indexed k (4 :: Int) e <&> \e' -> (a,b,c,d,e')   {-# INLINE _5 #-}  instance Field5 (a,b,c,d,e,f) (a,b,c,d,e',f) e e' where-  _5 k ~(a,b,c,d,e,f) = k e <&> \e' -> (a,b,c,d,e',f)+  _5 k ~(a,b,c,d,e,f) = indexed k (4 :: Int) e <&> \e' -> (a,b,c,d,e',f)   {-# INLINE _5 #-}  instance Field5 (a,b,c,d,e,f,g) (a,b,c,d,e',f,g) e e' where-  _5 k ~(a,b,c,d,e,f,g) = k e <&> \e' -> (a,b,c,d,e',f,g)+  _5 k ~(a,b,c,d,e,f,g) = indexed k (4 :: Int) e <&> \e' -> (a,b,c,d,e',f,g)   {-# INLINE _5 #-}  instance Field5 (a,b,c,d,e,f,g,h) (a,b,c,d,e',f,g,h) e e' where-  _5 k ~(a,b,c,d,e,f,g,h) = k e <&> \e' -> (a,b,c,d,e',f,g,h)+  _5 k ~(a,b,c,d,e,f,g,h) = indexed k (4 :: Int) e <&> \e' -> (a,b,c,d,e',f,g,h)   {-# INLINE _5 #-}  instance Field5 (a,b,c,d,e,f,g,h,i) (a,b,c,d,e',f,g,h,i) e e' where-  _5 k ~(a,b,c,d,e,f,g,h,i) = k e <&> \e' -> (a,b,c,d,e',f,g,h,i)+  _5 k ~(a,b,c,d,e,f,g,h,i) = indexed k (4 :: Int) e <&> \e' -> (a,b,c,d,e',f,g,h,i)   {-# INLINE _5 #-} --- | Provides access to the 6th element of a tuple+-- | Provides access to the 6th element of a tuple. class Field6 s t a b | s -> a, t -> b, s b -> t, t a -> s where-  -- | Access the 6th field of a tuple-  _6 :: Lens s t a b+  -- | Access the 6th field of a tuple.+  _6 :: IndexedLens Int s t a b  instance Field6 (a,b,c,d,e,f) (a,b,c,d,e,f') f f' where-  _6 k ~(a,b,c,d,e,f) = k f <&> \f' -> (a,b,c,d,e,f')+  _6 k ~(a,b,c,d,e,f) = indexed k (5 :: Int) f <&> \f' -> (a,b,c,d,e,f')   {-# INLINE _6 #-}  instance Field6 (a,b,c,d,e,f,g) (a,b,c,d,e,f',g) f f' where-  _6 k ~(a,b,c,d,e,f,g) = k f <&> \f' -> (a,b,c,d,e,f',g)+  _6 k ~(a,b,c,d,e,f,g) = indexed k (5 :: Int) f <&> \f' -> (a,b,c,d,e,f',g)   {-# INLINE _6 #-}  instance Field6 (a,b,c,d,e,f,g,h) (a,b,c,d,e,f',g,h) f f' where-  _6 k ~(a,b,c,d,e,f,g,h) = k f <&> \f' -> (a,b,c,d,e,f',g,h)+  _6 k ~(a,b,c,d,e,f,g,h) = indexed k (5 :: Int) f <&> \f' -> (a,b,c,d,e,f',g,h)   {-# INLINE _6 #-}  instance Field6 (a,b,c,d,e,f,g,h,i) (a,b,c,d,e,f',g,h,i) f f' where-  _6 k ~(a,b,c,d,e,f,g,h,i) = k f <&> \f' -> (a,b,c,d,e,f',g,h,i)+  _6 k ~(a,b,c,d,e,f,g,h,i) = indexed k (5 :: Int) f <&> \f' -> (a,b,c,d,e,f',g,h,i)   {-# INLINE _6 #-} --- | Provide access to the 7th field of a tuple+-- | Provide access to the 7th field of a tuple. class Field7 s t a b | s -> a, t -> b, s b -> t, t a -> s where-  -- | Access the 7th field of a tuple-  _7 :: Lens s t a b+  -- | Access the 7th field of a tuple.+  _7 :: IndexedLens Int s t a b  instance Field7 (a,b,c,d,e,f,g) (a,b,c,d,e,f,g') g g' where-  _7 k ~(a,b,c,d,e,f,g) = k g <&> \g' -> (a,b,c,d,e,f,g')+  _7 k ~(a,b,c,d,e,f,g) = indexed k (6 :: Int) g <&> \g' -> (a,b,c,d,e,f,g')   {-# INLINE _7 #-}  instance Field7 (a,b,c,d,e,f,g,h) (a,b,c,d,e,f,g',h) g g' where-  _7 k ~(a,b,c,d,e,f,g,h) = k g <&> \g' -> (a,b,c,d,e,f,g',h)+  _7 k ~(a,b,c,d,e,f,g,h) = indexed k (6 :: Int) g <&> \g' -> (a,b,c,d,e,f,g',h)   {-# INLINE _7 #-}  instance Field7 (a,b,c,d,e,f,g,h,i) (a,b,c,d,e,f,g',h,i) g g' where-  _7 k ~(a,b,c,d,e,f,g,h,i) = k g <&> \g' -> (a,b,c,d,e,f,g',h,i)+  _7 k ~(a,b,c,d,e,f,g,h,i) = indexed k (6 :: Int) g <&> \g' -> (a,b,c,d,e,f,g',h,i)   {-# INLINE _7 #-} --- | Provide access to the 8th field of a tuple+-- | Provide access to the 8th field of a tuple. class Field8 s t a b | s -> a, t -> b, s b -> t, t a -> s where-  -- | Access the 8th field of a tuple-  _8 :: Lens s t a b+  -- | Access the 8th field of a tuple.+  _8 :: IndexedLens Int s t a b  instance Field8 (a,b,c,d,e,f,g,h) (a,b,c,d,e,f,g,h') h h' where-  _8 k ~(a,b,c,d,e,f,g,h) = k h <&> \h' -> (a,b,c,d,e,f,g,h')+  _8 k ~(a,b,c,d,e,f,g,h) = indexed k (7 :: Int) h <&> \h' -> (a,b,c,d,e,f,g,h')   {-# INLINE _8 #-}  instance Field8 (a,b,c,d,e,f,g,h,i) (a,b,c,d,e,f,g,h',i) h h' where-  _8 k ~(a,b,c,d,e,f,g,h,i) = k h <&> \h' -> (a,b,c,d,e,f,g,h',i)+  _8 k ~(a,b,c,d,e,f,g,h,i) = indexed k (7 :: Int) h <&> \h' -> (a,b,c,d,e,f,g,h',i)   {-# INLINE _8 #-} --- | Provides access to the 9th field of a tuple+-- | Provides access to the 9th field of a tuple. class Field9 s t a b | s -> a, t -> b, s b -> t, t a -> s where-  -- | Access the 9th field of a tuple-  _9 :: Lens s t a b+  -- | Access the 9th field of a tuple.+  _9 :: IndexedLens Int s t a b  instance Field9 (a,b,c,d,e,f,g,h,i) (a,b,c,d,e,f,g,h,i') i i' where-  _9 k ~(a,b,c,d,e,f,g,h,i) = k i <&> \i' -> (a,b,c,d,e,f,g,h,i')+  _9 k ~(a,b,c,d,e,f,g,h,i) = indexed k (8 :: Int) i <&> \i' -> (a,b,c,d,e,f,g,h,i')   {-# INLINE _9 #-}
src/Control/Lens/Type.hs view
@@ -1,115 +1,63 @@ {-# LANGUAGE CPP #-}+{-# LANGUAGE GADTs #-} {-# LANGUAGE Rank2Types #-}-{-# LANGUAGE LiberalTypeSynonyms #-}-{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE UndecidableInstances #-}-{-# LANGUAGE TypeOperators #-}-#ifdef TRUSTWORTHY-{-# LANGUAGE Trustworthy #-}-#endif---#ifndef MIN_VERSION_mtl-#define MIN_VERSION_mtl(x,y,z) 1-#endif-+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE KindSignatures #-} ------------------------------------------------------------------------------- -- | -- Module      :  Control.Lens.Type--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  provisional -- Portability :  Rank2Types ----- A @'Lens' s t a b@ is a purely functional reference.------ While a 'Control.Lens.Traversal.Traversal' could be used for--- 'Control.Lens.Getter.Getting' like a valid 'Control.Lens.Fold.Fold',--- it wasn't a valid 'Control.Lens.Getter.Getter' as 'Applicative' wasn't a superclass of--- 'Control.Lens.Getter.Gettable'.------ 'Functor', however is the superclass of both.------ @type 'Lens' s t a b = forall f. 'Functor' f => (a -> f b) -> s -> f t@------ Every 'Lens' is a valid 'Control.Lens.Setter.Setter'.------ Every 'Lens' can be used for 'Control.Lens.Getter.Getting' like a--- 'Control.Lens.Fold.Fold' that doesn't use the 'Applicative' or--- 'Control.Lens.Getter.Gettable'.------ Every 'Lens' is a valid 'Control.Lens.Traversal.Traversal' that only uses--- the 'Functor' part of the 'Applicative' it is supplied.------ Every 'Lens' can be used for 'Control.Lens.Getter.Getting' like a valid--- 'Control.Lens.Getter.Getter', since 'Functor' is a superclass of 'Control.Lens.Getter.Gettable'------ Since every 'Lens' can be used for 'Control.Lens.Getter.Getting' like a--- valid 'Control.Lens.Getter.Getter' it follows that it must view exactly one element in the--- structure.------ The lens laws follow from this property and the desire for it to act like--- a 'Data.Traversable.Traversable' when used as a--- 'Control.Lens.Traversal.Traversal'.------ In the examples below, 'getter' and 'setter' are supplied as example getters--- and setters, and are not actual functions supplied by this package.+-- This module exports the majority of the types that need to appear in user+-- signatures or in documentation when talking about lenses. The remaining types+-- for consuming lenses are distributed across various modules in the hierarchy. ------------------------------------------------------------------------------- module Control.Lens.Type   (-  -- * Lenses-    Lens+  -- * Other+    Equality, Equality'+  , Iso, Iso'+  , Prism , Prism'+  -- * Lenses, Folds and Traversals+  , Lens, Lens'+  , Traversal, Traversal'+  , Setter, Setter'+  , Getter, Fold+  , Action, MonadicFold+  -- * Indexed+  , IndexedLens, IndexedLens'+  , IndexedTraversal, IndexedTraversal'+  , IndexedSetter, IndexedSetter'+  , IndexedGetter, IndexedFold+  , IndexedAction, IndexedMonadicFold+  -- * Index-Preserving+  , IndexPreservingLens, IndexPreservingLens'+  , IndexPreservingTraversal, IndexPreservingTraversal'+  , IndexPreservingSetter, IndexPreservingSetter'+  , IndexPreservingGetter, IndexPreservingFold+  , IndexPreservingAction, IndexPreservingMonadicFold+  -- * Common   , Simple--  , lens-  , (%%~)-  , (%%=)---  -- * Lateral Composition-  , choosing-  , chosen-  , alongside-  , inside--  -- * Setting Functionally with Passthrough-  , (<%~), (<+~), (<-~), (<*~), (<//~)-  , (<^~), (<^^~), (<**~)-  , (<||~), (<&&~), (<<>~)-  , (<<%~), (<<.~)--  -- * Setting State with Passthrough-  , (<%=), (<+=), (<-=), (<*=), (<//=)-  , (<^=), (<^^=), (<**=)-  , (<||=), (<&&=), (<<>=)-  , (<<%=), (<<.=)-  , (<<~)--  -- * Cloning Lenses-  , cloneLens-  , ReifiedLens(..)--  -- * Context-  , Context(..)-  , locus--  -- * Simplified and In-Progress-  , LensLike-  , Overloaded-  , SimpleLens-  , SimpleLensLike-  , SimpleOverloaded-  , SimpleReifiedLens+  , LensLike, LensLike'+  , Over, Over'+  , IndexedLensLike, IndexedLensLike'+  , Overloading, Overloading'+  , Overloaded, Overloaded'   ) where  import Control.Applicative-import Control.Comonad.Store as Store-import Control.Lens.Combinators ((<&>))-import Control.Lens.Internal (Context(..))-import Control.Monad.State as State-import Data.Monoid (Monoid(mappend))+import Control.Lens.Internal.Action+import Control.Lens.Internal.Getter+import Control.Lens.Internal.Setter+import Control.Lens.Internal.Indexed+import Data.Profunctor  -- $setup -- >>> import Control.Lens@@ -120,12 +68,8 @@ -- >>> let h :: Expr -> Expr -> Expr; h = Debug.SimpleReflect.Vars.h -- >>> let getter :: Expr -> Expr; getter = fun "getter" -- >>> let setter :: Expr -> Expr -> Expr; setter = fun "setter"--infixr 4 %%~-infix  4 %%=-infixr 4 <+~, <*~, <-~, <//~, <^~, <^^~, <**~, <&&~, <||~, <<>~, <%~, <<%~, <<.~-infix  4 <+=, <*=, <-=, <//=, <^=, <^^=, <**=, <&&=, <||=, <<>=, <%=, <<%=, <<.=-infixr 2 <<~+-- >>> import Numeric.Natural+-- >>> let nat :: Prism' Integer Natural; nat = prism toInteger $ \i -> if i < 0 then Left i else Right (fromInteger i)  ------------------------------------------------------------------------------- -- Lenses@@ -135,19 +79,25 @@ -- <http://comonad.com/reader/2012/mirrored-lenses/>. -- -- With great power comes great responsibility and a 'Lens' is subject to the--- three common sense lens laws:+-- three common sense 'Lens' laws: -- -- 1) You get back what you put in: ----- @'Control.Lens.Getter.view' l ('Control.Lens.Setter.set' l b a)  ≡ b@+-- @+-- 'Control.Lens.Getter.view' l ('Control.Lens.Setter.set' l b a)  ≡ b+-- @ -- -- 2) Putting back what you got doesn't change anything: ----- @'Control.Lens.Setter.set' l ('Control.Lens.Getter.view' l a) a  ≡ a@+-- @+-- 'Control.Lens.Setter.set' l ('Control.Lens.Getter.view' l a) a  ≡ a+-- @ -- -- 3) Setting twice is the same as setting once: ----- @'Control.Lens.Setter.set' l c ('Control.Lens.Setter.set' l b a) ≡ 'Control.Lens.Setter.set' l c a@+-- @+-- 'Control.Lens.Setter.set' l c ('Control.Lens.Setter.set' l b a) ≡ 'Control.Lens.Setter.set' l c a+-- @ -- -- These laws are strong enough that the 4 type parameters of a 'Lens' cannot -- vary fully independently. For more on how they interact, read the \"Why is@@ -155,622 +105,457 @@ -- <http://comonad.com/reader/2012/mirrored-lenses/>. -- -- Every 'Lens' can be used directly as a 'Control.Lens.Setter.Setter' or--- 'Control.Lens.Traversal.Traversal'.+-- 'Traversal'. -- -- You can also use a 'Lens' for 'Control.Lens.Getter.Getting' as if it were a--- 'Control.Lens.Fold.Fold' or 'Control.Lens.Getter.Getter'.+-- 'Fold' or 'Getter'. ----- Since every lens is a valid 'Control.Lens.Traversal.Traversal', the--- traversal laws are required of any lenses you create:+-- Since every 'Lens' is a valid 'Traversal', the+-- 'Traversal' laws are required of any 'Lens' you create: -- -- @ -- l 'pure' ≡ 'pure' -- 'fmap' (l f) '.' l g ≡ 'Data.Functor.Compose.getCompose' '.' l ('Data.Functor.Compose.Compose' '.' 'fmap' f '.' g) -- @ ----- @type 'Lens' s t a b = forall f. 'Functor' f => 'LensLike' f s t a b@+-- @+-- type 'Lens' s t a b = forall f. 'Functor' f => 'LensLike' f s t a b+-- @ type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t --- | A 'Simple' 'Lens', 'Simple' 'Control.Lens.Traversal.Traversal', ... can--- be used instead of a 'Lens','Control.Lens.Traversal.Traversal', ...--- whenever the type variables don't change upon setting a value.------ @--- 'Data.Complex.Lens.imaginary' :: 'Simple' 'Lens' ('Data.Complex.Complex' a) a--- 'Data.List.Lens.traverseHead' :: 'Simple' 'Control.Lens.Lens.Traversal' [a] a+-- | @+-- type 'Lens'' = 'Simple' 'Lens' -- @------ Note: To use this alias in your own code with @'LensLike' f@ or--- 'Control.Lens.Setter.Setter', you may have to turn on @LiberalTypeSynonyms@.-type Simple f s a = f s s a a+type Lens' s a = Lens s s a a --- | @type 'SimpleLens' = 'Simple' 'Lens'@-type SimpleLens s a = Lens s s a a+-- | Every 'IndexedLens' is a valid 'Lens' and a valid 'Control.Lens.Traversal.IndexedTraversal'.+type IndexedLens i s t a b = forall f p. (Indexable i p, Functor f) => p a (f b) -> s -> f t --- | @type 'SimpleLensLike' f = 'Simple' ('LensLike' f)@-type SimpleLensLike f s a = LensLike f s s a a+-- | @+-- type 'IndexedLens'' i = 'Simple' ('IndexedLens' i)+-- @+type IndexedLens' i s a = IndexedLens i s s a a ------------------------------ Constructing Lenses---------------------------+-- | An 'IndexPreservingLens' leaves any index it is composed with alone.+type IndexPreservingLens s t a b = forall p f. (Conjoined p, Functor f) => p a (f b) -> p s (f t) --- | Build a 'Lens' from a getter and a setter.------ @'lens' :: 'Functor' f => (s -> a) -> (s -> b -> t) -> (a -> f b) -> s -> f t@------ >>> s ^. lens getter setter--- getter s------ >>> s & lens getter setter .~ b--- setter s b------ >>> s & lens getter setter %~ f--- setter s (f (getter s))-lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b-lens sa sbt afb s = sbt s <$> afb (sa s)-{-# INLINE lens #-}+-- | @+-- type 'IndexPreservingLens'' = 'Simple' 'IndexPreservingLens'+-- @+type IndexPreservingLens' s a = IndexPreservingLens s s a a ----------------------------------------------------------------------------------- LensLike--------------------------------------------------------------------------------+------------------------------------------------------------------------------+-- Traversals+------------------------------------------------------------------------------ --- |--- Many combinators that accept a 'Lens' can also accept a--- 'Control.Lens.Traversal.Traversal' in limited situations.------ They do so by specializing the type of 'Functor' that they require of the--- caller.------ If a function accepts a @'LensLike' f s t a b@ for some 'Functor' @f@,--- then they may be passed a 'Lens'.+-- | A 'Traversal' can be used directly as a 'Control.Lens.Setter.Setter' or a 'Fold' (but not as a 'Lens') and provides+-- the ability to both read and update multiple fields, subject to some relatively weak 'Traversal' laws. ----- Further, if @f@ is an 'Applicative', they may also be passed a--- 'Control.Lens.Traversal.Traversal'.-type LensLike f s t a b = (a -> f b) -> s -> f t---- | ('%%~') can be used in one of two scenarios:+-- These have also been known as multilenses, but they have the signature and spirit of ----- When applied to a 'Lens', it can edit the target of the 'Lens' in a--- structure, extracting a functorial result.+-- @+-- 'Data.Traversable.traverse' :: 'Data.Traversable.Traversable' f => 'Traversal' (f a) (f b) a b+-- @ ----- When applied to a 'Control.Lens.Traversal.Traversal', it can edit the--- targets of the 'Traversals', extracting an applicative summary of its--- actions.+-- and the more evocative name suggests their application. ----- For all that the definition of this combinator is just:+-- Most of the time the 'Traversal' you will want to use is just 'Data.Traversable.traverse', but you can also pass any+-- 'Lens' or 'Iso' as a 'Traversal', and composition of a 'Traversal' (or 'Lens' or 'Iso') with a 'Traversal' (or 'Lens' or 'Iso')+-- using ('.') forms a valid 'Traversal'. ----- @('%%~') ≡ 'id'@+-- The laws for a 'Traversal' @t@ follow from the laws for 'Data.Traversable.Traversable' as stated in \"The Essence of the Iterator Pattern\". -- -- @--- ('%%~') :: 'Functor' f =>     'Control.Lens.Iso.Iso' s t a b       -> (a -> f b) -> s -> f t--- ('%%~') :: 'Functor' f =>     'Lens' s t a b      -> (a -> f b) -> s -> f t--- ('%%~') :: 'Applicative' f => 'Control.Lens.Traversal.Traversal' s t a b -> (a -> f b) -> s -> f t+-- t 'pure' ≡ 'pure'+-- 'fmap' (t f) '.' t g ≡ 'Data.Functor.Compose.getCompose' '.' t ('Data.Functor.Compose.Compose' '.' 'fmap' f '.' g) -- @ ----- It may be beneficial to think about it as if it had these even more--- restrictive types, however:------ When applied to a 'Control.Lens.Traversal.Traversal', it can edit the--- targets of the 'Traversals', extracting a supplemental monoidal summary--- of its actions, by choosing @f = ((,) m)@------ @--- ('%%~') ::             'Control.Lens.Iso.Iso' s t a b       -> (a -> (r, b)) -> s -> (r, t)--- ('%%~') ::             'Lens' s t a b      -> (a -> (r, b)) -> s -> (r, t)--- ('%%~') :: 'Monoid' m => 'Control.Lens.Traversal.Traversal' s t a b -> (a -> (m, b)) -> s -> (m, t)+-- One consequence of this requirement is that a 'Traversal' needs to leave the same number of elements as a+-- candidate for subsequent 'Traversal' that it started with. Another testament to the strength of these laws+-- is that the caveat expressed in section 5.5 of the \"Essence of the Iterator Pattern\" about exotic+-- 'Data.Traversable.Traversable' instances that 'Data.Traversable.traverse' the same entry multiple times was actually already ruled out by the+-- second law in that same paper!+type Traversal s t a b = forall f. Applicative f => (a -> f b) -> s -> f t++-- | @+-- type 'Traversal'' = 'Simple' 'Traversal' -- @-(%%~) :: LensLike f s t a b -> (a -> f b) -> s -> f t-(%%~) = id-{-# INLINE (%%~) #-}+type Traversal' s a = Traversal s s a a --- | Modify the target of a 'Lens' in the current state returning some extra--- information of type @r@ or modify all targets of a--- 'Control.Lens.Traversal.Traversal' in the current state, extracting extra--- information of type @r@ and return a monoidal summary of the changes.------ >>> runState (_1 %%= \x -> (f x, g x)) (a,b)--- (f a,(g a,b))------ @('%%=') ≡ ('state' '.')@+-- | Every 'IndexedTraversal' is a valid 'Control.Lens.Traversal.Traversal' or+-- 'Control.Lens.Fold.IndexedFold'. ----- It may be useful to think of ('%%='), instead, as having either of the--- following more restricted type signatures:+-- The 'Indexed' constraint is used to allow an 'IndexedTraversal' to be used+-- directly as a 'Control.Lens.Traversal.Traversal'. --+-- The 'Control.Lens.Traversal.Traversal' laws are still required to hold.+type IndexedTraversal i s t a b = forall p f. (Indexable i p, Applicative f) => p a (f b) -> s -> f t++-- | @+-- type 'IndexedTraversal'' i = 'Simple' ('IndexedTraversal' i) -- @--- ('%%=') :: 'MonadState' s m             => 'Control.Lens.Iso.Iso' s s a b       -> (a -> (r, b)) -> m r--- ('%%=') :: 'MonadState' s m             => 'Lens' s s a b      -> (a -> (r, b)) -> m r--- ('%%=') :: ('MonadState' s m, 'Monoid' r) => 'Control.Lens.Traversal.Traversal' s s a b -> (a -> (r, b)) -> m r+type IndexedTraversal' i s a = IndexedTraversal i s s a a++-- | An 'IndexPreservingLens' leaves any index it is composed with alone.+type IndexPreservingTraversal s t a b = forall p f. (Conjoined p, Applicative f) => p a (f b) -> p s (f t)++-- | @+-- type 'IndexPreservingTraversal'' = 'Simple' 'IndexPreservingTraversal' -- @-(%%=) :: MonadState s m => LensLike ((,) r) s s a b -> (a -> (r, b)) -> m r-#if MIN_VERSION_mtl(2,1,1)-l %%= f = State.state (l f)-#else-l %%= f = do-  (r, s) <- State.gets (l f)-  State.put s-  return r-#endif-{-# INLINE (%%=) #-}+type IndexPreservingTraversal' s a = IndexPreservingTraversal s s a a ----------------------------------------------------------------------------------- Common Lenses--------------------------------------------------------------------------------+------------------------------------------------------------------------------+-- Setters+------------------------------------------------------------------------------ --- | Lift a 'Lens' so it can run under a function.+-- | The only 'LensLike' law that can apply to a 'Setter' @l@ is that ---inside :: LensLike (Context a b) s t a b -> Lens (e -> s) (e -> t) (e -> a) (e -> b)-inside l f es = o <$> f i where-  i e = case l (Context id) (es e) of Context _ a -> a-  o ea e = case l (Context id) (es e) of Context k _ -> k (ea e)---- | Merge two lenses, getters, setters, folds or traversals.+-- @+-- 'Control.Lens.Setter.set' l y ('Control.Lens.Setter.set' l x a) ≡ 'Control.Lens.Setter.set' l y a+-- @ ----- @'chosen' ≡ 'choosing' 'id' 'id'@+-- You can't 'Control.Lens.Getter.view' a 'Setter' in general, so the other two laws are irrelevant. --+-- However, two 'Functor' laws apply to a 'Setter':+-- -- @--- 'choosing' :: 'Control.Lens.Getter.Getter' s a           -> 'Control.Lens.Getter.Getter' s' a           -> 'Control.Lens.Getter.Getter' ('Either' s s') a--- 'choosing' :: 'Control.Lens.Fold.Fold' s a             -> 'Control.Lens.Fold.Fold' s' a             -> 'Control.Lens.Fold.Fold' ('Either' s s') a--- 'choosing' :: 'Simple' 'Lens' s a      -> 'Simple' 'Lens' s' a      -> 'Simple' 'Lens' ('Either' s s') a--- 'choosing' :: 'Simple' 'Control.Lens.Traversal.Traversal' s a -> 'Simple' 'Control.Lens.Traversal.Traversal' s' a -> 'Simple' 'Control.Lens.Traversal.Traversal' ('Either' s s') a--- 'choosing' :: 'Simple' 'Control.Lens.Setter.Setter' s a    -> 'Simple' 'Control.Lens.Setter.Setter' s' a    -> 'Simple' 'Control.Lens.Setter.Setter' ('Either' s s') a+-- 'Control.Lens.Setter.over' l 'id' ≡ 'id'+-- 'Control.Lens.Setter.over' l f '.' 'Control.Lens.Setter.over' l g ≡ 'Control.Lens.Setter.over' l (f '.' g) -- @-choosing :: Functor f-       => LensLike f s t a b-       -> LensLike f s' t' a b-       -> LensLike f (Either s s') (Either t t') a b-choosing l _ f (Left a)   = Left <$> l f a-choosing _ r f (Right a') = Right <$> r f a'-{-# INLINE choosing #-}---- | This is a 'Lens' that updates either side of an 'Either', where both sides have the same type. ----- @'chosen' ≡ 'choosing' 'id' 'id'@+-- These can be stated more directly: ----- >>> Left a^.chosen--- a+-- @+-- l 'pure' ≡ 'pure'+-- l f '.' 'untainted' '.' l g ≡ l (f '.' 'untainted' '.' g)+-- @ ----- >>> Right a^.chosen--- a+-- You can compose a 'Setter' with a 'Lens' or a 'Traversal' using ('.') from the @Prelude@+-- and the result is always only a 'Setter' and nothing more. ----- >>> Right "hello"^.chosen--- "hello"+-- >>> over traverse f [a,b,c,d]+-- [f a,f b,f c,f d] ----- >>> Right a & chosen *~ b--- Right (a * b)-chosen :: Lens (Either a a) (Either b b) a b-chosen f (Left a) = Left <$> f a-chosen f (Right a) = Right <$> f a-{-# INLINE chosen #-}---- | 'alongside' makes a 'Lens' from two other lenses.+-- >>> over _1 f (a,b)+-- (f a,b) ----- >>> (Left a, Right b)^.alongside chosen chosen--- (a,b)+-- >>> over (traverse._1) f [(a,b),(c,d)]+-- [(f a,b),(f c,d)] ----- >>> (Left a, Right b) & alongside chosen chosen .~ (c,d)--- (Left c,Right d)+-- >>> over both f (a,b)+-- (f a,f b) ----- @'alongside' :: 'Lens' s t a b -> 'Lens' s' t' a' b' -> 'Lens' (s,s') (t,t') (a,a') (b,b')@-alongside :: LensLike (Context a b) s t a b-           -> LensLike (Context a' b')  s' t' a' b'-           -> Lens (s,s') (t,t') (a,a') (b,b')-alongside l r f (s, s') = case l (Context id) s of-  Context bt a -> case r (Context id) s' of-    Context bt' a' -> f (a,a') <&> \(b,b') -> (bt b, bt' b')-{-# INLINE alongside #-}+-- >>> over (traverse.both) f [(a,b),(c,d)]+-- [(f a,f b),(f c,f d)]+type Setter s t a b = forall f. Settable f => (a -> f b) -> s -> f t --- | This 'Lens' lets you 'view' the current 'pos' of any 'Store'--- 'Comonad' and 'seek' to a new position. This reduces the API--- for working with a 'ComonadStore' instances to a single 'Lens'.+-- | A 'Setter'' is just a 'Setter' that doesn't change the types. --+-- These are particularly common when talking about monomorphic containers. /e.g./+-- -- @--- 'pos' w ≡ w '^.' 'locus'--- 'seek' s w ≡ w '&' 'locus' '.~' s--- 'seeks' f w ≡ w '&' 'locus' '%~' f+-- 'sets' Data.Text.map :: 'Setter'' 'Data.Text.Internal.Text' 'Char' -- @ -- -- @--- 'locus' :: Simple Lens ('Context' s s a) s+-- type 'Setter'' = 'Setter'' -- @-locus :: ComonadStore s w => Simple Lens (w a) s-locus f w = (`seek` w) <$> f (pos w)------------------------------------------------------------------------------------ Cloning Lenses--------------------------------------------------------------------------------+type Setter' s a = Setter s s a a --- |--- Cloning a 'Lens' is one way to make sure you aren't given--- something weaker, such as a 'Control.Lens.Traversal.Traversal' and can be--- used as a way to pass around lenses that have to be monomorphic in @f@.------ Note: This only accepts a proper 'Lens'.+-- | Every 'IndexedSetter' is a valid 'Setter'. ----- >>> let example l x = set (cloneLens l) (x^.cloneLens l + 1) x in example _2 ("hello",1,"you")--- ("hello",2,"you")-cloneLens :: Functor f-  => LensLike (Context a b) s t a b-  -> (a -> f b) -> s -> f t-cloneLens f afb s = case f (Context id) s of-  Context bt a -> bt <$> afb a-{-# INLINE cloneLens #-}+-- The 'Setter' laws are still required to hold.+type IndexedSetter i s t a b = forall f p.+  (Indexable i p, Settable f) => p a (f b) -> s -> f t ----------------------------------------------------------------------------------- Overloading function application--------------------------------------------------------------------------------+-- | @+-- type 'IndexedSetter'' i = 'Simple' ('IndexedSetter' i)+-- @+type IndexedSetter' i s a = IndexedSetter i s s a a --- | @type 'LensLike' f s t a b = 'Overloaded' (->) f s t a b@-type Overloaded k f s t a b = k (a -> f b) (s -> f t)+-- | An 'IndexPreservingSetter' can be composed with a 'IndexedSetter', 'IndexedTraversal' or 'IndexedLens'+-- and leaves the index intact, yielding an 'IndexedSetter'.+type IndexPreservingSetter s t a b = forall p f. (Conjoined p, Settable f) => p a (f b) -> p s (f t) --- | @type 'SimpleOverloaded' k f s a = 'Simple' ('Overloaded' k f) s a@-type SimpleOverloaded k f s a = Overloaded k f s s a a+-- | @+-- type 'IndexedPreservingSetter'' i = 'Simple' 'IndexedPreservingSetter'+-- @+type IndexPreservingSetter' s a = IndexPreservingSetter s s a a ----------------------------------------------------------------------------------- Setting and Remembering--------------------------------------------------------------------------------+-----------------------------------------------------------------------------+-- Isomorphisms+----------------------------------------------------------------------------- --- | Modify the target of a 'Lens' and return the result------ When you do not need the result of the addition, ('Control.Lens.Setter.%~') is more flexible.+-- | Isomorphism families can be composed with another 'Lens' using ('.') and 'id'. ----- @--- ('<%~') ::             'Lens' s t a b      -> (a -> b) -> s -> (b, t)--- ('<%~') ::             'Control.Lens.Iso.Iso' s t a b       -> (a -> b) -> s -> (b, t)--- ('<%~') :: 'Monoid' b => 'Control.Lens.Traversal.Traversal' s t a b -> (a -> b) -> s -> (b, t)+-- Note: Composition with an 'Iso' is index- and measure- preserving.+type Iso s t a b = forall p f. (Profunctor p, Functor f) => p a (f b) -> p s (f t)++-- | @+-- type 'Iso'' = 'Control.Lens.Type.Simple' 'Iso' -- @-(<%~) :: LensLike ((,)b) s t a b -> (a -> b) -> s -> (b, t)-l <%~ f = l $ \s -> let t = f s in (t, t)-{-# INLINE (<%~) #-}+type Iso' s a = Iso s s a a --- | Increment the target of a numerically valued 'Lens' and return the result+------------------------------------------------------------------------------+-- Prism Internals+------------------------------------------------------------------------------++-- | A 'Prism' @l@ is a 0-or-1 target 'Traversal' that can also be turned+-- around with 'Control.Lens.Review.re' to obtain a 'Getter' in the+-- opposite direction. ----- When you do not need the result of the addition, ('Control.Lens.Setter.+~') is more flexible.+-- There are two laws that a 'Prism' should satisfy: --+-- First, if I 'Control.Lens.Review.re' or 'Control.Lens.Prism.review' a value with a 'Prism' and then 'Control.Lens.Prism.preview' or use ('Control.Lens.Fold.^?'), I will get it back:+-- -- @--- ('<+~') :: 'Num' a => 'Simple' 'Lens' s a -> a -> s -> (a, s)--- ('<+~') :: 'Num' a => 'Simple' 'Control.Lens.Iso.Iso' s a  -> a -> s -> (a, s)+-- 'Control.Lens.Prism.preview' l ('Control.Lens.Prism.review' l b) ≡ 'Just' b -- @-(<+~) :: Num a => LensLike ((,)a) s t a a -> a -> s -> (a, t)-l <+~ a = l <%~ (+ a)-{-# INLINE (<+~) #-}---- | Decrement the target of a numerically valued 'Lens' and return the result ----- When you do not need the result of the subtraction, ('Control.Lens.Setter.-~') is more flexible.+-- Second, if you can extract a value @a@ using a 'Prism' @l@ from a value @s@, then the value @s@ is completely described my @l@ and @a@: ----- @--- ('<-~') :: 'Num' a => 'Simple' 'Lens' s a -> a -> s -> (a, s)--- ('<-~') :: 'Num' a => 'Simple' 'Control.Lens.Iso.Iso' s a  -> a -> s -> (a, s)--- @-(<-~) :: Num a => LensLike ((,)a) s t a a -> a -> s -> (a, t)-l <-~ a = l <%~ subtract a-{-# INLINE (<-~) #-}---- | Multiply the target of a numerically valued 'Lens' and return the result+-- If @'Control.Lens.Prism.preview' l s ≡ 'Just' a@ then @'Control.Lens.Prism.review' l a ≡ s@ ----- When you do not need the result of the multiplication, ('Control.Lens.Setter.*~') is more--- flexible.+-- These two laws imply that the 'Traversal' laws hold for every 'Prism' and that we 'Data.Traversable.traverse' at most 1 element: -- -- @--- ('<*~') :: 'Num' b => 'Simple' 'Lens' s a -> a -> a -> (s, a)--- ('<*~') :: 'Num' b => 'Simple' 'Control.Lens.Iso.Iso' s a -> a -> a -> (s, a))+-- 'Control.Lens.Fold.lengthOf' l x '<=' 1 -- @-(<*~) :: Num a => LensLike ((,)a) s t a a -> a -> s -> (a, t)-l <*~ a = l <%~ (* a)-{-# INLINE (<*~) #-}---- | Divide the target of a fractionally valued 'Lens' and return the result. ----- When you do not need the result of the division, ('Control.Lens.Setter.//~') is more flexible.+-- It may help to think of this as a 'Iso' that can be partial in one direction. ----- @--- ('<//~') :: 'Fractional' b => 'Simple' 'Lens' s a -> a -> a -> (s, a)--- ('<//~') :: 'Fractional' b => 'Simple' 'Control.Lens.Iso.Iso' s a -> a -> a -> (s, a))--- @-(<//~) :: Fractional a => LensLike ((,)a) s t a a -> a -> s -> (a, t)-l <//~ a = l <%~ (/ a)-{-# INLINE (<//~) #-}---- | Raise the target of a numerically valued 'Lens' to a non-negative--- 'Integral' power and return the result+-- Every 'Prism' is a valid 'Traversal'. ----- When you do not need the result of the division, ('Control.Lens.Setter.^~') is more flexible.+-- Every 'Iso' is a valid 'Prism'. ----- @--- ('<^~') :: ('Num' b, 'Integral' e) => 'Simple' 'Lens' s a -> e -> a -> (a, s)--- ('<^~') :: ('Num' b, 'Integral' e) => 'Simple' 'Control.Lens.Iso.Iso' s a -> e -> a -> (a, s)--- @-(<^~) :: (Num a, Integral e) => LensLike ((,)a) s t a a -> e -> s -> (a, t)-l <^~ e = l <%~ (^ e)-{-# INLINE (<^~) #-}---- | Raise the target of a fractionally valued 'Lens' to an 'Integral' power--- and return the result.+-- For example, you might have a @'Prism'' 'Integer' 'Numeric.Natural.Natural'@ allows you to always+-- go from a 'Numeric.Natural.Natural' to an 'Integer', and provide you with tools to check if an 'Integer' is+-- a 'Numeric.Natural.Natural' and/or to edit one if it is. ----- When you do not need the result of the division, ('Control.Lens.Setter.^^~') is more flexible. -- -- @--- ('<^^~') :: ('Fractional' b, 'Integral' e) => 'Simple' 'Lens' s a -> e -> a -> (a, s)--- ('<^^~') :: ('Fractional' b, 'Integral' e) => 'Simple' 'Control.Lens.Iso.Iso' s a -> e -> a -> (a, s)+-- 'nat' :: 'Prism'' 'Integer' 'Numeric.Natural.Natural'+-- 'nat' = 'Control.Lens.Prism.prism' 'toInteger' '$' \\ i ->+--    if i '<' 0+--    then 'Left' i+--    else 'Right' ('fromInteger' i) -- @-(<^^~) :: (Fractional a, Integral e) => LensLike ((,)a) s t a a -> e -> s -> (a, t)-l <^^~ e = l <%~ (^^ e)-{-# INLINE (<^^~) #-}---- | Raise the target of a floating-point valued 'Lens' to an arbitrary power--- and return the result. ----- When you do not need the result of the division, ('Control.Lens.Setter.**~') is more flexible.+-- Now we can ask if an 'Integer' is a 'Numeric.Natural.Natural'. ----- @--- ('<**~') :: 'Floating' a => 'Simple' 'Lens' s a -> a -> s -> (a, s)--- ('<**~') :: 'Floating' a => 'Simple' 'Control.Lens.Iso.Iso' s a  -> a -> s -> (a, s)--- @-(<**~) :: Floating a => LensLike ((,)a) s t a a -> a -> s -> (a, t)-l <**~ a = l <%~ (** a)-{-# INLINE (<**~) #-}---- | Logically '||' a Boolean valued 'Lens' and return the result+-- >>> 5^?nat+-- Just 5 ----- When you do not need the result of the operation, ('Control.Lens.Setter.||~') is more flexible.+-- >>> (-5)^?nat+-- Nothing ----- @--- ('<||~') :: 'Simple' 'Lens' s 'Bool' -> 'Bool' -> s -> ('Bool', s)--- ('<||~') :: 'Simple' 'Control.Lens.Iso.Iso' s 'Bool'  -> 'Bool' -> s -> ('Bool', s)--- @-(<||~) :: LensLike ((,)Bool) s t Bool Bool -> Bool -> s -> (Bool, t)-l <||~ b = l <%~ (|| b)-{-# INLINE (<||~) #-}---- | Logically '&&' a Boolean valued 'Lens' and return the result+-- We can update the ones that are: ----- When you do not need the result of the operation, ('Control.Lens.Setter.&&~') is more flexible.+-- >>> (-3,4) & both.nat *~ 2+-- (-3,8) ----- @--- ('<&&~') :: 'Simple' 'Lens' s 'Bool' -> 'Bool' -> s -> ('Bool', s)--- ('<&&~') :: 'Simple' 'Control.Lens.Iso.Iso' s 'Bool'  -> 'Bool' -> s -> ('Bool', s)--- @-(<&&~) :: LensLike ((,)Bool) s t Bool Bool -> Bool -> s -> (Bool, t)-l <&&~ b = l <%~ (&& b)-{-# INLINE (<&&~) #-}---- | Modify the target of a 'Lens', but return the old value.+-- And we can then convert from a 'Numeric.Natural.Natural' to an 'Integer'. ----- When you do not need the result of the addition, ('Control.Lens.Setter.%~') is more flexible.+-- >>> 5 ^. re nat -- :: Natural+-- 5 ----- @--- ('<<%~') ::             'Lens' s t a b      -> (a -> b) -> s -> (b, t)--- ('<<%~') ::             'Control.Lens.Iso.Iso' s t a b       -> (a -> b) -> s -> (b, t)--- ('<<%~') :: 'Monoid' b => 'Control.Lens.Traversal.Traversal' s t a b -> (a -> b) -> s -> (b, t)--- @-(<<%~) :: LensLike ((,)a) s t a b -> (a -> b) -> s -> (a, t)-l <<%~ f = l $ \a -> (a, f a)-{-# INLINE (<<%~) #-}---- | Modify the target of a 'Lens', but return the old value.+-- Similarly we can use a 'Prism' to 'Data.Traversable.traverse' the 'Left' half of an 'Either': ----- When you do not need the old value, ('Control.Lens.Setter.%~') is more flexible.+-- >>> Left "hello" & _Left %~ length+-- Left 5 ----- @--- ('<<%~') ::             'Lens' s t a b      -> b -> s -> (a, t)--- ('<<%~') ::             'Control.Lens.Iso.Iso' s t a b       -> b -> s -> (a, t)--- ('<<%~') :: 'Monoid' b => 'Control.Lens.Traversal.Traversal' s t a b -> b -> s -> (a, t)--- @-(<<.~) :: LensLike ((,)a) s t a b -> b -> s -> (a, t)-l <<.~ b = l $ \a -> (a, b)-{-# INLINE (<<.~) #-}+-- or to construct an 'Either':+--+-- >>> 5^.re _Left+-- Left 5+--+-- such that if you query it with the 'Prism', you will get your original input back.+--+-- >>> 5^.re _Left ^? _Left+-- Just 5+--+-- Another interesting way to think of a 'Prism' is as the categorical dual of a 'Lens'+-- -- a co-'Lens', so to speak. This is what permits the construction of 'Control.Lens.Prism.outside'.+--+-- Note: Composition with a 'Prism' is index-preserving.+type Prism s t a b = forall p f. (Choice p, Applicative f) => p a (f b) -> p s (f t) +-- | A 'Simple' 'Prism'.+type Prism' s a = Prism s s a a+ ---------------------------------------------------------------------------------- Setting and Remembering State+-- Equality ------------------------------------------------------------------------------- --- | Modify the target of a 'Lens' into your monad's state by a user supplied--- function and return the result.------ When applied to a 'Control.Lens.Traversal.Traversal', it this will return a monoidal summary of all of the intermediate--- results.------ When you do not need the result of the operation, ('Control.Lens.Setter.%=') is more flexible.+-- | A witness that @(a ~ s, b ~ t)@. ----- @--- ('<%=') :: 'MonadState' s m             => 'Simple' 'Lens' s a     -> (a -> a) -> m a--- ('<%=') :: 'MonadState' s m             => 'Simple' 'Control.Lens.Iso.Iso' s a      -> (a -> a) -> m a--- ('<%=') :: ('MonadState' s m, 'Monoid' a) => 'Simple' 'Traversal' s a -> (a -> a) -> m a--- @-(<%=) :: MonadState s m => LensLike ((,)b) s s a b -> (a -> b) -> m b-l <%= f = l %%= \a -> let b = f a in (b,b)-{-# INLINE (<%=) #-}+-- Note: Composition with an 'Equality' is index-preserving.+type Equality s t a b = forall p (f :: * -> *). p a (f b) -> p s (f t) +-- | A 'Simple' 'Equality'.+type Equality' s a = Equality s s a a --- | Add to the target of a numerically valued 'Lens' into your monad's state--- and return the result.+-------------------------------------------------------------------------------+-- Getters+-------------------------------------------------------------------------------++-- | A 'Getter' describes how to retrieve a single value in a way that can be+-- composed with other 'LensLike' constructions. ----- When you do not need the result of the addition, ('Control.Lens.Setter.+=') is more--- flexible.+-- Unlike a 'Lens' a 'Getter' is read-only. Since a 'Getter'+-- cannot be used to write back there are no 'Lens' laws that can be applied to+-- it. In fact, it is isomorphic to an arbitrary function from @(a -> s)@. ----- @--- ('<+=') :: ('MonadState' s m, 'Num' a) => 'Simple' 'Lens' s a -> a -> m a--- ('<+=') :: ('MonadState' s m, 'Num' a) => 'Simple' 'Control.Lens.Iso.Iso' s a -> a -> m a--- @-(<+=) :: (MonadState s m, Num a) => SimpleLensLike ((,)a) s a -> a -> m a-l <+= a = l <%= (+ a)-{-# INLINE (<+=) #-}+-- Moreover, a 'Getter' can be used directly as a 'Control.Lens.Fold.Fold',+-- since it just ignores the 'Applicative'.+type Getter s a = forall f. Gettable f => (a -> f a) -> s -> f s --- | Subtract from the target of a numerically valued 'Lens' into your monad's--- state and return the result.+-- | Every 'IndexedGetter' is a valid 'Control.Lens.Fold.IndexedFold' and can be used for 'Control.Lens.Getter.Getting' like a 'Getter'.+type IndexedGetter i s a = forall p f. (Indexable i p, Gettable f) => p a (f a) -> s -> f s++-- | An 'IndexPreservingGetter' can be used as a 'Getter', but when composed with an 'IndexedTraversal',+-- 'IndexedFold', or 'IndexedLens' yields an 'IndexedFold', 'IndexedFold' or 'IndexedGetter' respectively.+type IndexPreservingGetter s a = forall p f. (Conjoined p, Gettable f) => p a (f a) -> p s (f s)++--------------------------+-- Folds+--------------------------++-- | A 'Fold' describes how to retrieve multiple values in a way that can be composed+-- with other 'LensLike' constructions. ----- When you do not need the result of the subtraction, ('Control.Lens.Setter.-=') is more--- flexible.+-- A @'Fold' s a@ provides a structure with operations very similar to those of the 'Data.Foldable.Foldable'+-- typeclass, see 'Control.Lens.Fold.foldMapOf' and the other 'Fold' combinators. ----- @--- ('<-=') :: ('MonadState' s m, 'Num' a) => 'Simple' 'Lens' s a -> a -> m a--- ('<-=') :: ('MonadState' s m, 'Num' a) => 'Simple' 'Control.Lens.Iso.Iso' s a -> a -> m a--- @-(<-=) :: (MonadState s m, Num a) => SimpleLensLike ((,)a) s a -> a -> m a-l <-= a = l <%= subtract a-{-# INLINE (<-=) #-}---- | Multiply the target of a numerically valued 'Lens' into your monad's--- state and return the result.+-- By convention, if there exists a 'foo' method that expects a @'Data.Foldable.Foldable' (f a)@, then there should be a+-- @fooOf@ method that takes a @'Fold' s a@ and a value of type @s@. ----- When you do not need the result of the multiplication, ('Control.Lens.Setter.*=') is more--- flexible.+-- A 'Getter' is a legal 'Fold' that just ignores the supplied 'Data.Monoid.Monoid'. ----- @--- ('<*=') :: ('MonadState' s m, 'Num' a) => 'Simple' 'Lens' s a -> a -> m a--- ('<*=') :: ('MonadState' s m, 'Num' a) => 'Simple' 'Control.Lens.Iso.Iso' s a -> a -> m a--- @-(<*=) :: (MonadState s m, Num a) => SimpleLensLike ((,)a) s a -> a -> m a-l <*= a = l <%= (* a)-{-# INLINE (<*=) #-}+-- Unlike a 'Control.Lens.Traversal.Traversal' a 'Fold' is read-only. Since a 'Fold' cannot be used to write back+-- there are no 'Lens' laws that apply.+type Fold s a = forall f. (Gettable f, Applicative f) => (a -> f a) -> s -> f s --- | Divide the target of a fractionally valued 'Lens' into your monad's state--- and return the result.+-- | Every 'IndexedFold' is a valid 'Control.Lens.Fold.Fold' and can be used for 'Control.Lens.Getter.Getting'.+type IndexedFold i s a = forall p f.  (Indexable i p, Applicative f, Gettable f) => p a (f a) -> s -> f s++-- | An 'IndexPreservingFold' can be used as a 'Fold', but when composed with an 'IndexedTraversal',+-- 'IndexedFold', or 'IndexedLens' yields an 'IndexedFold' respectively.+type IndexPreservingFold s a = forall p f. (Conjoined p, Gettable f, Applicative f) => p a (f a) -> p s (f s)++-------------------------------------------------------------------------------+-- Actions+-------------------------------------------------------------------------------++-- | An 'Action' is a 'Getter' enriched with access to a 'Monad' for side-effects. ----- When you do not need the result of the division, ('Control.Lens.Setter.//=') is more flexible.+-- Every 'Getter' can be used as an 'Action'. ----- @--- ('<//=') :: ('MonadState' s m, 'Fractional' a) => 'Simple' 'Lens' s a -> a -> m a--- ('<//=') :: ('MonadState' s m, 'Fractional' a) => 'Simple' 'Control.Lens.Iso.Iso' s a -> a -> m a--- @-(<//=) :: (MonadState s m, Fractional a) => SimpleLensLike ((,)a) s a -> a -> m a-l <//= a = l <%= (/ a)-{-# INLINE (<//=) #-}+-- You can compose an 'Action' with another 'Action' using ('Prelude..') from the @Prelude@.+type Action m s a = forall f r. Effective m r f => (a -> f a) -> s -> f s --- | Raise the target of a numerically valued 'Lens' into your monad's state--- to a non-negative 'Integral' power and return the result.+-- | An 'IndexedAction' is an 'IndexedGetter' enriched with access to a 'Monad' for side-effects. ----- When you do not need the result of the operation, ('Control.Lens.Setter.**=') is more flexible.+-- Every 'Getter' can be used as an 'Action'. ----- @--- ('<^=') :: ('MonadState' s m, 'Num' a, 'Integral' e) => 'Simple' 'Lens' s a -> e -> m a--- ('<^=') :: ('MonadState' s m, 'Num' a, 'Integral' e) => 'Simple' 'Control.Lens.Iso.Iso' s a -> e -> m a--- @-(<^=) :: (MonadState s m, Num a, Integral e) => SimpleLensLike ((,)a) s a -> e -> m a-l <^= e = l <%= (^ e)-{-# INLINE (<^=) #-}+-- You can compose an 'Action' with another 'Action' using ('Prelude..') from the @Prelude@.+type IndexedAction i m s a = forall p f r. (Indexable i p, Effective m r f) => p a (f a) -> s -> f s --- | Raise the target of a fractionally valued 'Lens' into your monad's state--- to an 'Integral' power and return the result.+-- | An 'IndexPreservingAction' can be used as a 'Action', but when composed with an 'IndexedTraversal',+-- 'IndexedFold', or 'IndexedLens' yields an 'IndexedMonadicFold', 'IndexedMonadicFold' or 'IndexedAction' respectively.+type IndexPreservingAction m s a = forall p f r. (Conjoined p, Effective m r f) => p a (f a) -> p s (f s)++-------------------------------------------------------------------------------+-- MonadicFolds+-------------------------------------------------------------------------------++-- | A 'MonadicFold' is a 'Fold' enriched with access to a 'Monad' for side-effects. ----- When you do not need the result of the operation, ('Control.Lens.Setter.^^=') is more flexible.+-- Every 'Fold' can be used as a 'MonadicFold', that simply ignores the access to the 'Monad'. ----- @--- ('<^^=') :: ('MonadState' s m, 'Fractional' b, 'Integral' e) => 'Simple' 'Lens' s a -> e -> m a--- ('<^^=') :: ('MonadState' s m, 'Fractional' b, 'Integral' e) => 'Simple' 'Control.Lens.Iso.Iso' s a  -> e -> m a--- @-(<^^=) :: (MonadState s m, Fractional a, Integral e) => SimpleLensLike ((,)a) s a -> e -> m a-l <^^= e = l <%= (^^ e)-{-# INLINE (<^^=) #-}+-- You can compose a 'MonadicFold' with another 'MonadicFold' using ('Prelude..') from the @Prelude@.+type MonadicFold m s a = forall f r. (Effective m r f, Applicative f) => (a -> f a) -> s -> f s --- | Raise the target of a floating-point valued 'Lens' into your monad's--- state to an arbitrary power and return the result.+-- | An 'IndexedMonadicFold' is an 'IndexedFold' enriched with access to a 'Monad' for side-effects. ----- When you do not need the result of the operation, ('Control.Lens.Setter.**=') is more flexible.+-- Every 'IndexedFold' can be used as an 'IndexedMonadicFold', that simply ignores the access to the 'Monad'. ----- @--- ('<**=') :: ('MonadState' s m, 'Floating' a) => 'Simple' 'Lens' s a -> a -> m a--- ('<**=') :: ('MonadState' s m, 'Floating' a) => 'Simple' 'Control.Lens.Iso.Iso' s a -> a -> m a--- @-(<**=) :: (MonadState s m, Floating a) => SimpleLensLike ((,)a) s a -> a -> m a-l <**= a = l <%= (** a)-{-# INLINE (<**=) #-}+-- You can compose an 'IndexedMonadicFold' with another 'IndexedMonadicFold' using ('Prelude..') from the @Prelude@.+type IndexedMonadicFold i m s a = forall p f r. (Indexable i p, Effective m r f, Applicative f) => p a (f a) -> s -> f s --- | Logically '||' a Boolean valued 'Lens' into your monad's state and return--- the result.------ When you do not need the result of the operation, ('Control.Lens.Setter.||=') is more flexible.+-- | An 'IndexPreservingFold' can be used as a 'Fold', but when composed with an 'IndexedTraversal',+-- 'IndexedFold', or 'IndexedLens' yields an 'IndexedFold' respectively.+type IndexPreservingMonadicFold m s a = forall p f r. (Conjoined p, Effective m r f, Applicative f) => p a (f a) -> p s (f s)++-------------------------------------------------------------------------------+-- Simple Overloading+-------------------------------------------------------------------------------++-- | A 'Simple' 'Lens', 'Simple' 'Traversal', ... can+-- be used instead of a 'Lens','Traversal', ...+-- whenever the type variables don't change upon setting a value. -- -- @--- ('<||=') :: 'MonadState' s m => 'Simple' 'Lens' s 'Bool' -> 'Bool' -> m 'Bool'--- ('<||=') :: 'MonadState' s m => 'Simple' 'Control.Lens.Iso.Iso' s 'Bool'  -> 'Bool' -> m 'Bool'+-- 'Data.Complex.Lens.imaginary' :: 'Simple' 'Lens' ('Data.Complex.Complex' a) a+-- 'Data.List.Lens._head' :: 'Simple' 'IndexedTraversal' 'Int' [a] a -- @-(<||=) :: MonadState s m => SimpleLensLike ((,)Bool) s Bool -> Bool -> m Bool-l <||= b = l <%= (|| b)-{-# INLINE (<||=) #-}---- | Logically '&&' a Boolean valued 'Lens' into your monad's state and return--- the result. ----- When you do not need the result of the operation, ('Control.Lens.Setter.&&=') is more flexible.+-- Note: To use this alias in your own code with @'LensLike' f@ or+-- 'Setter', you may have to turn on @LiberalTypeSynonyms@. --+-- This is commonly abbreviated as a \"prime\" marker, /e.g./ 'Lens'' = 'Simple' 'Lens'.+type Simple f s a = f s s a a++-- | @+-- type 'LensLike' f s t a b = 'Overloading' (->) (->) f s t a b -- @--- ('<&&=') :: 'MonadState' s m => 'Simple' 'Lens' s 'Bool' -> 'Bool' -> m 'Bool'--- ('<&&=') :: 'MonadState' s m => 'Simple' 'Control.Lens.Iso.Iso' s 'Bool'  -> 'Bool' -> m 'Bool'+type Overloading p q f s t a b = p a (f b) -> q s (f t)++-- | @+-- type 'Overloading'' p q f s a = 'Simple' ('Overloading' p q f) s a -- @-(<&&=) :: MonadState s m => SimpleLensLike ((,)Bool) s Bool -> Bool -> m Bool-l <&&= b = l <%= (&& b)-{-# INLINE (<&&=) #-}+type Overloading' p q f s a = Overloading p q f s s a a --- | Modify the target of a 'Lens' into your monad's state by a user supplied--- function and return the /old/ value that was replaced.------ When applied to a 'Control.Lens.Traversal.Traversal', it this will return a monoidal summary of all of the old values--- present.------ When you do not need the result of the operation, ('Control.Lens.Setter.%=') is more flexible.---+-- | @+-- type 'LensLike' f s t a b = 'Overloaded' (->) f s t a b -- @--- ('<<%=') :: 'MonadState' s m             => 'Simple' 'Lens' s a     -> (a -> a) -> m a--- ('<<%=') :: 'MonadState' s m             => 'Simple' 'Control.Lens.Iso.Iso' s a      -> (a -> a) -> m a--- ('<<%=') :: ('MonadState' s m, 'Monoid' b) => 'Simple' 'Traversal' s a -> (a -> a) -> m a+type Overloaded p f s t a b = p a (f b) -> p s (f t)++-- | @+-- type 'Overloaded'' p q f s a = 'Simple' ('Overloaded' p q f) s a -- @-(<<%=) :: MonadState s m => LensLike ((,)a) s s a b -> (a -> b) -> m a-l <<%= f = l %%= \a -> (a, f a)-{-# INLINE (<<%=) #-}+type Overloaded' p f s a = Overloaded p f s s a a --- | Modify the target of a 'Lens' into your monad's state by a user supplied--- function and return the /old/ value that was replaced.+-- | Many combinators that accept a 'Lens' can also accept a+-- 'Traversal' in limited situations. ----- When applied to a 'Control.Lens.Traversal.Traversal', it this will return a monoidal summary of all of the old values--- present.+-- They do so by specializing the type of 'Functor' that they require of the+-- caller. ----- When you do not need the result of the operation, ('Control.Lens.Setter.%=') is more flexible.+-- If a function accepts a @'LensLike' f s t a b@ for some 'Functor' @f@,+-- then they may be passed a 'Lens'. ----- @--- ('<<%=') :: 'MonadState' s m             => 'Simple' 'Lens' s a     -> (a -> a) -> m a--- ('<<%=') :: 'MonadState' s m             => 'Simple' 'Control.Lens.Iso.Iso' s a      -> (a -> a) -> m a--- ('<<%=') :: ('MonadState' s m, 'Monoid' t) => 'Simple' 'Traversal' s a -> (a -> a) -> m a--- @-(<<.=) :: MonadState s m => LensLike ((,)a) s s a b -> b -> m a-l <<.= b = l %%= \a -> (a,b)-{-# INLINE (<<.=) #-}+-- Further, if @f@ is an 'Applicative', they may also be passed a+-- 'Traversal'.+type LensLike f s t a b = (a -> f b) -> s -> f t --- | Run a monadic action, and set the target of 'Lens' to its result.------ @--- ('<<~') :: 'MonadState' s m => 'Control.Lens.Iso.Iso' s s a b   -> m b -> m b--- ('<<~') :: 'MonadState' s m => 'Control.Lens.Type.Lens' s s a b  -> m b -> m b+-- | @+-- type 'LensLike'' f = 'Simple' ('LensLike' f) -- @------ NB: This is limited to taking an actual 'Lens' than admitting a 'Control.Lens.Traversal.Traversal' because--- there are potential loss of state issues otherwise.-(<<~) :: MonadState s m => LensLike (Context a b) s s a b -> m b -> m b-l <<~ mb = do-  b <- mb-  modify $ \s -> case l (Context id) s of Context f _ -> f b-  return b-{-# INLINE (<<~) #-}---- | 'mappend' a monoidal value onto the end of the target of a 'Lens' and--- return the result------ When you do not need the result of the operation, ('<>~') is more flexible.-(<<>~) :: Monoid m => LensLike ((,)m) s t m m -> m -> s -> (m, t)-l <<>~ m = l <%~ (`mappend` m)-{-# INLINE (<<>~) #-}+type LensLike' f s a = LensLike f s s a a --- | 'mappend' a monoidal value onto the end of the target of a 'Lens' into--- your monad's state and return the result.------ When you do not need the result of the operation, ('<>=') is more flexible.-(<<>=) :: (MonadState s m, Monoid r) => SimpleLensLike ((,)r) s r -> r -> m r-l <<>= r = l <%= (`mappend` r)-{-# INLINE (<<>=) #-}+-- | Convenient alias for constructing indexed lenses and their ilk.+type IndexedLensLike i f s t a b = forall p. Indexable i p => p a (f b) -> s -> f t +-- | Convenient alias for constructing simple indexed lenses and their ilk.+type IndexedLensLike' i f s a = IndexedLensLike i f s s a a --- | Useful for storing lenses in containers.-newtype ReifiedLens s t a b = ReifyLens { reflectLens :: Lens s t a b }+-- | This is a convenient alias for use when you need to consume either indexed or non-indexed lens-likes based on context.+type Over p f s t a b = p a (f b) -> s -> f t --- | @type 'SimpleReifiedLens' = 'Simple' 'ReifiedLens'@-type SimpleReifiedLens s a = ReifiedLens s s a a+-- | This is a convenient alias for use when you need to consume either indexed or non-indexed lens-likes based on context.+--+-- @+-- type 'Over'' p f = 'Simple' ('Over' p f)+-- @+type Over' p f s a = Over p f s s a a
− src/Control/Lens/WithIndex.hs
@@ -1,497 +0,0 @@-{-# LANGUAGE MagicHash #-}-{-# LANGUAGE CPP #-}-{-# LANGUAGE Rank2Types #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE FunctionalDependencies #-}-#ifdef DEFAULT_SIGNATURES-{-# LANGUAGE DefaultSignatures #-}-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ > 706-#define MPTC_DEFAULTS-#endif-#endif-#ifdef TRUSTWORTHY-{-# LANGUAGE Trustworthy #-} -- vector, hashable-#endif---#ifndef MIN_VERSION_containers-#define MIN_VERSION_containers(x,y,z) 1-#endif----------------------------------------------------------------------------------- |--- Module      :  Control.Lens.WithIndex--- Copyright   :  (C) 2012 Edward Kmett--- License     :  BSD-style (see the file LICENSE)--- Maintainer  :  Edward Kmett <ekmett@gmail.com>--- Stability   :  provisional--- Portability :  Rank2Types------ (These need to be defined together for @DefaultSignatures@ to work.)---------------------------------------------------------------------------------module Control.Lens.WithIndex-  (-  -- * Indexed Functors-    FunctorWithIndex(..)-  , imapped-  -- * Indexed Foldables-  , FoldableWithIndex(..)-  , ifolded-  , ifolding-  -- ** Indexed Foldable Combinators-  , iany-  , iall-  , itraverse_-  , ifor_-  , imapM_-  , iforM_-  , iconcatMap-  , ifind-  , ifoldrM-  , ifoldlM-  , itoList-  -- * Converting to Folds-  , withIndices-  , indices-  -- * Indexed Traversables-  , TraversableWithIndex(..)-  , itraversed-  -- * Indexed Traversable Combinators-  , ifor-  , imapM-  , iforM-  , imapAccumR-  , imapAccumL-  , iwhere-  ) where--import Control.Applicative-import Control.Applicative.Backwards-import Control.Monad (void, liftM)-import Control.Monad.Trans.State.Lazy as Lazy-import Control.Lens.Classes-import Control.Lens.Fold-import Control.Lens.Internal-import Control.Lens.Internal.Combinators-import Control.Lens.IndexedSetter-import Control.Lens.IndexedFold-import Control.Lens.IndexedTraversal-import Data.Foldable-import Data.Hashable-import Data.HashMap.Lazy as HashMap-import Data.IntMap as IntMap-import Data.Map as Map-import Data.Monoid-import Data.Sequence hiding (index)-import Data.Traversable-import Data.Vector (Vector)-import qualified Data.Vector as V---- $setup--- >>> import Control.Lens------------------------------------------------------------------------------------ FunctorWithIndex------------------------------------------------------------------------------------ | A 'Functor' with an additional index.------ Instances must satisfy a modified form of the 'Functor' laws:------ @--- 'imap' f '.' 'imap' g ≡ 'imap' (\i -> f i . g i)--- 'imap' (\_ a -> a) ≡ 'id'--- @-class Functor f => FunctorWithIndex i f | f -> i where-  -- | Map with access to the index.-  imap :: (i -> a -> b) -> f a -> f b-#ifdef MPTC_DEFAULTS-  default imap :: TraversableWithIndex i f => (i -> a -> b) -> f a -> f b-  imap = imapOf itraversed-  {-# INLINE imap #-}-#endif---- | The 'IndexedSetter' for a 'FunctorWithIndex'.------ If you don't need access to the index, then 'mapped' is more flexible in what it accepts.-imapped :: FunctorWithIndex i f => IndexedSetter i (f a) (f b) a b-imapped = isets imap-{-# INLINE imapped #-}------------------------------------------------------------------------------------ FoldableWithIndex------------------------------------------------------------------------------------ | A container that supports folding with an additional index.-class Foldable f => FoldableWithIndex i f | f -> i where-  ---  -- |-  -- Fold a container by mapping value to an arbitrary 'Monoid' with access to the index @i@.-  ---  -- When you don't need access to the index then 'foldMap' is more flexible in what it accepts.-  ---  -- @'foldMap' ≡ 'ifoldMap' '.' 'const'@-  ifoldMap :: Monoid m => (i -> a -> m) -> f a -> m-#ifdef MPTC_DEFAULTS-  default ifoldMap :: (TraversableWithIndex i f, Monoid m) => (i -> a -> m) -> f a -> m-  ifoldMap = ifoldMapOf itraversed-  {-# INLINE ifoldMap #-}-#endif--  -- | Right-associative fold of an indexed container with access to the index @i@.-  ---  -- When you don't need access to the index then 'Data.Foldable.foldr' is more flexible in what it accepts.-  ---  -- @'Data.Foldable.foldr' ≡ 'ifoldr' '.' 'const'@-  ifoldr   :: (i -> a -> b -> b) -> b -> f a -> b-  ifoldr f z t = appEndo (ifoldMap (\i -> endo# (f i)) t) z--  -- |-  -- Left-associative fold of an indexed container with access to the index @i@.-  ---  -- When you don't need access to the index then 'Data.Foldable.foldl' is more flexible in what it accepts.-  ---  -- @'Data.Foldable.foldl' ≡ 'ifoldl' '.' 'const'@-  ifoldl :: (i -> b -> a -> b) -> b -> f a -> b-  ifoldl f z t = appEndo (getDual (ifoldMap (\i -> dual# (endo# (flip (f i)))) t)) z--  -- | /Strictly/ fold right over the elements of a structure with access to the index @i@.-  ---  -- When you don't need access to the index then 'foldr'' is more flexible in what it accepts.-  ---  -- @'foldr'' ≡ 'ifoldr'' '.' 'const'@-  ifoldr' :: (i -> a -> b -> b) -> b -> f a -> b-  ifoldr' f z0 xs = ifoldl f' id xs z0-    where f' i k x z = k $! f i x z--  -- | Fold over the elements of a structure with an index, associating to the left, but /strictly/.-  ---  -- When you don't need access to the index then 'Control.Lens.Fold.foldlOf'' is more flexible in what it accepts.-  ---  -- @'Control.Lens.Fold.foldlOf'' l ≡ 'ifoldlOf'' l '.' 'const'@-  ifoldl' :: (i -> b -> a -> b) -> b -> f a -> b-  ifoldl' f z0 xs = ifoldr f' id xs z0-    where f' i x k z = k $! f i z x---- | The 'IndexedFold' of a 'FoldableWithIndex' container.-ifolded :: FoldableWithIndex i f => IndexedFold i (f a) a-ifolded = indexed $ \ f -> coerce . getFolding . ifoldMap (\i -> folding# (f i))-{-# INLINE ifolded #-}---- | Obtain a 'Fold' by lifting an operation that returns a foldable result.------ This can be useful to lift operations from @Data.List@ and elsewhere into a 'Fold'.-ifolding :: FoldableWithIndex i f => (s -> f a) -> IndexedFold i s a-ifolding sfa = indexed $ \ iagb -> coerce . itraverse_ iagb . sfa-{-# INLINE ifolding #-}---- |--- Return whether or not any element in a container satisfies a predicate, with access to the index @i@.------ When you don't need access to the index then 'any' is more flexible in what it accepts.------ @'any' ≡ 'iany' '.' 'const'@-iany :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Bool-iany f = getAny# (ifoldMap (\i -> any# (f i)))-{-# INLINE iany #-}---- |--- Return whether or not all elements in a container satisfy a predicate, with access to the index @i@.------ When you don't need access to the index then 'all' is more flexible in what it accepts.------ @'all' ≡ 'iall' '.' 'const'@-iall :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Bool-iall f = getAll# (ifoldMap (\i -> all# (f i)))-{-# INLINE iall #-}---- |--- Traverse elements with access to the index @i@, discarding the results.------ When you don't need access to the index then 'traverse_' is more flexible in what it accepts.------ @'traverse_' l = 'itraverse' '.' 'const'@-itraverse_ :: (FoldableWithIndex i t, Applicative f) => (i -> a -> f b) -> t a -> f ()-itraverse_ f = getTraversed# (ifoldMap (\i -> traversed# (void . f i)))-{-# INLINE itraverse_ #-}---- |--- Traverse elements with access to the index @i@, discarding the results (with the arguments flipped).------ @'ifor_' ≡ 'flip' 'itraverse_'@------ When you don't need access to the index then 'for_' is more flexible in what it accepts.------ @'for_' a ≡ 'ifor_' a '.' 'const'@-ifor_ :: (FoldableWithIndex i t, Applicative f) => t a -> (i -> a -> f b) -> f ()-ifor_ = flip itraverse_-{-# INLINE ifor_ #-}---- |--- Run monadic actions for each target of an 'IndexedFold' or 'Control.Lens.IndexedTraversal.IndexedTraversal' with access to the index,--- discarding the results.------ When you don't need access to the index then 'Control.Lens.Fold.mapMOf_' is more flexible in what it accepts.------ @'mapM_' ≡ 'imapM' '.' 'const'@-imapM_ :: (FoldableWithIndex i t, Monad m) => (i -> a -> m b) -> t a -> m ()-imapM_ f = getSequenced# (ifoldMap (\i -> sequenced# (liftM skip . f i)))-{-# INLINE imapM_ #-}---- |--- Run monadic actions for each target of an 'IndexedFold' or 'Control.Lens.IndexedTraversal.IndexedTraversal' with access to the index,--- discarding the results (with the arguments flipped).------ @'iforM_' ≡ 'flip' 'imapM_'@------ When you don't need access to the index then 'Control.Lens.Fold.forMOf_' is more flexible in what it accepts.------ @'Control.Lens.Fold.forMOf_' l a ≡ 'iforMOf' l a '.' 'const'@-iforM_ :: (FoldableWithIndex i t, Monad m) => t a -> (i -> a -> m b) -> m ()-iforM_ = flip imapM_-{-# INLINE iforM_ #-}---- |--- Concatenate the results of a function of the elements of an indexed container with access to the index.------ When you don't need access to the index then 'concatMap' is more flexible in what it accepts.------ @--- 'concatMap' ≡ 'iconcatMap' . 'const'--- 'iconcatMap' ≡ 'ifoldMap'--- @-iconcatMap :: FoldableWithIndex i f => (i -> a -> [b]) -> f a -> [b]-iconcatMap = ifoldMap-{-# INLINE iconcatMap #-}---- | Searches a container with a predicate that is also supplied the index, returning the left-most element of the structure--- matching the predicate, or 'Nothing' if there is no such element.------ When you don't need access to the index then 'find' is more flexible in what it accepts.------ @'find' ≡ 'ifind' '.' 'const'@-ifind :: FoldableWithIndex i f => (i -> a -> Bool) -> f a -> Maybe (i, a)-ifind p = getFirst . ifoldMap step where-  step i c-    | p i c     = First $ Just (i, c)-    | otherwise = First Nothing-{-# INLINE ifind #-}---- | Monadic fold right over the elements of a structure with an index.------ When you don't need access to the index then 'foldrM' is more flexible in what it accepts.------ @'foldrM' ≡ 'ifoldrM' '.' 'const'@-ifoldrM :: (FoldableWithIndex i f, Monad m) => (i -> a -> b -> m b) -> b -> f a -> m b-ifoldrM f z0 xs = ifoldl f' return xs z0-  where f' i k x z = f i x z >>= k-{-# INLINE ifoldrM #-}---- | Monadic fold over the elements of a structure with an index, associating to the left.------ When you don't need access to the index then 'foldlM' is more flexible in what it accepts.------ @'foldlM' ≡ 'ifoldlM' '.' 'const'@-ifoldlM :: (FoldableWithIndex i f, Monad m) => (i -> b -> a -> m b) -> b -> f a -> m b-ifoldlM f z0 xs = ifoldr f' return xs z0-  where f' i x k z = f i z x >>= k-{-# INLINE ifoldlM #-}---- | Extract the key-value pairs from a structure.------ When you don't need access to the indices in the result, then 'Data.Foldable.toList' is more flexible in what it accepts.------ @'Data.Foldable.toList' ≡ 'Data.List.map' 'fst' '.' 'itoList'@-itoList :: FoldableWithIndex i f => f a -> [(i,a)]-itoList = ifoldr (\i c -> ((i,c):)) []-{-# INLINE itoList #-}------------------------------------------------------------------------------------ Converting to Folds------------------------------------------------------------------------------------ | Fold a container with indices returning both the indices and the values.-withIndices :: FoldableWithIndex i f => Fold (f a) (i,a)-withIndices f = coerce . getFolding . ifoldMap (\i a -> Folding (f (i,a)))-{-# INLINE withIndices #-}---- | Fold a container with indices returning only the indices.-indices :: FoldableWithIndex i f => Fold (f a) i-indices f = coerce . getFolding# (ifoldMap (const . folding# f))-{-# INLINE indices #-}------------------------------------------------------------------------------------ TraversableWithIndex------------------------------------------------------------------------------------ | A 'Traversable' with an additional index.------ An instance must satisfy a (modified) form of the 'Traversable' laws:------ @--- 'itraverse' ('const' 'Data.Functor.Identity.Identity') ≡ 'Data.Functor.Identity.Identity'--- 'fmap' ('itraverse' f) '.' 'itraverse' g ≡ 'getCompose' '.' 'itraverse' (\i -> 'Compose' '.' 'fmap' (f i) '.' g i)--- @-class (FunctorWithIndex i t, FoldableWithIndex i t, Traversable t) => TraversableWithIndex i t | t -> i where-  -- | Traverse an indexed container.-  itraverse :: Applicative f => (i -> a -> f b) -> t a -> f (t b)-#ifdef MPTC_DEFAULTS-  default itraverse :: Applicative f => (Int -> a -> f b) -> t a -> f (t b)-  itraverse = withIndex traversed-  {-# INLINE itraverse #-}-#endif---- | The 'IndexedTraversal' of a 'TraversableWithIndex' container.-itraversed :: TraversableWithIndex i f => IndexedTraversal i (f a) (f b) a b-itraversed = indexed itraverse-{-# INLINE itraversed #-}---- |--- Traverse with an index (and the arguments flipped)------ @--- 'for' a ≡ 'ifor' a '.' 'const'--- 'ifor' ≡ 'flip' 'itraverse'--- @-ifor :: (TraversableWithIndex i t, Applicative f) => t a -> (i -> a -> f b) -> f (t b)-ifor = flip itraverse-{-# INLINE ifor #-}---- | Map each element of a structure to a monadic action,--- evaluate these actions from left to right, and collect the results, with access--- the index.------ When you don't need access to the index 'mapM' is more liberal in what it can accept.------ @'mapM' ≡ 'imapM' '.' 'const'@-imapM :: (TraversableWithIndex i t, Monad m) => (i -> a -> m b) -> t a -> m (t b)-imapM f = unwrapMonad# (itraverse (\i -> wrapMonad# (f i)))-{-# INLINE imapM #-}---- | Map each element of a structure to a monadic action,--- evaluate these actions from left to right, and collect the results, with access--- its position (and the arguments flipped).------ @--- 'forM' a ≡ 'iforM' a '.' 'const'--- 'iforM' ≡ 'flip' 'imapM'--- @-iforM :: (TraversableWithIndex i t, Monad m) => t a -> (i -> a -> m b) -> m (t b)-iforM = flip imapM-{-# INLINE iforM #-}---- | Generalizes 'Data.Traversable.mapAccumR' to add access to the index.------ 'imapAccumROf' accumulates state from right to left.------ @'Control.Lens.Traversal.mapAccumR' ≡ 'imapAccumR' '.' 'const'@-imapAccumR :: TraversableWithIndex i t => (i -> s -> a -> (s, b)) -> s -> t a -> (s, t b)-imapAccumR f s0 a = swap (Lazy.runState (itraverse (\i c -> Lazy.state (\s -> swap (f i s c))) a) s0)-{-# INLINE imapAccumR #-}---- | Generalizes 'Data.Traversable.mapAccumL' to add access to the index.------ 'imapAccumLOf' accumulates state from left to right.------ @'Control.Lens.Traversal.mapAccumLOf' ≡ 'imapAccumL' '.' 'const'@-imapAccumL :: TraversableWithIndex i t => (i -> s -> a -> (s, b)) -> s -> t a -> (s, t b)-imapAccumL f s0 a = swap (Lazy.runState (forwards (itraverse (\i c -> Backwards (Lazy.state (\s -> swap (f i s c)))) a)) s0)-{-# INLINE imapAccumL #-}---- | Access the element of an indexed container where the index matches a predicate.------ >>> over (iwhere (>0)) Prelude.reverse $ ["He","was","stressed","o_O"]--- ["He","saw","desserts","O_o"]-iwhere :: TraversableWithIndex i t => (i -> Bool) -> SimpleIndexedTraversal i (t a) a-iwhere p = indexed $ \f a -> itraverse (\i c -> if p i then f i c else pure c) a-{-# INLINE iwhere #-}------------------------------------------------------------------------------------ Instances------------------------------------------------------------------------------------ | The position in the list is available as the index.-instance FunctorWithIndex Int [] where-  imap = imapOf itraversed-  {-# INLINE imap #-}-instance FoldableWithIndex Int [] where-  ifoldMap = ifoldMapOf itraversed-  {-# INLINE ifoldMap #-}-instance TraversableWithIndex Int [] where-  itraverse = withIndex traversed-  {-# INLINE itraverse #-}---- | The position in the sequence is available as the index.-instance FunctorWithIndex Int Seq where-  imap = imapOf itraversed-  {-# INLINE imap #-}-instance FoldableWithIndex Int Seq where-  ifoldMap = ifoldMapOf itraversed-  {-# INLINE ifoldMap #-}-instance TraversableWithIndex Int Seq where-  itraverse = withIndex traversed-  {-# INLINE itraverse #-}--instance FunctorWithIndex Int Vector where-  imap = V.imap-  {-# INLINE imap #-}-instance FoldableWithIndex Int Vector where-  ifoldMap = ifoldMapOf itraversed-  {-# INLINE ifoldMap #-}-  ifoldr = V.ifoldr-  ifoldl = V.ifoldl . flip-  ifoldr' = V.ifoldr'-  ifoldl' = V.ifoldl' . flip-instance TraversableWithIndex Int Vector where-  itraverse f = sequenceA . V.imap f-  {-# INLINE itraverse #-}--instance FunctorWithIndex Int IntMap where-  imap = imapOf itraversed-  {-# INLINE imap #-}-instance FoldableWithIndex Int IntMap where-  ifoldMap = ifoldMapOf itraversed-  {-# INLINE ifoldMap #-}-instance TraversableWithIndex Int IntMap where-#if MIN_VERSION_containers(0,5,0)-  itraverse = IntMap.traverseWithKey-#else-  itraverse f = sequenceA . IntMap.mapWithKey f-#endif-  {-# INLINE itraverse #-}--instance FunctorWithIndex k (Map k) where-  imap = imapOf itraversed-  {-# INLINE imap #-}-instance FoldableWithIndex k (Map k) where-  ifoldMap = ifoldMapOf itraversed-  {-# INLINE ifoldMap #-}-instance TraversableWithIndex k (Map k) where-#if MIN_VERSION_containers(0,5,0)-  itraverse = Map.traverseWithKey-#else-  itraverse f = sequenceA . Map.mapWithKey f-#endif-  {-# INLINE itraverse #-}--instance (Eq k, Hashable k) => FunctorWithIndex k (HashMap k) where-  imap = imapOf itraversed-  {-# INLINE imap #-}-instance (Eq k, Hashable k) => FoldableWithIndex k (HashMap k) where-  ifoldMap = ifoldMapOf itraversed-  {-# INLINE ifoldMap #-}-instance (Eq k, Hashable k) => TraversableWithIndex k (HashMap k) where-  itraverse = HashMap.traverseWithKey-  {-# INLINE itraverse #-}------------------------------------------------------------------------------------ Misc.----------------------------------------------------------------------------------swap :: (a,b) -> (b,a)-swap (a,b) = (b,a)-{-# INLINE swap #-}--skip :: a -> ()-skip _ = ()-{-# INLINE skip #-}
src/Control/Lens/Wrapped.hs view
@@ -1,18 +1,19 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE Rank2Types #-}-{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE TypeSynonymInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FunctionalDependencies #-}+#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 706+{-# LANGUAGE PolyKinds #-}+#endif #ifdef TRUSTWORTHY {-# LANGUAGE Trustworthy #-} #endif- ----------------------------------------------------------------------------- -- | -- Module      :  Control.Lens.Wrapped--- Copyright   :  (C) 2012 Edward Kmett, Michael Sloan+-- Copyright   :  (C) 2012-13 Edward Kmett, Michael Sloan -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  experimental@@ -25,10 +26,10 @@ -- they can be done with the 'Iso' directly: -- -- @--- Control.Newtype.over 'Sum' f ≡ 'wrapping' 'Sum' '%~' f--- Control.Newtype.under 'Sum' f ≡ 'unwrapping' 'Sum' '%~' f--- Control.Newtype.overF 'Sum' f ≡ 'mapping' ('wrapping' 'Sum') '%~' f--- Control.Newtype.underF 'Sum' f ≡ 'mapping' ('unwrapping' 'Sum') '%~' f+-- Control.Newtype.over 'Sum' f ≡ 'wrapping' 'Sum' 'Control.Lens.Setter.%~' f+-- Control.Newtype.under 'Sum' f ≡ 'unwrapping' 'Sum' 'Control.Lens.Setter.%~' f+-- Control.Newtype.overF 'Sum' f ≡ 'mapping' ('wrapping' 'Sum') 'Control.Lens.Setter.%~' f+-- Control.Newtype.underF 'Sum' f ≡ 'mapping' ('unwrapping' 'Sum') 'Control.Lens.Setter.%~' f -- @ -- -- 'under' can also be used with 'wrapping' to provide the equivalent of@@ -43,6 +44,7 @@ module Control.Lens.Wrapped   ( Wrapped(..)   , unwrapped+  , wrapped', unwrapped'   , wrapping, unwrapping   , wrappings, unwrappings   , op@@ -50,15 +52,13 @@   ) where  import           Control.Applicative-import           Control.Applicative.Backwards-import           Control.Applicative.Lift import           Control.Arrow--- import        Control.Comonad.Trans.Env--- import        Control.Comonad.Trans.Store+import           Control.Applicative.Backwards import           Control.Comonad.Trans.Traced import           Control.Exception-import           Control.Lens.Prism+import           Control.Lens.Internal.Review import           Control.Lens.Iso+import           Control.Lens.Review import           Control.Monad.Trans.Cont import           Control.Monad.Trans.Error import           Control.Monad.Trans.Identity@@ -73,6 +73,8 @@ import qualified Control.Monad.Trans.Writer.Strict as Strict import           Data.Foldable as Foldable import           Data.Functor.Compose+import           Data.Functor.Contravariant+import qualified Data.Functor.Contravariant.Compose as Contravariant import           Data.Functor.Constant import           Data.Functor.Coproduct import           Data.Functor.Identity@@ -86,6 +88,7 @@ import           Data.Monoid import           Data.Sequence as Seq hiding (length) import           Data.Set as Set+import           Data.Tagged  -- $setup -- >>> import Control.Lens@@ -137,6 +140,10 @@   wrapped = iso Const getConst   {-# INLINE wrapped #-} +instance Wrapped a b (Dual a) (Dual b) where+  wrapped = iso Dual getDual+  {-# INLINE wrapped #-}+ instance Wrapped (a -> a) (b -> b) (Endo a) (Endo b) where   wrapped = iso Endo appEndo   {-# INLINE wrapped #-}@@ -153,6 +160,12 @@   wrapped = iso ArrowMonad getArrowMonad   {-# INLINE wrapped #-} +-- * lens++instance Wrapped a b (Reviewed s a) (Reviewed t b) where+  wrapped = iso Reviewed runReviewed+  {-# INLINE wrapped #-}+ -- * transformers  instance Wrapped (f a) (f' a') (Backwards f a) (Backwards f' a') where@@ -183,10 +196,6 @@   wrapped = iso IdentityT runIdentityT   {-# INLINE wrapped #-} -instance (Applicative f, Applicative g) => Wrapped (f a) (g b) (Lift f a) (Lift g b) where-  wrapped = iso Other unLift-  {-# INLINE wrapped #-}- instance Wrapped (m [a]) (m' [a']) (ListT m a) (ListT m' a') where   wrapped = iso ListT runListT   {-# INLINE wrapped #-}@@ -239,35 +248,78 @@  -- * unordered-containers --- | Use @'wrapping' HashMap.fromList'@. Unwrapping returns some permutation of the list.+-- | Use @'wrapping' 'HashMap.fromList'@. Unwrapping returns some permutation of the list. instance (Hashable k, Eq k, Hashable k', Eq k') => Wrapped [(k, a)] [(k', b)] (HashMap k a) (HashMap k' b) where   wrapped = iso HashMap.fromList HashMap.toList+  {-# INLINE wrapped #-} --- | Use @'wrapping' HashSet.fromList'@. Unwrapping returns some permutation of the list.+-- | Use @'wrapping' 'HashSet.fromList'@. Unwrapping returns some permutation of the list. instance (Hashable a, Eq a, Hashable b, Eq b) => Wrapped [a] [b] (HashSet a) (HashSet b) where   wrapped = iso HashSet.fromList HashSet.toList+  {-# INLINE wrapped #-}  -- * containers  -- | Use @'wrapping' 'IntMap.fromList'@. unwrapping returns a /sorted/ list. instance Wrapped [(Int, a)] [(Int, b)] (IntMap a) (IntMap b) where   wrapped = iso IntMap.fromList IntMap.toAscList+  {-# INLINE wrapped #-}  -- | Use @'wrapping' 'IntSet.fromList'@. unwrapping returns a /sorted/ list. instance Wrapped [Int] [Int] IntSet IntSet where   wrapped = iso IntSet.fromList IntSet.toAscList+  {-# INLINE wrapped #-}  -- | Use @'wrapping' 'Map.fromList'@. unwrapping returns a /sorted/ list. instance (Ord k, Ord k') => Wrapped [(k, a)] [(k', b)] (Map k a) (Map k' b) where   wrapped = iso Map.fromList Map.toAscList+  {-# INLINE wrapped #-}  -- | Use @'wrapping' 'Set.fromList'@. unwrapping returns a /sorted/ list. instance (Ord a, Ord b) => Wrapped [a] [b] (Set a) (Set b) where   wrapped = iso Set.fromList Set.toAscList+  {-# INLINE wrapped #-}  instance Wrapped [a] [b] (Seq a) (Seq b) where   wrapped = iso Seq.fromList Foldable.toList+  {-# INLINE wrapped #-} +-- * contravariant++instance Wrapped (a -> Bool) (a' -> Bool) (Predicate a) (Predicate a') where+  wrapped = iso Predicate getPredicate+  {-# INLINE wrapped #-}++instance Wrapped (a -> a -> Ordering) (a' -> a' -> Ordering) (Comparison a) (Comparison a') where+  wrapped = iso Comparison getComparison+  {-# INLINE wrapped #-}++instance Wrapped (a -> a -> Bool) (a' -> a' -> Bool) (Equivalence a) (Equivalence a') where+  wrapped = iso Equivalence getEquivalence+  {-# INLINE wrapped #-}++instance Wrapped (b -> a) (b' -> a') (Op a b) (Op a' b') where+  wrapped = iso Op getOp+  {-# INLINE wrapped #-}++instance Wrapped (f (g a)) (f' (g' a')) (Contravariant.Compose f g a) (Contravariant.Compose f' g' a') where+  wrapped = iso Contravariant.Compose Contravariant.getCompose+  {-# INLINE wrapped #-}++instance Wrapped (f (g a)) (f' (g' a')) (Contravariant.ComposeFC f g a) (Contravariant.ComposeFC f' g' a') where+  wrapped = iso Contravariant.ComposeFC Contravariant.getComposeFC+  {-# INLINE wrapped #-}++instance Wrapped (f (g a)) (f' (g' a')) (Contravariant.ComposeCF f g a) (Contravariant.ComposeFC f' g' a') where+  wrapped = iso Contravariant.ComposeCF Contravariant.getComposeFC+  {-# INLINE wrapped #-}++-- * tagged++instance Wrapped a b (Tagged s a) (Tagged t b) where+  wrapped = iso Tagged unTagged+  {-# INLINE wrapped #-}+ -- * Control.Exception  instance Wrapped String String AssertionFailed AssertionFailed where@@ -330,10 +382,10 @@ getArrowMonad (ArrowMonad x) = x {-# INLINE getArrowMonad #-} --- | Given the constructor for a @Wrapped@ type, return a+-- | Given the constructor for a 'Wrapped' type, return a -- deconstructor that is its inverse. ----- Assuming the @Wrapped@ instance is legal, these laws hold:+-- Assuming the 'Wrapped' instance is legal, these laws hold: -- -- @ -- 'op' f '.' f ≡ 'id'@@ -350,7 +402,7 @@ op f = review (wrapping f) {-# INLINE op #-} --- | This is a convenient alias for @'from' 'wrapped'@+-- | This is a convenient alias for @'from' 'wrapped'@. -- -- >>> Const "hello" & unwrapped %~ length & getConst -- 5@@ -358,6 +410,16 @@ unwrapped = from wrapped {-# INLINE unwrapped #-} +-- | A convenient type-restricted version of 'wrapped' for aiding type inference.+wrapped' :: Wrapped s s a a => Iso' s a+wrapped' = wrapped+{-# INLINE wrapped' #-}++-- | A convenient type-restricted version of 'unwrapped' for aiding type inference.+unwrapped' :: Wrapped s s a a => Iso' a s+unwrapped' = unwrapped+{-# INLINE unwrapped' #-}+ -- | This is a convenient version of 'wrapped' with an argument that's ignored. -- -- The argument is used to specify which newtype the user intends to wrap@@ -428,8 +490,7 @@ ala = au . wrapping {-# INLINE ala #-} --- |--- This combinator is based on @ala'@ from Conor McBride's work on Epigram.+-- | This combinator is based on @ala'@ from Conor McBride's work on Epigram. -- -- As with 'wrapping', the user supplied function for the newtype is /ignored/. --
src/Control/Lens/Zipper.hs view
@@ -1,7 +1,7 @@ ----------------------------------------------------------------------------- -- | -- Module      :  Control.Lens.Zipper--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  experimental@@ -10,22 +10,24 @@ -- This module provides a 'Zipper' with fairly strong type checking guarantees. -- -- The code here is inspired by Brandon Simmons' @zippo@ package, but uses--- a slightly different approach to represent the 'Zipper' that makes the whole thing--- look like his breadcrumb trail, and can move side-to-side through traversals.+-- a different approach to represent the 'Zipper' that makes the whole thing+-- look like his breadcrumb trail, and can move side-to-side through+-- traversals. -- -- Some examples types: ----- [@'Top' ':>' a@] represents a trivial 'Zipper' with its focus at the root.+-- [@'Top' ':>>' a@] represents a trivial 'Zipper' with its focus at the root. ----- [@'Top' ':>' 'Data.Tree.Tree' a ':>' a@] represents a 'Zipper' that starts with a+-- [@'Top' ':>>' 'Data.Tree.Tree' a ':>>' a@] represents a 'Zipper' that starts with a --   'Data.Tree.Tree' and descends in a single step to values of type @a@. ----- [@'Top' ':>' 'Data.Tree.Tree' a ':>' 'Data.Tree.Tree' a ':>' 'Data.Tree.Tree' a@] represents a 'Zipper' into a+-- [@'Top' ':>>' 'Data.Tree.Tree' a ':>>' 'Data.Tree.Tree' a ':>>' 'Data.Tree.Tree' a@] represents a 'Zipper' into a --   'Data.Tree.Tree' with an intermediate bookmarked 'Data.Tree.Tree', --   focusing in yet another 'Data.Tree.Tree'. ----- Since individual levels of a 'Zipper' are managed by an arbitrary 'Traversal',--- you can move left and right through the 'Traversal' selecting neighboring elements.+-- Since individual levels of a 'Zipper' are managed by an arbitrary+-- 'Control.Lens.Type.IndexedTraversal', you can move left and right through+-- the 'Control.Lens.Type.IndexedTraversal' selecting neighboring elements. -- -- >>> zipper ("hello","world") & downward _1 & fromWithin traverse & focus .~ 'J' & rightmost & focus .~ 'y' & rezip -- ("Jelly","world")@@ -33,12 +35,19 @@ -- This is particularly powerful when compiled with 'Control.Lens.Plated.plate', -- 'Data.Data.Lens.uniplate' or 'Data.Data.Lens.biplate' for walking down into -- self-similar children in syntax trees and other structures.+--+-- Given keys in ascending order you can jump directly to a given key with+-- 'moveTo'. When used with traversals for balanced+-- tree-like structures such as an 'Data.IntMap.IntMap' or 'Data.Map.Map',+-- searching for a key with 'moveTo' can be done in logarithmic time. ----------------------------------------------------------------------------- module Control.Lens.Zipper   (   -- * Zippers     Top()   , (:>)()+  , (:>>)()+  , (:@)()   , Zipper   , zipper   -- ** Focusing@@ -46,14 +55,12 @@   , focusedContext   -- ** Vertical Movement   , upward-  , downward-  , within-  , withins+  , downward, idownward+  , within, iwithin+  , withins, iwithins   -- ** Lateral Movement-  , leftward-  , rightward-  , leftmost-  , rightmost+  , leftward, rightward+  , leftmost, rightmost   -- ** Movement Combinators   , tug   , tugs@@ -64,6 +71,8 @@   , teeth   , jerkTo   , tugTo+  , moveTo+  , moveToward   -- ** Closing the zipper   , rezip   , Zipped@@ -75,6 +84,7 @@   , restoreNearTape   -- ** Unsafe Movement   , fromWithin+  , ifromWithin   , unsafelyRestoreTape   ) where 
src/Control/Lens/Zoom.hs view
@@ -1,20 +1,17 @@-{-# LANGUAGE MagicHash #-} {-# LANGUAGE CPP #-}-{-# LANGUAGE Rank2Types #-}-{-# LANGUAGE LiberalTypeSynonyms #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE FunctionalDependencies #-}+{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE UndecidableInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FunctionalDependencies #-} #ifdef TRUSTWORTHY {-# LANGUAGE Trustworthy #-} #endif - ------------------------------------------------------------------------------- -- | -- Module      :  Control.Lens.Zoom--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  provisional@@ -27,8 +24,8 @@   ) where  import Control.Lens.Getter-import Control.Lens.Internal-import Control.Lens.Internal.Combinators+import Control.Lens.Internal.Action+import Control.Lens.Internal.Zoom import Control.Lens.Type import Control.Monad import Control.Monad.Reader as Reader@@ -44,10 +41,10 @@ import Control.Monad.Trans.Identity import Control.Monad.Trans.Maybe import Data.Monoid+import Data.Profunctor.Unsafe  -- $setup -- >>> import Control.Lens--- >>> import Data.List.Lens (_tail) -- >>> import Control.Monad.State -- >>> import Data.Map as Map -- >>> import Debug.SimpleReflect.Expr as Expr@@ -56,23 +53,24 @@ -- >>> let g :: Expr -> Expr; g = Vars.g -- >>> let h :: Expr -> Expr -> Expr; h = Vars.h --- Chosen so that they have lower fixity than ('%='), and to match ('<~')+-- Chosen so that they have lower fixity than ('%='), and to match ('<~'). infixr 2 `zoom`, `magnify` --- | This class allows us to use 'zoom' in, changing the State supplied by--- many different monad transformers, potentially quite deep in a monad transformer stack.-class (MonadState s m, MonadState t n) => Zoom m n k s t | m -> s k, n -> t k, m t -> n, n s -> m where-  -- | Run a monadic action in a larger state than it was defined in,-  -- using a 'Simple' 'Lens' or 'Simple' 'Control.Lens.Traversal.Traversal'.+-- | This class allows us to use 'zoom' in, changing the 'State' supplied by+-- many different 'Control.Monad.Monad' transformers, potentially quite+-- deep in a 'Monad' transformer stack.+class (Zoomed m ~ Zoomed n, MonadState s m, MonadState t n) => Zoom m n s t | m -> s, n -> t, m t -> n, n s -> m where+  -- | Run a monadic action in a larger 'State' than it was defined in,+  -- using a 'Lens'' or 'Control.Lens.Traversal.Traversal''.   ---  -- This is commonly used to lift actions in a simpler state monad into a-  -- state monad with a larger state type.+  -- This is commonly used to lift actions in a simpler 'State'+  -- 'Monad' into a 'State' 'Monad' with a larger 'State' type.   ---  -- When applied to a 'Simple 'Control.Lens.Traversal.Traversal' over+  -- When applied to a 'Simple' 'Control.Lens.Traversal.Traversal' over   -- multiple values, the actions for each target are executed sequentially   -- and the results are aggregated.   ---  -- This can be used to edit pretty much any monad transformer stack with a state in it!+  -- This can be used to edit pretty much any 'Monad' transformer stack with a 'State' in it!   --   -- >>> flip State.evalState (a,b) $ zoom _1 $ use id   -- a@@ -90,75 +88,74 @@   -- a <> b   --   -- @-  -- 'zoom' :: 'Monad' m             => 'Simple' 'Lens' s t      -> 'StateT' t m a -> 'StateT' s m a-  -- 'zoom' :: ('Monad' m, 'Monoid' c) => 'Simple' 'Control.Lens.Traversal.Traversal' s t -> 'StateT' t m c -> 'StateT' s m c-  -- 'zoom' :: 'Monad' m             => 'Simple' 'Lens' s t      -> 'RWST' r w t m c -> 'RWST' r w s m c-  -- 'zoom' :: ('Monad' m, 'Monoid' c) => 'Simple' 'Control.Lens.Traversal.Traversal' s t -> 'RWST' r w t m c -> 'RWST' r w s m c-  -- 'zoom' :: 'Monad' m             => 'Simple' 'Lens' s t      -> 'ErrorT' e ('RWST' r w t m c) -> 'ErrorT' e ('RWST' r w s m c)-  -- 'zoom' :: ('Monad' m, 'Monoid' c) => 'Simple' 'Control.Lens.Traversal.Traversal' s t -> 'ErrorT' e ('RWST' r w t m c) -> 'ErrorT' e ('RWST' r w s m c)+  -- 'zoom' :: 'Monad' m             => 'Lens'' s t      -> 'StateT' t m a -> 'StateT' s m a+  -- 'zoom' :: ('Monad' m, 'Monoid' c) => 'Control.Lens.Traversal.Traversal'' s t -> 'StateT' t m c -> 'StateT' s m c+  -- 'zoom' :: 'Monad' m             => 'Lens'' s t      -> 'RWST' r w t m c -> 'RWST' r w s m c+  -- 'zoom' :: ('Monad' m, 'Monoid' c) => 'Control.Lens.Traversal.Traversal'' s t -> 'RWST' r w t m c -> 'RWST' r w s m c+  -- 'zoom' :: 'Monad' m             => 'Lens'' s t      -> 'ErrorT' e ('RWST' r w t m c) -> 'ErrorT' e ('RWST' r w s m c)+  -- 'zoom' :: ('Monad' m, 'Monoid' c) => 'Control.Lens.Traversal.Traversal'' s t -> 'ErrorT' e ('RWST' r w t m c) -> 'ErrorT' e ('RWST' r w s m c)   -- ...   -- @-  zoom :: SimpleLensLike (k c) t s -> m c -> n c+  zoom :: LensLike' (Zoomed m c) t s -> m c -> n c -instance Monad z => Zoom (Strict.StateT s z) (Strict.StateT t z) (Focusing z) s t where-  zoom l (Strict.StateT m) = Strict.StateT $ unfocusing# (l (focusing# m))+instance Monad z => Zoom (Strict.StateT s z) (Strict.StateT t z) s t where+  zoom l (Strict.StateT m) = Strict.StateT $ unfocusing #. l (Focusing #. m)   {-# INLINE zoom #-} -instance Monad z => Zoom (Lazy.StateT s z) (Lazy.StateT t z) (Focusing z) s t where-  zoom l (Lazy.StateT m) = Lazy.StateT $ unfocusing# (l (focusing# m))+instance Monad z => Zoom (Lazy.StateT s z) (Lazy.StateT t z) s t where+  zoom l (Lazy.StateT m) = Lazy.StateT $ unfocusing #. l (Focusing #. m)   {-# INLINE zoom #-} -instance Zoom m n k s t => Zoom (ReaderT e m) (ReaderT e n) k s t where+instance Zoom m n s t => Zoom (ReaderT e m) (ReaderT e n) s t where   zoom l (ReaderT m) = ReaderT (zoom l . m)   {-# INLINE zoom #-} -instance Zoom m n k s t => Zoom (IdentityT m) (IdentityT n) k s t where+instance Zoom m n s t => Zoom (IdentityT m) (IdentityT n) s t where   zoom l (IdentityT m) = IdentityT (zoom l m)   {-# INLINE zoom #-} -instance (Monoid w, Monad z) => Zoom (Strict.RWST r w s z) (Strict.RWST r w t z) (FocusingWith w z) s t where-  zoom l (Strict.RWST m) = Strict.RWST $ \r -> unfocusingWith# (l (focusingWith# (m r)))+instance (Monoid w, Monad z) => Zoom (Strict.RWST r w s z) (Strict.RWST r w t z) s t where+  zoom l (Strict.RWST m) = Strict.RWST $ \r -> unfocusingWith #. l (FocusingWith #. m r)   {-# INLINE zoom #-} -instance (Monoid w, Monad z) => Zoom (Lazy.RWST r w s z) (Lazy.RWST r w t z) (FocusingWith w z) s t where-  zoom l (Lazy.RWST m) = Lazy.RWST $ \r -> unfocusingWith# (l (focusingWith# (m r)))+instance (Monoid w, Monad z) => Zoom (Lazy.RWST r w s z) (Lazy.RWST r w t z) s t where+  zoom l (Lazy.RWST m) = Lazy.RWST $ \r -> unfocusingWith #. l (FocusingWith #. m r)   {-# INLINE zoom #-} -instance (Monoid w, Zoom m n k s t) => Zoom (Strict.WriterT w m) (Strict.WriterT w n) (FocusingPlus w k) s t where-  zoom l = Strict.WriterT . zoom (\afb -> unfocusingPlus# (l (focusingPlus# afb))) . Strict.runWriterT+instance (Monoid w, Zoom m n s t) => Zoom (Strict.WriterT w m) (Strict.WriterT w n) s t where+  zoom l = Strict.WriterT . zoom (\afb -> unfocusingPlus #. l (FocusingPlus #. afb)) . Strict.runWriterT   {-# INLINE zoom #-} -instance (Monoid w, Zoom m n k s t) => Zoom (Lazy.WriterT w m) (Lazy.WriterT w n) (FocusingPlus w k) s t where-  zoom l = Lazy.WriterT . zoom (\afb -> unfocusingPlus# (l (focusingPlus# afb))) . Lazy.runWriterT+instance (Monoid w, Zoom m n s t) => Zoom (Lazy.WriterT w m) (Lazy.WriterT w n) s t where+  zoom l = Lazy.WriterT . zoom (\afb -> unfocusingPlus #. l (FocusingPlus #. afb)) . Lazy.runWriterT   {-# INLINE zoom #-} -instance Zoom m n k s t => Zoom (ListT m) (ListT n) (FocusingOn [] k) s t where+instance Zoom m n s t => Zoom (ListT m) (ListT n) s t where   zoom l = ListT . zoom (\afb -> unfocusingOn . l (FocusingOn . afb)) . runListT   {-# INLINE zoom #-} -instance Zoom m n k s t => Zoom (MaybeT m) (MaybeT n) (FocusingMay k) s t where-  zoom l = MaybeT . liftM getMay . zoom (\afb -> unfocusingMay# (l (focusingMay# afb))) . liftM May . runMaybeT+instance Zoom m n s t => Zoom (MaybeT m) (MaybeT n) s t where+  zoom l = MaybeT . liftM getMay . zoom (\afb -> unfocusingMay #. l (FocusingMay #. afb)) . liftM May . runMaybeT   {-# INLINE zoom #-} -instance (Error e, Zoom m n k s t) => Zoom (ErrorT e m) (ErrorT e n) (FocusingErr e k) s t where-  zoom l = ErrorT . liftM getErr . zoom (\afb -> unfocusingErr# (l (focusingErr# afb))) . liftM Err . runErrorT+instance (Error e, Zoom m n s t) => Zoom (ErrorT e m) (ErrorT e n) s t where+  zoom l = ErrorT . liftM getErr . zoom (\afb -> unfocusingErr #. l (FocusingErr #. afb)) . liftM Err . runErrorT   {-# INLINE zoom #-} --- TODO: instance Zoom m m k a a => Zoom (ContT r m) (ContT r m) k a a where-+-- TODO: instance Zoom m m a a => Zoom (ContT r m) (ContT r m) a a where  -- | This class allows us to use 'magnify' part of the environment, changing the environment supplied by--- many different monad transformers. Unlike 'zoom' this can change the environment of a deeply nested monad transformer.+-- many different 'Monad' transformers. Unlike 'zoom' this can change the environment of a deeply nested 'Monad' transformer. -- -- Also, unlike 'zoom', this can be used with any valid 'Getter', but cannot be used with a 'Traversal' or 'Fold'.-class (MonadReader b m, MonadReader a n) => Magnify m n k b a | m -> b k, n -> a k, m a -> n, n b -> m where+class (Magnified m ~ Magnified n, MonadReader b m, MonadReader a n) => Magnify m n b a | m -> b, n -> a, m a -> n, n b -> m where   -- | Run a monadic action in a larger environment than it was defined in, using a 'Getter'.   --   -- This acts like 'Control.Monad.Reader.Class.local', but can in many cases change the type of the environment as well.   ---  -- This is commonly used to lift actions in a simpler Reader monad into a monad with a larger environment type.+  -- This is commonly used to lift actions in a simpler 'Reader' 'Monad' into a 'Monad' with a larger environment type.   ---  -- This can be used to edit pretty much any monad transformer stack with an environment in it:+  -- This can be used to edit pretty much any 'Monad' transformer stack with an environment in it:   --   -- >>> (1,2) & magnify _2 (+1)   -- 3@@ -172,29 +169,34 @@   -- @   -- 'magnify' ::             'Getter' s a -> (a -> r) -> s -> r   -- 'magnify' :: 'Monoid' c => 'Fold' s a   -> (a -> r) -> s -> r+  -- @+  --+  -- @   -- 'magnify' :: 'Monoid' w                'Getter' s t -> 'RWST' s w st c -> 'RWST' t w st c   -- 'magnify' :: ('Monoid' w, 'Monoid' c) => 'Fold' s t   -> 'RWST' s w st c -> 'RWST' t w st c   -- ...   -- @-  magnify :: ((b -> k c b) -> a -> k c a) -> m c -> n c+  magnify :: LensLike' (Magnified m c) a b -> m c -> n c -instance Monad m => Magnify (ReaderT b m) (ReaderT a m) (Effect m) b a where-  magnify l (ReaderT m) = ReaderT $ getEffect# (l (effect# m))+instance Monad m => Magnify (ReaderT b m) (ReaderT a m) b a where+  magnify l (ReaderT m) = ReaderT $ getEffect #. l (Effect #. m)   {-# INLINE magnify #-} --- | @'magnify' = 'views'@-instance Magnify ((->) b) ((->) a) Accessor b a where+-- | @+-- 'magnify' = 'views'+-- @+instance Magnify ((->) b) ((->) a) b a where   magnify = views   {-# INLINE magnify #-} -instance (Monad m, Monoid w) => Magnify (Strict.RWST b w s m) (Strict.RWST a w s m) (EffectRWS w s m) b a where-  magnify l (Strict.RWST m) = Strict.RWST $ getEffectRWS# (l (effectRWS# m))+instance (Monad m, Monoid w) => Magnify (Strict.RWST b w s m) (Strict.RWST a w s m) b a where+  magnify l (Strict.RWST m) = Strict.RWST $ getEffectRWS #. l (EffectRWS #. m)   {-# INLINE magnify #-} -instance (Monad m, Monoid w) => Magnify (Lazy.RWST b w s m) (Lazy.RWST a w s m) (EffectRWS w s m) b a where-  magnify l (Lazy.RWST m) = Lazy.RWST $ getEffectRWS# (l (effectRWS# m))+instance (Monad m, Monoid w) => Magnify (Lazy.RWST b w s m) (Lazy.RWST a w s m) b a where+  magnify l (Lazy.RWST m) = Lazy.RWST $ getEffectRWS #. l (EffectRWS #. m)   {-# INLINE magnify #-} -instance Magnify m n k b a => Magnify (IdentityT m) (IdentityT n) k b a where+instance Magnify m n b a => Magnify (IdentityT m) (IdentityT n) b a where   magnify l (IdentityT m) = IdentityT (magnify l m)   {-# INLINE magnify #-}
+ src/Control/Monad/Error/Lens.hs view
@@ -0,0 +1,144 @@+{-# LANGUAGE CPP #-}+#ifdef TRUSTWORTHY+{-# LANGUAGE Trustworthy #-}+#endif+-----------------------------------------------------------------------------+-- |+-- Module      :  Control.Monad.Error.Lens+-- Copyright   :  (C) 2013 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  provisional+-- Portability :  Control.Monad.Error+--+----------------------------------------------------------------------------+module Control.Monad.Error.Lens+  (+  -- * Catching+    catching, catching_+  -- * Handling+  , handling, handling_+  -- * Trying+  , trying+  -- * Throwing+  , throwing+  ) where++import Control.Lens+import Control.Monad.Error+import Data.Monoid++------------------------------------------------------------------------------+-- Catching+------------------------------------------------------------------------------++-- | Catch exceptions that match a given 'Prism' (or any 'Getter', really).+--+-- @+-- 'catching' :: 'MonadError' e m => 'Prism'' e a     -> m r -> (a -> m r) -> m r+-- 'catching' :: 'MonadError' e m => 'Lens'' e a      -> m r -> (a -> m r) -> m r+-- 'catching' :: 'MonadError' e m => 'Traversal'' e a -> m r -> (a -> m r) -> m r+-- 'catching' :: 'MonadError' e m => 'Iso'' e a       -> m r -> (a -> m r) -> m r+-- 'catching' :: 'MonadError' e m => 'Getter' e a     -> m r -> (a -> m r) -> m r+-- 'catching' :: 'MonadError' e m => 'Fold' e a       -> m r -> (a -> m r) -> m r+-- @+catching :: MonadError e m => Getting (First a) e t a b -> m r -> (a -> m r) -> m r+catching l = catchJust (preview l)+{-# INLINE catching #-}++-- | Catch exceptions that match a given 'Prism' (or any 'Getter'), discarding+-- the information about the match. This is particuarly useful when you have+-- a @'Prism'' e ()@ where the result of the 'Prism' or 'Fold' isn't+-- particularly valuable, just the fact that it matches.+--+-- @+-- 'catching_' :: 'MonadError' e m => 'Prism'' e a     -> m r -> m r -> m r+-- 'catching_' :: 'MonadError' e m => 'Lens'' e a      -> m r -> m r -> m r+-- 'catching_' :: 'MonadError' e m => 'Traversal'' e a -> m r -> m r -> m r+-- 'catching_' :: 'MonadError' e m => 'Iso'' e a       -> m r -> m r -> m r+-- 'catching_' :: 'MonadError' e m => 'Getter' e a     -> m r -> m r -> m r+-- 'catching_' :: 'MonadError' e m => 'Fold' e a       -> m r -> m r -> m r+-- @+catching_ :: MonadError e m => Getting (First a) e t a b -> m r -> m r -> m r+catching_ l a b = catchJust (preview l) a (const b)+{-# INLINE catching_ #-}++------------------------------------------------------------------------------+-- Handling+------------------------------------------------------------------------------++-- | A version of 'catching' with the arguments swapped around; useful in+-- situations where the code for the handler is shorter.+--+-- @+-- 'handling' :: 'MonadError' e m => 'Prism'' e a     -> (a -> m r) -> m r -> m r+-- 'handling' :: 'MonadError' e m => 'Lens'' e a      -> (a -> m r) -> m r -> m r+-- 'handling' :: 'MonadError' e m => 'Traversal'' e a -> (a -> m r) -> m r -> m r+-- 'handling' :: 'MonadError' e m => 'Iso'' e a       -> (a -> m r) -> m r -> m r+-- 'handling' :: 'MonadError' e m => 'Fold' e a       -> (a -> m r) -> m r -> m r+-- 'handling' :: 'MonadError' e m => 'Getter' e a     -> (a -> m r) -> m r -> m r+-- @+handling :: MonadError e m => Getting (First a) e t a b -> (a -> m r) -> m r -> m r+handling l = flip (catching l)+{-# INLINE handling #-}++-- | A version of 'catching_' with the arguments swapped around; useful in+-- situations where the code for the handler is shorter.+--+-- @+-- 'handling_' :: 'MonadError' e m => 'Prism'' e a     -> m r -> m r -> m r+-- 'handling_' :: 'MonadError' e m => 'Lens'' e a      -> m r -> m r -> m r+-- 'handling_' :: 'MonadError' e m => 'Traversal'' e a -> m r -> m r -> m r+-- 'handling_' :: 'MonadError' e m => 'Iso'' e a       -> m r -> m r -> m r+-- 'handling_' :: 'MonadError' e m => 'Getter' e a     -> m r -> m r -> m r+-- 'handling_' :: 'MonadError' e m => 'Fold' e a       -> m r -> m r -> m r+-- @+handling_ :: MonadError e m => Getting (First a) e t a b -> m r -> m r -> m r+handling_ l = flip (catching_ l)+{-# INLINE handling_ #-}++------------------------------------------------------------------------------+-- Trying+------------------------------------------------------------------------------++-- | 'trying' takes a 'Prism' (or any 'Getter') to select which exceptions are caught +-- If the 'Exception' does not match the predicate, it is re-thrown.+--+-- @+-- 'trying' :: 'MonadError' e m => 'Prism'' e a     -> m r -> m ('Either' a r)+-- 'trying' :: 'MonadError' e m => 'Lens'' e a      -> m r -> m ('Either' a r)+-- 'trying' :: 'MonadError' e m => 'Traversal'' e a -> m r -> m ('Either' a r)+-- 'trying' :: 'MonadError' e m => 'Iso'' e a       -> m r -> m ('Either' a r)+-- 'trying' :: 'MonadError' e m => 'Getter' e a     -> m r -> m ('Either' a r)+-- 'trying' :: 'MonadError' e m => 'Fold' e a       -> m r -> m ('Either' a r)+-- @+trying :: MonadError e m => Getting (First a) e t a b -> m r -> m (Either a r)+trying l m = catching l (liftM Right m) (return . Left)++------------------------------------------------------------------------------+-- Throwing+------------------------------------------------------------------------------++-- | Throw an 'Exception' described by a 'Prism'.+--+-- @'throwing' l ≡ 'reviews' l 'throwError'@+--+-- @+-- 'throwing' :: 'MonadError' e m => 'Prism'' e t -> t -> a+-- 'throwing' :: 'MonadError' e m => 'Iso'' e t   -> t -> a+-- @+throwing :: MonadError e m => AReview e e t t -> t -> m x+throwing l = reviews l throwError+{-# INLINE throwing #-}++------------------------------------------------------------------------------+-- Misc.+------------------------------------------------------------------------------++-- | Helper function to provide conditional catch behavior.+catchJust :: MonadError e m => (e -> Maybe t) -> m a -> (t -> m a) -> m a+catchJust f m k = catchError m $ \ e -> case f e of+  Nothing -> throwError e+  Just x  -> k x+{-# INLINE catchJust #-}+
src/Control/Parallel/Strategies/Lens.hs view
@@ -8,7 +8,7 @@ ----------------------------------------------------------------------------- -- | -- Module      :  Control.Parallel.Strategies.Lens--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-2013 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  provisional@@ -37,11 +37,11 @@ -- @ -- -- @--- 'evalOf' :: 'Simple' 'Lens' s a -> 'Strategy' a -> 'Strategy' s--- 'evalOf' :: 'Simple' 'Traversal' s a -> 'Strategy' a -> 'Strategy' s+-- 'evalOf' :: 'Lens'' s a -> 'Strategy' a -> 'Strategy' s+-- 'evalOf' :: 'Traversal'' s a -> 'Strategy' a -> 'Strategy' s -- 'evalOf' :: (a -> 'Eval' a) -> s -> 'Eval' s) -> 'Strategy' a -> 'Strategy' s -- @-evalOf :: SimpleLensLike Eval s a -> Strategy a -> Strategy s+evalOf :: LensLike' Eval s a -> Strategy a -> Strategy s evalOf l = l {-# INLINE evalOf #-} @@ -51,11 +51,11 @@ -- @'parTraversable' = 'parOf' 'traverse'@ -- -- @--- 'parOf' :: 'Simple' 'Lens' s a -> 'Strategy' a -> 'Strategy' s--- 'parOf' :: 'Simple' 'Traversal' s a -> 'Strategy' a -> 'Strategy' s+-- 'parOf' :: 'Lens'' s a -> 'Strategy' a -> 'Strategy' s+-- 'parOf' :: 'Traversal'' s a -> 'Strategy' a -> 'Strategy' s -- 'parOf' :: ((a -> 'Eval' a) -> s -> 'Eval' s) -> 'Strategy' a -> 'Strategy' s -- @-parOf :: SimpleLensLike Eval s a -> Strategy a -> Strategy s+parOf :: LensLike' Eval s a -> Strategy a -> Strategy s #if MIN_VERSION_parallel(3,2,0) parOf l s = l (rparWith s) #else
src/Control/Seq/Lens.hs view
@@ -1,13 +1,13 @@ ----------------------------------------------------------------------------- -- | -- Module      :  Control.Seq.Lens--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  provisional -- Portability :  portable ----- A 'Fold' can be used to take the role of 'Foldable' in @Control.Seq@+-- A 'Fold' can be used to take the role of 'Foldable' in @Control.Seq@. ---------------------------------------------------------------------------- module Control.Seq.Lens   ( seqOf
src/Data/Array/Lens.hs view
@@ -1,10 +1,8 @@-{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE Rank2Types #-}-{-# LANGUAGE LiberalTypeSynonyms #-} ----------------------------------------------------------------------------- -- | -- Module      :  Data.Array.Lens--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  provisional@@ -13,52 +11,24 @@ ---------------------------------------------------------------------------- module Data.Array.Lens   (-  -- * Indexing-    ix   -- * Setters-  , ixmapped-  -- * Traversal-  , _array+    ixmapped   ) where -import Control.Applicative import Control.Lens import Data.Array.IArray hiding (index) --- | Access an element of an array.------ Note: The indexed element is assumed to exist in the target 'IArray'.------ @--- arr '!' i ≡ arr '^.' 'ix' i--- arr '//' [(i,e)] ≡ 'ix' i '.~' e '$' arr--- @------ >>> ix 2 .~ 9 $ (listArray (1,5) [4,5,6,7,8] :: Array Int Int)--- array (1,5) [(1,4),(2,9),(3,6),(4,7),(5,8)]-ix :: (IArray a e, Ix i) => i -> Simple Lens (a i e) e-ix i f arr = f (arr ! i) <&> \e -> arr // [(i,e)]-{-# INLINE ix #-}---- | This setter can be used to derive a new 'IArray' from an old array by+-- | This 'setter' can be used to derive a new 'IArray' from an old 'IAarray' by -- applying a function to each of the indices to look it up in the old 'IArray'. -- -- This is a /contravariant/ 'Setter'. -- -- @--- 'ixmap' ≡ 'over' . 'ixmapped'--- 'ixmapped' ≡ 'sets' . 'ixmap'+-- 'ixmap' ≡ 'over' '.' 'ixmapped'+-- 'ixmapped' ≡ 'setting' '.' 'ixmap' -- 'over' ('ixmapped' b) f arr '!' i ≡ arr '!' f i -- 'bounds' ('over' ('ixmapped' b) f arr) ≡ b -- @-ixmapped :: (IArray a e, Ix i, Ix j) => (i,i) -> Setter (a j e) (a i e) i j-ixmapped = sets . ixmap+ixmapped :: (IArray a e, Ix i, Ix j) => (i,i) -> IndexPreservingSetter (a j e) (a i e) i j+ixmapped = setting . ixmap {-# INLINE ixmapped #-}---- | An 'IndexedTraversal' of the elements of an 'IArray', using the--- index into the array as the index of the traversal.------ @'amap' ≡ 'over' '_array'@-_array :: (IArray arr a, IArray arr b, Ix i) => IndexedTraversal i (arr i a) (arr i b) a b-_array = indexed $ \f arr -> array (bounds arr) <$> traverse (\(i,a) -> (,) i <$> f i a) (assocs arr)-{-# INLINE _array #-}
src/Data/Bits/Lens.hs view
@@ -1,10 +1,9 @@-{-# LANGUAGE LiberalTypeSynonyms #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE Rank2Types #-} ----------------------------------------------------------------------------- -- | -- Module      :  Data.Bits.Lens--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  experimental@@ -16,12 +15,14 @@   , (.|.=), (.&.=), (<.|.=), (<.&.=)   , bitAt   , bits+  , byteAt   ) where  import Control.Lens import Control.Monad.State import Data.Bits import Data.Functor+import Data.Word  -- $setup -- >>> import Data.Word@@ -29,63 +30,63 @@ infixr 4 .|.~, .&.~, <.|.~, <.&.~ infix 4 .|.=, .&.=, <.|.=, <.&.= --- | Bitwise '.|.' the target(s) of a 'Lens' or 'Setter'+-- | Bitwise '.|.' the target(s) of a 'Lens' or 'Setter'. -- -- >>> _2 .|.~ 6 $ ("hello",3) -- ("hello",7) -- -- @--- ('.|.~') :: 'Bits' a => 'Setter' s t a a -> a -> s -> t--- ('.|.~') :: 'Bits' a => 'Iso' s t a a -> a -> s -> t--- ('.|.~') :: 'Bits' a => 'Lens' s t a a -> a -> s -> t--- ('.|.~') :: ('Monoid a', 'Bits' a) => 'Traversal' s t a a -> a -> s -> t+-- ('.|.~') :: 'Bits' a             => 'Setter' s t a a    -> a -> s -> t+-- ('.|.~') :: 'Bits' a             => 'Iso' s t a a       -> a -> s -> t+-- ('.|.~') :: 'Bits' a             => 'Lens' s t a a      -> a -> s -> t+-- ('.|.~') :: ('Data.Monoid.Monoid' a, 'Bits' a) => 'Traversal' s t a a -> a -> s -> t -- @-(.|.~):: Bits a => Setting s t a a -> a -> s -> t+(.|.~):: Bits a => ASetter s t a a -> a -> s -> t l .|.~ n = over l (.|. n) {-# INLINE (.|.~) #-} --- | Bitwise '.&.' the target(s) of a 'Lens' or 'Setter'+-- | Bitwise '.&.' the target(s) of a 'Lens' or 'Setter'. -- -- >>> _2 .&.~ 7 $ ("hello",254) -- ("hello",6) -- -- @--- ('.&.~') :: 'Bits' a => 'Setter' s t a a -> a -> s -> t--- ('.&.~') :: 'Bits' a => 'Iso' s t a a -> a -> s -> t--- ('.&.~') :: 'Bits' a => 'Lens' s t a a -> a -> s -> t--- ('.&.~') :: ('Monoid a', 'Bits' a) => 'Traversal' s t a a -> a -> s -> t+-- ('.&.~') :: 'Bits' a             => 'Setter' s t a a    -> a -> s -> t+-- ('.&.~') :: 'Bits' a             => 'Iso' s t a a       -> a -> s -> t+-- ('.&.~') :: 'Bits' a             => 'Lens' s t a a      -> a -> s -> t+-- ('.&.~') :: ('Data.Monoid.Monoid' a, 'Bits' a) => 'Traversal' s t a a -> a -> s -> t -- @-(.&.~) :: Bits a => Setting s t a a -> a -> s -> t+(.&.~) :: Bits a => ASetter s t a a -> a -> s -> t l .&.~ n = over l (.&. n) {-# INLINE (.&.~) #-} --- | Modify the target(s) of a 'Simple' 'Lens', 'Setter' or 'Traversal' by computing its bitwise '.&.' with another value.+-- | Modify the target(s) of a 'Lens'', 'Setter'' or 'Traversal'' by computing its bitwise '.&.' with another value. -- -- >>> execState (do _1 .&.= 15; _2 .&.= 3) (7,7) -- (7,3) -- -- @--- ('.&.=') :: ('MonadState' s m, 'Bits' a) => 'Simple' 'Setter' s a -> a -> m ()--- ('.&.=') :: ('MonadState' s m, 'Bits' a) => 'Simple' 'Iso' s a -> a -> m ()--- ('.&.=') :: ('MonadState' s m, 'Bits' a) => 'Simple' 'Lens' s a -> a -> m ()--- ('.&.=') :: ('MonadState' s m, 'Bits' a) => 'Simple' 'Traversal' s a -> a -> m ()+-- ('.&.=') :: ('MonadState' s m, 'Bits' a) => 'Setter'' s a    -> a -> m ()+-- ('.&.=') :: ('MonadState' s m, 'Bits' a) => 'Iso'' s a       -> a -> m ()+-- ('.&.=') :: ('MonadState' s m, 'Bits' a) => 'Lens'' s a      -> a -> m ()+-- ('.&.=') :: ('MonadState' s m, 'Bits' a) => 'Traversal'' s a -> a -> m () -- @-(.&.=):: (MonadState s m, Bits a) => Simple Setting s a -> a -> m ()+(.&.=):: (MonadState s m, Bits a) => ASetter' s a -> a -> m () l .&.= a = modify (l .&.~ a) {-# INLINE (.&.=) #-} --- | Modify the target(s) of a 'Simple' 'Lens', 'Setter' or 'Traversal' by computing its bitwise '.|.' with another value.+-- | Modify the target(s) of a 'Lens'', 'Setter' or 'Traversal' by computing its bitwise '.|.' with another value. -- -- >>> execState (do _1 .|.= 15; _2 .|.= 3) (7,7) -- (15,7) -- -- @--- ('.|.=') :: ('MonadState' s m, 'Bits' a) => 'Simple' 'Setter' s a -> a -> m ()--- ('.|.=') :: ('MonadState' s m, 'Bits' a) => 'Simple' 'Iso' s a -> a -> m ()--- ('.|.=') :: ('MonadState' s m, 'Bits' a) => 'Simple' 'Lens' s a -> a -> m ()--- ('.|.=') :: ('MonadState' s m, 'Bits' a) => 'Simple' 'Traversal' s a -> a -> m ()+-- ('.|.=') :: ('MonadState' s m, 'Bits' a) => 'Setter'' s a    -> a -> m ()+-- ('.|.=') :: ('MonadState' s m, 'Bits' a) => 'Iso'' s a       -> a -> m ()+-- ('.|.=') :: ('MonadState' s m, 'Bits' a) => 'Lens'' s a      -> a -> m ()+-- ('.|.=') :: ('MonadState' s m, 'Bits' a) => 'Traversal'' s a -> a -> m () -- @-(.|.=) :: (MonadState s m, Bits a) => Simple Setting s a -> a -> m ()+(.|.=) :: (MonadState s m, Bits a) => ASetter' s a -> a -> m () l .|.= a = modify (l .|.~ a) {-# INLINE (.|.=) #-} @@ -96,9 +97,9 @@ -- (7,("hello",7)) -- -- @--- ('<.|.~') :: 'Bits' a => 'Iso' s t a a -> a -> s -> (a, t)--- ('<.|.~') :: 'Bits' a => 'Lens' s t a a -> a -> s -> (a, t)--- ('<.|.~') :: ('Bits' a, 'Monoid a) => 'Traversal' s t a a -> a -> s -> (a, t)+-- ('<.|.~') :: 'Bits' a             => 'Iso' s t a a       -> a -> s -> (a, t)+-- ('<.|.~') :: 'Bits' a             => 'Lens' s t a a      -> a -> s -> (a, t)+-- ('<.|.~') :: ('Bits' a, 'Data.Monoid.Monoid' a) => 'Traversal' s t a a -> a -> s -> (a, t) -- @ (<.|.~):: Bits a => LensLike ((,) a) s t a a -> a -> s -> (a, t) l <.|.~ n = l <%~ (.|. n)@@ -111,45 +112,45 @@ -- (6,("hello",6)) -- -- @--- ('<.&.~') :: 'Bits' a => 'Iso' s t a a -> a -> s -> (a, t)--- ('<.&.~') :: 'Bits' a => 'Lens' s t a a -> a -> s -> (a, t)--- ('<.&.~') :: ('Bits' a, 'Monoid a) => 'Traversal' s t a a -> a -> s -> (a, t)+-- ('<.&.~') :: 'Bits' a             => 'Iso'       s t a a -> a -> s -> (a, t)+-- ('<.&.~') :: 'Bits' a             => 'Lens'      s t a a -> a -> s -> (a, t)+-- ('<.&.~') :: ('Bits' a, 'Data.Monoid.Monoid' a) => 'Traversal' s t a a -> a -> s -> (a, t) -- @ (<.&.~) :: Bits a => LensLike ((,) a) s t a a -> a -> s -> (a, t) l <.&.~ n = l <%~ (.&. n) {-# INLINE (<.&.~) #-} --- | Modify the target(s) of a 'Simple' 'Lens' (or 'Traversal') by computing its bitwise '.&.' with another value,--- returning the result (or a monoidal summary of all of the results traversed)+-- | Modify the target(s) of a 'Lens'' (or 'Traversal'') by computing its bitwise '.&.' with another value,+-- returning the result (or a monoidal summary of all of the results traversed). -- -- >>> runState (_1 <.&.= 15) (31,0) -- (15,(15,0)) -- -- @--- ('<.&.=') :: ('MonadState' s m, 'Bits' a) => 'Simple' 'Lens' s a -> a -> m a--- ('<.&.=') :: ('MonadState' s m, 'Bits' a, 'Monoid' a) => 'Simple' 'Traversal' s a -> a -> m a+-- ('<.&.=') :: ('MonadState' s m, 'Bits' a)           => 'Lens'' s a      -> a -> m a+-- ('<.&.=') :: ('MonadState' s m, 'Bits' a, 'Data.Monoid.Monoid' a) => 'Traversal'' s a -> a -> m a -- @-(<.&.=):: (MonadState s m, Bits a) => SimpleLensLike ((,)a) s a -> a -> m a+(<.&.=):: (MonadState s m, Bits a) => LensLike' ((,)a) s a -> a -> m a l <.&.= b = l <%= (.&. b) {-# INLINE (<.&.=) #-} --- | Modify the target(s) of a 'Simple' 'Lens', (or 'Traversal') by computing its bitwise '.|.' with another value,--- returning the result (or a monoidal summary of all of the results traversed)+-- | Modify the target(s) of a 'Lens'', (or 'Traversal') by computing its bitwise '.|.' with another value,+-- returning the result (or a monoidal summary of all of the results traversed). -- -- >>> runState (_1 <.|.= 7) (28,0) -- (31,(31,0)) -- -- @--- ('<.|.=') :: ('MonadState' s m, 'Bits' a) => 'Simple' 'Lens' s a -> a -> m a--- ('<.|.=') :: ('MonadState' s m, 'Bits' a, 'Monoid' a) => 'Simple' 'Traversal' s a -> a -> m a+-- ('<.|.=') :: ('MonadState' s m, 'Bits' a)           => 'Lens'' s a      -> a -> m a+-- ('<.|.=') :: ('MonadState' s m, 'Bits' a, 'Data.Monoid.Monoid' a) => 'Traversal'' s a -> a -> m a -- @-(<.|.=) :: (MonadState s m, Bits a) => SimpleLensLike ((,)a) s a -> a -> m a+(<.|.=) :: (MonadState s m, Bits a) => LensLike' ((,)a) s a -> a -> m a l <.|.= b = l <%= (.|. b) {-# INLINE (<.|.=) #-} --- | This lens can be used to access the value of the nth bit in a number.+-- | This 'Lens' can be used to access the value of the nth bit in a number. ----- @'bitAt' n@ is only a legal 'Lens' into @b@ if @0 <= n < 'bitSize' ('undefined' :: b)@+-- @'bitAt' n@ is only a legal 'Lens' into @b@ if @0 '<=' n '<' 'bitSize' ('undefined' :: b)@. -- -- >>> 16^.bitAt 4 -- True@@ -162,10 +163,32 @@ -- -- >>> 16 & bitAt 4 .~ False -- 0-bitAt :: Bits b => Int -> SimpleIndexedLens Int b Bool-bitAt n = indexed $ \f b -> f n (testBit b n) <&> \x -> if x then setBit b n else clearBit b n+bitAt :: Bits b => Int -> IndexedLens' Int b Bool+bitAt n f b = indexed f n (testBit b n) <&> \x -> if x then setBit b n else clearBit b n {-# INLINE bitAt #-} +-- | Get the nth byte, counting from the low end.+--+-- @'byteAt' n@ is a legal 'Lens' into @b@ iff @0 '<=' n '<' 'div' ('bitSize' ('undefined' :: b)) 8@+--+-- >>> (0xff00 :: Word16)^.byteAt 0+-- 0+--+-- >>> (0xff00 :: Word16)^.byteAt 1+-- 255+--+-- >>> byteAt 1 .~ 0 $ 0xff00 :: Word16+-- 0+--+-- >>> byteAt 0 .~ 0xff $ 0 :: Word16+-- 255+byteAt :: (Integral b, Bits b) => Int -> IndexedLens' Int b Word8+byteAt i f b = back <$> indexed f i (forward b) where+  back w8 = (fromIntegral w8 `shiftL` (i * 8))+    .|. (complement (255 `shiftL` (i * 8)) .&. b)+  forward = fromIntegral . (.&.) 0xff . flip shiftR (i * 8)++ -- | Traverse over all bits in a numeric type. -- -- The bit position is available as the index.@@ -175,12 +198,11 @@ -- -- If you supply this an 'Integer', the result will be an infinite 'Traversal', which -- can be productively consumed, but not reassembled.-bits :: (Num b, Bits b) => SimpleIndexedTraversal Int b Bool-bits = indexed $ \f b -> let-    g n      = (,) n <$> f n (testBit b n)-    bs       = Prelude.takeWhile hasBit [0..]-    hasBit n = complementBit b n /= b -- test to make sure that complementing this bit actually changes the value-    step (n,True) r = setBit r n-    step _        r = r-  in Prelude.foldr step 0 <$> traverse g bs+bits :: (Num b, Bits b) => IndexedTraversal' Int b Bool+bits f b = Prelude.foldr step 0 <$> traverse g bs where+  g n      = (,) n <$> indexed f n (testBit b n)+  bs       = Prelude.takeWhile hasBit [0..]+  hasBit n = complementBit b n /= b -- test to make sure that complementing this bit actually changes the value+  step (n,True) r = setBit r n+  step _        r = r {-# INLINE bits #-}
src/Data/ByteString/Lazy/Lens.hs view
@@ -1,9 +1,8 @@-{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleContexts #-} ----------------------------------------------------------------------------- -- | -- Module      :  Data.ByteString.Lazy.Lens--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-2013 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  experimental@@ -17,29 +16,31 @@   ) where  import Control.Lens-import Data.ByteString.Lazy as Words+import Control.Lens.Internal.ByteString+import Data.ByteString.Lazy       as Words import Data.ByteString.Lazy.Char8 as Char8 import Data.Word (Word8)+import Data.Int (Int64) --- | 'Data.ByteString.Lazy.pack' (or 'Data.ByteString.Lazy.unpack') a list of bytes into a 'ByteString'+-- | 'Data.ByteString.Lazy.pack' (or 'Data.ByteString.Lazy.unpack') a list of bytes into a 'ByteString'. -- -- @'Data.ByteString.Lazy.pack' x = x '^.' 'packedBytes'@ -- -- @'Data.ByteString.Lazy.unpack' x = x '^.' 'from' 'packedBytes'@-packedBytes :: Simple Iso [Word8] ByteString-packedBytes = iso Words.pack Words.unpack+packedBytes :: Iso' [Word8] ByteString+packedBytes = iso Words.pack unpackLazy {-# INLINE packedBytes #-} --- | Traverse the individual bytes in a 'ByteString'+-- | Traverse the individual bytes in a 'ByteString'. ----- @'bytes' = 'from' 'packedBytes' . 'itraversed'@+-- @'bytes' = 'from' 'packedBytes' '.' 'itraversed'@ -- -- @'anyOf' 'bytes' ('==' 0x80) :: 'ByteString' -> 'Bool'@-bytes :: SimpleIndexedTraversal Int ByteString Word8-bytes = from packedBytes .> itraversed+bytes :: IndexedTraversal' Int64 ByteString Word8+bytes = traversedLazy {-# INLINE bytes #-} --- | 'Data.ByteString.Lazy.Char8.pack' (or 'Data.ByteString.Lazy.Char8.unpack') a list of characters into a 'ByteString'+-- | 'Data.ByteString.Lazy.Char8.pack' (or 'Data.ByteString.Lazy.Char8.unpack') a list of characters into a 'ByteString'. -- -- When writing back to the 'ByteString' it is assumed that every 'Char' -- lies between '\x00' and '\xff'.@@ -47,8 +48,8 @@ -- @'Data.ByteString.Lazy.Char8.pack' x = x '^.' 'packedChars'@ -- -- @'Data.ByteString.Lazy.Char8.unpack' x = x '^.' 'from' 'packedChars'@-packedChars :: Simple Iso String ByteString-packedChars = iso Char8.pack Char8.unpack+packedChars :: Iso' String ByteString+packedChars = iso Char8.pack unpackLazy8 {-# INLINE packedChars #-}  -- | Traverse the individual bytes in a 'ByteString' as characters.@@ -56,9 +57,9 @@ -- When writing back to the 'ByteString' it is assumed that every 'Char' -- lies between '\x00' and '\xff'. ----- @'chars' = 'from' 'packedChars' '.>' 'itraversed'@+-- @'chars' = 'from' 'packedChars' '.' 'itraversed'@ -- -- @'anyOf' 'chars' ('==' \'c\') :: 'ByteString' -> 'Bool'@-chars :: SimpleIndexedTraversal Int ByteString Char-chars = from packedChars .> itraversed+chars :: IndexedTraversal' Int64 ByteString Char+chars = traversedLazy8 {-# INLINE chars #-}
src/Data/ByteString/Lens.hs view
@@ -1,9 +1,8 @@-{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleContexts #-} ----------------------------------------------------------------------------- -- | -- Module      :  Data.ByteString.Lens--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  experimental@@ -23,14 +22,14 @@  -- | Traversals for ByteStrings. class IsByteString t where-  -- | 'Data.ByteString.pack' (or 'Data.ByteString.unpack') a list of bytes into a strict or lazy 'ByteString'+  -- | 'Data.ByteString.pack' (or 'Data.ByteString.unpack') a list of bytes into a strict or lazy 'ByteString'.   --   -- @'Data.ByteString.pack' x = x '^.' 'packedBytes'@   --   -- @'Data.ByteString.unpack' x = x '^.' 'from' 'packedBytes'@-  packedBytes :: Simple Iso [Word8] t+  packedBytes :: Iso' [Word8] t -  -- | 'Data.ByteString.Char8.pack' (or 'Data.ByteString.Char8.unpack') a list of characters into a strict or lazy 'ByteString'+  -- | 'Data.ByteString.Char8.pack' (or 'Data.ByteString.Char8.unpack') a list of characters into a strict or lazy 'ByteString'.   --   -- When writing back to the 'ByteString' it is assumed that every 'Char'   -- lies between '\x00' and '\xff'.@@ -38,15 +37,15 @@   -- @'Data.ByteString.Char8.pack' x = x '^.' 'packedChars'@   --   -- @'Data.ByteString.Char8.unpack' x = x '^.' 'from' 'packedChars'@-  packedChars :: Simple Iso String t+  packedChars :: Iso' String t    -- | Traverse each 'Word8' in a strict or lazy 'ByteString'   ---  -- @'bytes' = 'from' 'packedBytes' '.>' 'itraversed'@+  -- @'bytes' = 'from' 'packedBytes' '.' 'itraversed'@   --   -- @'anyOf' 'bytes' ('==' 0x80) :: 'ByteString' -> 'Bool'@-  bytes :: SimpleIndexedTraversal Int t Word8-  bytes = from packedBytes .> itraversed+  bytes :: IndexedTraversal' Int t Word8+  bytes = from packedBytes . traversed   {-# INLINE bytes #-}    -- | Traverse the individual bytes in a strict or lazy 'ByteString' as characters.@@ -54,11 +53,11 @@   -- When writing back to the 'ByteString' it is assumed that every 'Char'   -- lies between '\x00' and '\xff'.   ---  -- @'chars' = 'from' 'packedChars' . 'traverse'@+  -- @'chars' = 'from' 'packedChars' '.' 'traverse'@   --   -- @'anyOf' 'chars' ('==' \'c\') :: 'ByteString' -> 'Bool'@-  chars :: SimpleIndexedTraversal Int t Char-  chars = from packedChars .> itraversed+  chars :: IndexedTraversal' Int t Char+  chars = from packedChars . traversed   {-# INLINE chars #-}  instance IsByteString Strict.ByteString where@@ -76,7 +75,7 @@   {-# INLINE packedBytes #-}   packedChars = Lazy.packedChars   {-# INLINE packedChars #-}-  bytes = Lazy.bytes+  bytes = from packedBytes . traversed   {-# INLINE bytes #-}-  chars = Lazy.chars+  chars = from packedChars . traversed   {-# INLINE chars #-}
src/Data/ByteString/Strict/Lens.hs view
@@ -1,9 +1,10 @@-{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE BangPatterns #-} ----------------------------------------------------------------------------- -- | -- Module      :  Data.ByteString.Strict.Lens--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-2013 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  experimental@@ -16,26 +17,30 @@   ) where  import Control.Lens-import Data.ByteString as Words+import Control.Lens.Internal.ByteString+import Data.ByteString       as Words import Data.ByteString.Char8 as Char8-import Data.Word (Word8)+import Data.Word +-- $setup+-- >>> import Control.Lens+ -- | 'Data.ByteString.pack' (or 'Data.ByteString.unpack') a list of bytes into a 'ByteString' -- -- @'Data.ByteString.pack' x = x '^.' 'packedBytes'@ -- -- @'Data.ByteString.unpack' x = x '^.' 'from' 'packedBytes'@-packedBytes :: Simple Iso [Word8] ByteString-packedBytes = iso Words.pack Words.unpack+packedBytes :: Iso' [Word8] ByteString+packedBytes = iso Words.pack unpackStrict {-# INLINE packedBytes #-} --- | Traverse each 'Word8' in a 'ByteString'+-- | Traverse each 'Word8' in a 'ByteString'. ----- @'bytes' = 'from' 'packedBytes' '.>' 'itraversed'@+-- @'bytes' = 'from' 'packedBytes' '.' 'itraversed'@ -- -- @'anyOf' 'bytes' ('==' 0x80) :: 'ByteString' -> 'Bool'@-bytes :: SimpleIndexedTraversal Int ByteString Word8-bytes = from packedBytes .> itraversed+bytes :: IndexedTraversal' Int ByteString Word8+bytes = traversedStrictTree 0 {-# INLINE bytes #-}  -- | 'Data.ByteString.Char8.pack' (or 'Data.ByteString.Char8.unpack') a list of characters into a 'ByteString'@@ -46,8 +51,8 @@ -- @'Data.ByteString.Char8.pack' x = x '^.' 'packedChars'@ -- -- @'Data.ByteString.Char8.unpack' x = x '^.' 'from' 'packedChars'@-packedChars :: Simple Iso String ByteString-packedChars = iso Char8.pack Char8.unpack+packedChars :: Iso' String ByteString+packedChars = iso Char8.pack unpackStrict8 {-# INLINE packedChars #-}  -- | Traverse the individual bytes in a 'ByteString' as characters.@@ -55,9 +60,9 @@ -- When writing back to the 'ByteString' it is assumed that every 'Char' -- lies between '\x00' and '\xff'. ----- @'chars' = 'from' 'packedChars' . 'traverse'@+-- @'chars' = 'from' 'packedChars' '.' 'traverse'@ -- -- @'anyOf' 'chars' ('==' \'c\') :: 'ByteString' -> 'Bool'@-chars :: SimpleIndexedTraversal Int ByteString Char-chars = from packedChars .> itraversed+chars :: IndexedTraversal' Int ByteString Char+chars = traversedStrictTree8 0 {-# INLINE chars #-}
src/Data/Complex/Lens.hs view
@@ -1,5 +1,4 @@ {-# LANGUAGE CPP #-}-{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleContexts #-} #ifndef MIN_VERSION_base #define MIN_VERSION_base(x,y,z) 1@@ -7,7 +6,7 @@ ----------------------------------------------------------------------------- -- | -- Module      :  Data.Complex.Lens--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  experimental@@ -23,7 +22,6 @@   , _magnitude   , _phase   , _conjugate-  , complex   ) where  import Control.Applicative@@ -34,7 +32,7 @@ -- >>> import Debug.SimpleReflect -- >>> let { a ≈ b = abs (a - b) < 1e-6; infix 4 ≈ } --- | Access the 'realPart' of a 'Complex' number+-- | Access the 'realPart' of a 'Complex' number. -- -- >>> (a :+ b)^._realPart -- a@@ -44,13 +42,14 @@ -- -- @'_realPart' :: 'Functor' f => (a -> f a) -> 'Complex' a -> f ('Complex' a)@ #if MIN_VERSION_base(4,4,0)-_realPart :: Simple Lens (Complex a) a+_realPart :: Lens' (Complex a) a #else-_realPart :: RealFloat a => Simple Lens (Complex a) a+_realPart :: RealFloat a => Lens' (Complex a) a #endif _realPart f (a :+ b) = (:+ b) <$> f a+{-# INLINE _realPart #-} --- | Access the 'imagPart' of a 'Complex' number+-- | Access the 'imagPart' of a 'Complex' number. -- -- >>> (a :+ b)^._imagPart -- b@@ -60,13 +59,14 @@ -- -- @'_imagPart' :: 'Functor' f => (a -> f a) -> 'Complex' a -> f ('Complex' a)@ #if MIN_VERSION_base(4,4,0)-_imagPart :: Simple Lens (Complex a) a+_imagPart :: Lens' (Complex a) a #else-_imagPart :: RealFloat a => Simple Lens (Complex a) a+_imagPart :: RealFloat a => Lens' (Complex a) a #endif _imagPart f (a :+ b) = (a :+) <$> f b+{-# INLINE _imagPart #-} --- | This isn't /quite/ a legal lens. Notably the+-- | This isn't /quite/ a legal 'Lens'. Notably the -- -- @'view' l ('set' l b a) = b@ --@@ -76,15 +76,16 @@ -- that! -- -- Otherwise, this is a perfectly cromulent 'Lens'.-_polar :: RealFloat a => Simple Iso (Complex a) (a,a)+_polar :: RealFloat a => Iso' (Complex a) (a,a) _polar = iso polar (uncurry mkPolar)+{-# INLINE _polar #-} --- | Access the 'magnitude' of a 'Complex' number+-- | Access the 'magnitude' of a 'Complex' number. -- -- >>> (10.0 :+ 20.0) & _magnitude *~ 2 -- 20.0 :+ 40.0 ----- This isn't /quite/ a legal lens. Notably the+-- This isn't /quite/ a legal 'Lens'. Notably the -- -- @'view' l ('set' l b a) = b@ --@@ -94,18 +95,19 @@ -- Otherwise, this is a perfectly cromulent 'Lens'. -- -- Setting the 'magnitude' of a zero 'Complex' number assumes the 'phase' is 0.-_magnitude :: RealFloat a => Simple Lens (Complex a) a+_magnitude :: RealFloat a => Lens' (Complex a) a _magnitude f c = setMag <$> f r   where setMag r' | r /= 0    = c * (r' / r :+ 0)                   | otherwise = r' :+ 0         r = magnitude c+{-# INLINE _magnitude #-} --- | Access the 'phase' of a 'Complex' number+-- | Access the 'phase' of a 'Complex' number. -- -- >>> (mkPolar 10 (2-pi) & _phase +~ pi & view _phase) ≈ 2 -- True ----- This isn't /quite/ a legal lens. Notably the+-- This isn't /quite/ a legal 'Lens'. Notably the -- -- @'view' l ('set' l b a) = b@ --@@ -113,36 +115,19 @@ -- The phase is always in that range when queried. So don't do that! -- -- Otherwise, this is a perfectly cromulent 'Lens'.-_phase :: RealFloat a => Simple Lens (Complex a) a+_phase :: RealFloat a => Lens' (Complex a) a _phase f c = setPhase <$> f theta   where setPhase theta' = c * cis (theta' - theta)         theta = phase c+{-# INLINE _phase #-} --- | Access the 'conjugate' of a 'Complex' number+-- | Access the 'conjugate' of a 'Complex' number. -- -- >>> (2.0 :+ 3.0) & _conjugate . _imagPart -~ 1 -- 2.0 :+ 4.0 -- -- >>> (mkPolar 10.0 2.0 ^. _conjugate . _phase) ≈ (-2.0) -- True-_conjugate :: RealFloat a => Simple Iso (Complex a) (Complex a)+_conjugate :: RealFloat a => Iso' (Complex a) (Complex a) _conjugate = iso conjugate conjugate---- | Traverse both the 'realPart' and the 'imagPart' of a 'Complex' number.------ >>> a :+ b & complex .~ c--- c :+ c------ >>> a :+ b & complex *~ 2--- a * 2 :+ b * 2------ >>> sumOf complex (a :+ b)--- a + b------ @'complex' :: 'Applicative' f => (a -> f b) -> 'Complex' a -> f ('Complex' b)@-#if MIN_VERSION_base(4,4,0)-complex :: Traversal (Complex a) (Complex b) a b-#else-complex :: (RealFloat a, RealFloat b) => Traversal (Complex a) (Complex b) a b-#endif-complex f (a :+ b) = (:+) <$> f a <*> f b+{-# INLINE _conjugate #-}
src/Data/Data/Lens.hs view
@@ -1,12 +1,10 @@ {-# LANGUAGE CPP #-}-{-# LANGUAGE GADTs #-} {-# LANGUAGE MagicHash #-} {-# LANGUAGE Rank2Types #-} {-# LANGUAGE UnboxedTuples #-} {-# LANGUAGE PatternGuards #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE LiberalTypeSynonyms #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE ExistentialQuantification #-} #ifdef TRUSTWORTHY@@ -15,7 +13,7 @@ ----------------------------------------------------------------------------- -- | -- Module      :  Data.Data.Lens--- Copyright   :  (C) 2012 Edward Kmett, (C) 2006-2012 Neil Mitchell+-- Copyright   :  (C) 2012-2013 Edward Kmett, (C) 2006-2012 Neil Mitchell -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  experimental@@ -45,21 +43,18 @@  import           Control.Applicative import           Control.Exception as E-import           Control.Lens.Getter-import           Control.Lens.Indexed-import           Control.Lens.IndexedLens-import           Control.Lens.IndexedSetter-import           Control.Lens.IndexedTraversal-import           Control.Lens.Internal+import           Control.Lens.Combinators+import           Control.Lens.Internal.Context+import           Control.Lens.Internal.Indexed import           Control.Lens.Setter import           Control.Lens.Traversal import           Control.Lens.Type import           Data.Data import           GHC.IO import           Unsafe.Coerce as Unsafe+import           Data.Maybe  #ifndef SAFE-import           Control.Arrow ((&&&)) import           Data.Foldable import qualified Data.HashMap.Strict as M import           Data.HashMap.Strict (HashMap, (!))@@ -70,6 +65,10 @@ import           GHC.Exts (realWorld#) #endif +{-# ANN module "HLint: ignore Eta reduce" #-}+{-# ANN module "HLint: ignore Use foldl" #-}+{-# ANN module "HLint: ignore Reduce duplication" #-}+ -- $setup -- >>> import Control.Lens @@ -84,6 +83,7 @@ -- This really belongs in @Data.Data@. gtraverse :: (Applicative f, Data a) => (forall d. Data d => d -> f d) -> a -> f a gtraverse f = gfoldl (\x y -> x <*> f y) pure+{-# INLINE gtraverse #-}  ------------------------------------------------------------------------------- -- Naïve Traversal@@ -92,7 +92,7 @@ -- | Naïve 'Traversal' using 'Data'. This does not attempt to optimize the traversal. -- -- This is primarily useful when the children are immediately obvious, and for benchmarking.-tinplate :: (Data s, Typeable a) => Simple Traversal s a+tinplate :: (Data s, Typeable a) => Traversal' s a tinplate f = gfoldl (step f) pure {-# INLINE tinplate #-} @@ -111,7 +111,7 @@ -- of areas that cannot contain a value of type @a@. -- -- This is 'uniplate' with a more liberal signature.-template :: forall s a. (Data s, Typeable a) => Simple Traversal s a+template :: forall s a. (Data s, Typeable a) => Traversal' s a #ifdef SAFE template = tinplate #else@@ -124,12 +124,12 @@ -- type @a@ using 'Data'. -- -- 'uniplate' is a useful default definition for 'Control.Lens.Plated.plate'-uniplate :: Data a => Simple Traversal a a+uniplate :: Data a => Traversal' a a uniplate = template {-# INLINE uniplate #-}  -- | 'biplate' performs like 'template', except when @s ~ a@, it returns itself and nothing else.-biplate :: forall s a. (Data s, Typeable a) => Simple Traversal s a+biplate :: forall s a. (Data s, Typeable a) => Traversal' s a #ifdef SAFE biplate f s   | typeOf (undefined :: s) == typeOf (undefined :: a) = pure s@@ -152,7 +152,7 @@  instance Typeable a => Exception (FieldException a) -lookupon :: Typeable a => SimpleLensLike (Indexing Mutator) s a -> (s -> a) -> s -> Maybe (Int, Context a a s)+lookupon :: Typeable a => LensLike' (Indexing Mutator) s a -> (s -> a) -> s -> Maybe (Int, Context a a s) lookupon l field s = case unsafePerformIO $ E.try $ evaluate $ field $ s & indexing l %@~ \i (a::a) -> E.throw (FieldException i a) of   Right _ -> Nothing   Left e -> case fromException e of@@ -161,7 +161,7 @@ {-# INLINE lookupon #-}  --- | This automatically constructs a 'Simple' 'Traversal' from an function.+-- | This automatically constructs a 'Traversal'' from an function. -- -- >>> (2,4) & upon fst *~ 5 -- (10,4)@@ -192,15 +192,15 @@ -- -- Second, the structure must not contain strict or unboxed fields of the same type that will be visited by 'Data' ----- @'upon' :: ('Data' s, 'Data' a) => (s -> a) -> 'SimpleIndexedTraversal' [Int] s a@-upon :: forall k f s a. (Indexable [Int] k, Applicative f, Data s, Data a) => (s -> a) -> k (a -> f a) (s -> f s)-upon field = indexed $ \ f s -> case lookupon template field s of+-- @'upon' :: ('Data' s, 'Data' a) => (s -> a) -> 'IndexedTraversal'' [Int] s a@+upon :: forall p f s a. (Indexable [Int] p, Applicative f, Data s, Data a) => (s -> a) -> p a (f a) -> s -> f s+upon field f s = case lookupon template field s of   Nothing -> pure s   Just (i, Context k0 a0) ->     let-      go :: [Int] -> SimpleTraversal s a -> (a -> s) -> a -> f s+      go :: [Int] -> Traversal' s a -> (a -> s) -> a -> f s       go is l k a = case lookupon (l.uniplate) field s of-        Nothing                 -> k <$> f (reverse is) a+        Nothing                 -> k <$> indexed f (reverse is) a         Just (j, Context k' a') -> go (j:is) (l.elementOf uniplate j) k' a'     in go [i] (elementOf template i) k0 a0 {-# INLINE upon #-}@@ -214,19 +214,19 @@ -- -- >>> upon' (tail.tail) .~ [10,20] $ [1,2,3,4] -- [1,2,10,20]-upon' :: forall s a. (Data s, Data a) => (s -> a) -> SimpleIndexedLens [Int] s a-upon' field = indexed $ \ f s -> let+upon' :: forall s a. (Data s, Data a) => (s -> a) -> IndexedLens' [Int] s a+upon' field f s = let     ~(isn, kn) = case lookupon template field s of       Nothing -> (error "upon': no index, not a member", const s)       Just (i, Context k0 _) -> go [i] (elementOf template i) k0-    go :: [Int] -> SimpleTraversal s a -> (a -> s) -> ([Int], a -> s)+    go :: [Int] -> Traversal' s a -> (a -> s) -> ([Int], a -> s)     go is l k = case lookupon (l.uniplate) field s of       Nothing                -> (reverse is, k)       Just (j, Context k' _) -> go (j:is) (l.elementOf uniplate j) k'-  in kn <$> f isn (field s)+  in kn <$> indexed f isn (field s) {-# INLINE upon' #-} --- | This automatically constructs a 'Simple' 'Traversal' from a field accessor.+-- | This automatically constructs a 'Traversal'' from a field accessor. -- -- The index of the 'Traversal' can be used as an offset into @'elementOf' ('indexing' 'template')@ or into the list -- returned by @'holesOf' 'template'@.@@ -241,10 +241,10 @@ -- [1,2,10,20] -- -- When in doubt, use 'upon' instead.-onceUpon :: forall s a. (Data s, Typeable a) => (s -> a) -> SimpleIndexedTraversal Int s a-onceUpon field = indexed $ \f s -> case lookupon template field s of-  Nothing -> pure s-  Just (i, Context k a) -> k <$> f i a+onceUpon :: forall s a. (Data s, Typeable a) => (s -> a) -> IndexedTraversal' Int s a+onceUpon field f s = case lookupon template field s of+  Nothing               -> pure s+  Just (i, Context k a) -> k <$> indexed f i a {-# INLINE onceUpon #-}  -- | This more trusting version of 'upon' uses your function directly as the getter for a 'Lens'.@@ -262,12 +262,9 @@ -- @'elementOf' ('indexed' 'template')@ or into the list returned by @'holesOf' 'template'@. -- -- When in doubt, use 'upon'' instead.-onceUpon' :: forall s a. (Data s, Typeable a) => (s -> a) -> SimpleIndexedLens Int s a-onceUpon' field = indexed $ \f s -> let-    ~(i, Context k _) = case lookupon template field s of-      Nothing -> error "upon': no index, not a member"-      Just ip -> ip-  in k <$> f i (field s)+onceUpon' :: forall s a. (Data s, Typeable a) => (s -> a) -> IndexedLens' Int s a+onceUpon' field f s = k <$> indexed f i (field s) where+  ~(i, Context k _) = fromMaybe (error "upon': no index, not a member") (lookupon template field s) {-# INLINE onceUpon' #-}  #ifndef SAFE@@ -293,6 +290,7 @@     gmapQ dataBox (fromConstr c `asTypeOf` x)   | otherwise = []   where dt = dataTypeOf x+{-# INLINE sybChildren #-}  ------------------------------------------------------------------------------- -- HitMap@@ -330,11 +328,13 @@        where x' = f x {-# INLINE fixEq #-} +#ifndef HLINT -- | inlineable 'unsafePerformIO' inlinePerformIO :: IO a -> a inlinePerformIO (IO m) = case m realWorld# of   (# _, r #) -> r {-# INLINE inlinePerformIO #-}+#endif  ------------------------------------------------------------------------------- -- Cache@@ -382,6 +382,7 @@   fmap f (Hit a) = Hit (f a)   fmap _ Follow  = Follow   fmap _ Miss    = Miss+  {-# INLINE fmap #-}  ------------------------------------------------------------------------------- -- Oracles@@ -391,6 +392,7 @@  instance Functor Oracle where   fmap f (Oracle g) = Oracle (fmap f . g)+  {-# INLINE fmap #-}  hitTest :: (Data a, Typeable b) => a -> b -> Oracle b hitTest a b@@ -436,7 +438,7 @@ -------------------------------------------------------------------------------  part :: (a -> Bool) -> HashSet a -> (HashSet a, HashSet a)-part p = S.filter p &&& S.filter (not . p)+part p s = (S.filter p s, S.filter (not . p) s) {-# INLINE part #-}  type Follower = TypeRep -> Bool@@ -445,7 +447,7 @@ follower a b m   | S.null hit               = const False   | S.null miss              = const True-  | S.size hit < S.size miss = \k -> S.member k hit+  | S.size hit < S.size miss = S.member ?? hit   | otherwise = \k -> not (S.member k miss)   where (hit, miss) = part (\x -> S.member b (m ! x)) (S.insert a (m ! a)) 
src/Data/Dynamic/Lens.hs view
@@ -1,25 +1,42 @@-{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE MultiParamTypeClasses #-} ----------------------------------------------------------------------------- -- | -- Module      :  Data.Dynamic.Lens--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-2013 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com>--- Stability   :  provisional--- Portability :  portable+-- Stability   :  experimental+-- Portability :  non-portable -- ---------------------------------------------------------------------------- module Data.Dynamic.Lens-  ( dynamic+  ( AsDynamic(..)   ) where +import Control.Exception+import Control.Exception.Lens import Control.Lens import Data.Dynamic --- |--- Traverse the typed value contained in a 'Dynamic' where the type required by your function matches that--- of the contents of the 'Dynamic'.-dynamic :: Typeable a => Simple Prism Dynamic a-dynamic = prism toDyn $ \e -> maybe (Left e) Right (fromDynamic e)-{-# INLINE dynamic #-}+-- | Any 'Dynamic' can be thrown as an 'Exception'+class AsDynamic t where+  -- | This 'Prism' allows you to traverse the typed value contained in a+  -- 'Dynamic' where the type required by your function matches that+  -- of the contents of the 'Dynamic', or construct a 'Dynamic' value+  -- out of whole cloth. It can also be used to catch or throw a 'Dynamic'+  -- value as 'SomeException'.+  --+  -- @+  -- '_Dynamic' :: 'Typeable' a => 'Prism'' 'Dynamic'       a+  -- '_Dynamic' :: 'Typeable' a => 'Prism'' 'SomeException' a+  -- @+  _Dynamic :: Typeable a => Prism' t a++instance AsDynamic Dynamic where+  _Dynamic = prism' toDyn fromDynamic+  {-# INLINE _Dynamic #-}++instance AsDynamic SomeException where+  _Dynamic = exception.prism' toDyn fromDynamic+  {-# INLINE _Dynamic #-}
src/Data/HashSet/Lens.hs view
@@ -6,7 +6,7 @@ ----------------------------------------------------------------------------- -- | -- Module      :  Data.HashSet.Lens--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  provisional@@ -18,8 +18,9 @@   , setOf   ) where -import Control.Lens.Getter-import Control.Lens.Setter+import Control.Lens.Getter (Getting, views)+import Control.Lens.Setter (setting)+import Control.Lens.Type import Data.HashSet as HashSet import Data.Hashable @@ -29,21 +30,20 @@ -- | This 'Setter' can be used to change the type of a 'HashSet' by mapping -- the elements to new values. ----- Sadly, you can't create a valid 'Control.Lens.Traversal.Traversal' for a 'Set', but you can--- manipulate it by reading using 'folded' and reindexing it via 'setmapped'.----setmapped :: (Eq i, Hashable i, Eq j, Hashable j) => Setter (HashSet i) (HashSet j) i j-setmapped = sets HashSet.map+-- Sadly, you can't create a valid 'Traversal' for a 'Set', but you can+-- manipulate it by reading using 'Control.Lens.Fold.folded' and reindexing it via 'setmapped'.+setmapped :: (Eq i, Hashable i, Eq j, Hashable j) => IndexPreservingSetter (HashSet i) (HashSet j) i j+setmapped = setting HashSet.map {-# INLINE setmapped #-} --- | Construct a set from a 'Getter', 'Control.Lens.Fold.Fold', 'Control.Lens.Traversal.Traversal', 'Control.Lens.Type.Lens' or 'Control.Lens.Iso.Iso'.+-- | Construct a set from a 'Getter', 'Control.Lens.Fold.Fold', 'Control.Lens.Traversal.Traversal', 'Control.Lens.Lens.Lens' or 'Control.Lens.Iso.Iso'. -- -- @--- 'setOf' :: 'Hashable' a         => 'Getter' s a           -> s -> 'HashSet' a--- 'setOf' :: ('Eq' a, 'Hashable' a) => 'Control.Lens.Fold.Fold' s a             -> s -> 'HashSet' a--- 'setOf' :: 'Hashable' a         => 'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a       -> s -> 'HashSet' a--- 'setOf' :: 'Hashable' a         => 'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a      -> s -> 'HashSet' a--- 'setOf' :: ('Eq' a, 'Hashable' a) => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a -> s -> 'HashSet' a+-- 'setOf' :: 'Hashable' a         => 'Getter' s a     -> s -> 'HashSet' a+-- 'setOf' :: ('Eq' a, 'Hashable' a) => 'Fold' s a       -> s -> 'HashSet' a+-- 'setOf' :: 'Hashable' a         => 'Iso'' s a       -> s -> 'HashSet' a+-- 'setOf' :: 'Hashable' a         => 'Lens'' s a      -> s -> 'HashSet' a+-- 'setOf' :: ('Eq' a, 'Hashable' a) => 'Traversal'' s a -> s -> 'HashSet' a -- @ setOf :: Hashable a => Getting (HashSet a) s t a b -> s -> HashSet a setOf l = views l HashSet.singleton
src/Data/IntSet/Lens.hs view
@@ -2,7 +2,7 @@ ----------------------------------------------------------------------------- -- | -- Module      :  Data.IntSet.Lens--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  provisional@@ -38,21 +38,24 @@ -- -- >>> over setmapped (+1) (fromList [1,2,3,4]) -- fromList [2,3,4,5]-setmapped :: Simple Setter IntSet Int-setmapped = sets IntSet.map+setmapped :: IndexPreservingSetter' IntSet Int+setmapped = setting IntSet.map {-# INLINE setmapped #-}  -- | Construct an 'IntSet' from a 'Getter', 'Fold', 'Traversal', 'Lens' or 'Iso'. --+-- >>> setOf folded [1,2,3,4]+-- fromList [1,2,3,4]+-- -- >>> setOf (folded._2) [("hello",1),("world",2),("!!!",3)] -- fromList [1,2,3] -- -- @--- 'setOf' :: 'Getter' s 'Int'           -> s -> 'IntSet'--- 'setOf' :: 'Fold' s 'Int'             -> s -> 'IntSet'--- 'setOf' :: 'Simple' 'Iso' s 'Int'       -> s -> 'IntSet'--- 'setOf' :: 'Simple' 'Lens' s 'Int'      -> s -> 'IntSet'--- 'setOf' :: 'Simple' 'Traversal' s 'Int' -> s -> 'IntSet'+-- 'setOf' :: 'Getter' s 'Int'     -> s -> 'IntSet'+-- 'setOf' :: 'Fold' s 'Int'       -> s -> 'IntSet'+-- 'setOf' :: 'Iso'' s 'Int'       -> s -> 'IntSet'+-- 'setOf' :: 'Lens'' s 'Int'      -> s -> 'IntSet'+-- 'setOf' :: 'Traversal'' s 'Int' -> s -> 'IntSet' -- @ setOf :: Getting IntSet s t Int b -> s -> IntSet setOf l = views l IntSet.singleton
src/Data/List/Lens.hs view
@@ -1,10 +1,9 @@-{-# LANGUAGE LiberalTypeSynonyms #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE Rank2Types #-} ----------------------------------------------------------------------------- -- | -- Module      :  Data.List.Lens--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  provisional@@ -14,15 +13,9 @@ -- ---------------------------------------------------------------------------- module Data.List.Lens-  (-    _head-  , _tail-  , _last-  , _init-  , strippingPrefix+  ( strippingPrefix   ) where -import Control.Applicative import Control.Lens import Data.List @@ -32,141 +25,6 @@ -- >>> let f :: Expr -> Expr; f = Debug.SimpleReflect.Vars.f -- >>> let g :: Expr -> Expr; g = Debug.SimpleReflect.Vars.g --- | A 'Traversal' reading and writing to the 'head' of a /non-empty/ list.------ >>> [a,b,c]^? _head--- Just a------ >>> [a,b,c] & _head .~ d--- [d,b,c]------ >>> [a,b,c] & _head %~ f--- [f a,b,c]------ >>> [] & _head %~ f--- []------ >>> [1,2,3]^?!_head--- 1------ >>> []^?_head--- Nothing------ >>> [1,2]^?_head--- Just 1------ >>> [] & _head .~ 1--- []------ >>> [0] & _head .~ 2--- [2]------ >>> [0,1] & _head .~ 2--- [2,1]-------_head :: SimpleIndexedTraversal Int [a] a-_head = indexed $ \f aas -> case aas of-  (a:as) -> (:as) <$> f (0 :: Int) a-  _      -> pure aas-{-# INLINE _head #-}---- | A 'Traversal' reading and writing to the 'tail' of a /non-empty/ list------ >>> [a,b] & _tail .~ [c,d,e]--- [a,c,d,e]------ >>> [] & _tail .~ [a,b]--- []------ >>> [a,b,c,d,e] & _tail.traverse %~ f--- [a,f b,f c,f d,f e]------ >>> [1,2] & _tail .~ [3,4,5]--- [1,3,4,5]------ >>> [] & _tail .~ [1,2]--- []------ >>> [a,b,c]^?_tail--- Just [b,c]------ >>> [1,2]^?!_tail--- [2]------ >>> "hello"^._tail--- "ello"------ >>> ""^._tail--- ""-_tail :: Simple Traversal [a] [a]-_tail f (a:as) = (a:) <$> f as-_tail _ as     = pure as-{-# INLINE _tail #-}---- | A 'Traversal' reading and writing to the last element of a /non-empty/ list------ >>> [a,b,c]^?!_last--- c------ >>> []^?_last--- Nothing------ >>> [a,b,c] & _last %~ f--- [a,b,f c]------ >>> [1,2]^?_last--- Just 2------ >>> [] & _last .~ 1--- []------ >>> [0] & _last .~ 2--- [2]------ >>> [0,1] & _last .~ 2--- [0,2]-_last :: SimpleIndexedTraversal Int [a] a-_last = indexed $ \f aas -> case aas of-  []     -> pure aas-  (a:as) -> let go n b []  = return <$> f n b-                go n b (c:cs) = (b:) <$> (go $! n + 1) c cs-            in go (0 :: Int) a as-{-# INLINE _last #-}---- | A 'Traversal' reading and replacing all but the a last element of a /non-empty/ list------ >>> [a,b,c,d]^?_init--- Just [a,b,c]------ >>> []^?_init--- Nothing------ >>> [a,b] & _init .~ [c,d,e]--- [c,d,e,b]------ >>> [] & _init .~ [a,b]--- []------ >>> [a,b,c,d] & _init.traverse %~ f--- [f a,f b,f c,d]------ >>> [1,2,3]^?_init--- Just [1,2]------ >>> [1,2,3,4]^?!_init--- [1,2,3]------ >>> "hello"^._init--- "hell"------ >>> ""^._init--- ""-_init :: Simple Traversal [a] [a]-_init _ [] = pure []-_init f as = (++ [Prelude.last as]) <$> f (Prelude.init as)-{-# INLINE _init #-}- -- | A 'Prism' stripping a prefix from a list when used as a 'Traversal', or -- prepending that prefix when run backwards: --@@ -176,9 +34,8 @@ -- >>> "review" ^? strippingPrefix "pre" -- Nothing ----- >>> "amble"^.remit (strippingPrefix "pre")+-- >>> "amble"^.re (strippingPrefix "pre") -- "preamble"-strippingPrefix :: Eq a => [a] -> Simple Prism [a] [a]-strippingPrefix ps = prism (ps ++) $ \xs -> case stripPrefix ps xs of-  Nothing  -> Left xs-  Just xs' -> Right xs'+strippingPrefix :: Eq a => [a] -> Prism' [a] [a]+strippingPrefix ps = prism' (ps ++) (stripPrefix ps)+{-# INLINE strippingPrefix #-}
src/Data/List/Split/Lens.hs view
@@ -1,10 +1,7 @@-{-# LANGUAGE Rank2Types #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE LiberalTypeSynonyms #-} ---------------------------------------------------------------------------- -- | -- Module      :  Data.List.Split.Lens--- Copyright   :  (C) 2012 Edward Kmett, Alexander Altman+-- Copyright   :  (C) 2012-2013 Edward Kmett, Alexander Altman -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  provisional@@ -37,7 +34,6 @@  import Control.Applicative import Control.Lens-import Control.Lens.Classes import Data.Monoid import Data.List.Split import Data.List.Split.Internals@@ -45,7 +41,7 @@ -- $setup -- >>> import Control.Lens --- | Obtain a 'Fold' by splitting another 'Fold', 'Control.Lens.Type.Lens', 'Getter' or 'Control.Lens.Traversal.Traversal' according to the given splitting strategy.+-- | Obtain a 'Fold' by splitting another 'Fold', 'Lens', 'Getter' or 'Traversal' according to the given splitting strategy. -- -- @ -- 'splitting' :: 'Splitter' a -> 'Fold' i s a -> 'Fold' [i] s [a]@@ -54,7 +50,7 @@ splitting s l f = coerce . traverse f . split s . toListOf l {-# INLINE splitting #-} --- | Obtain a 'Fold' by splitting another 'Fold', 'Control.Lens.Type.Lens', 'Getter' or 'Control.Lens.Traversal.Traversal' on the given delimiter.+-- | Obtain a 'Fold' by splitting another 'Fold', 'Lens', 'Getter' or 'Traversal' on the given delimiter. -- -- Equivalent to @'splitting' '.' 'dropDelims' '.' 'onSublist'@. --@@ -65,7 +61,7 @@ splittingOn s l f = coerce . traverse f . splitOn s . toListOf l {-# INLINE splittingOn #-} --- | Obtain a 'Fold' by splitting another 'Fold', 'Control.Lens.Type.Lens', 'Getter' or 'Control.Lens.Traversal.Traversal' on any of the given elements.+-- | Obtain a 'Fold' by splitting another 'Fold', 'Lens', 'Getter' or 'Traversal' on any of the given elements. -- -- Equivalent to @'splitting' '.' 'dropDelims' '.' 'oneOf'@. --@@ -76,7 +72,7 @@ splittingOneOf s l f = coerce . traverse f . splitOneOf s . toListOf l {-# INLINE splittingOneOf #-} --- | Obtain a 'Fold' by splitting another 'Fold', 'Control.Lens.Type.Lens', 'Getter' or 'Control.Lens.Traversal.Traversal' on elements satisfying the given predicate.+-- | Obtain a 'Fold' by splitting another 'Fold', 'Lens', 'Getter' or 'Traversal' on elements satisfying the given predicate. -- -- Equivalent to @'splitting' '.' 'dropDelims' '.' 'whenElt'@. --@@ -87,7 +83,7 @@ splittingWhen s l f = coerce . traverse f . splitWhen s . toListOf l {-# INLINE splittingWhen #-} --- | Obtain a 'Fold' by splitting another 'Fold', 'Control.Lens.Type.Lens', 'Getter' or 'Control.Lens.Traversal.Traversal' into chunks terminated by the given delimiter.+-- | Obtain a 'Fold' by splitting another 'Fold', 'Lens', 'Getter' or 'Traversal' into chunks terminated by the given delimiter. -- -- Equivalent to @'splitting' '.' 'dropDelims' '.' 'onSublist'@. --@@ -98,7 +94,7 @@ endingBy s l f = coerce . traverse f . endBy s . toListOf l {-# INLINE endingBy #-} --- | Obtain a 'Fold' by splitting another 'Fold', 'Control.Lens.Type.Lens', 'Getter' or 'Control.Lens.Traversal.Traversal' into chunks terminated by any of the given elements.+-- | Obtain a 'Fold' by splitting another 'Fold', 'Lens', 'Getter' or 'Traversal' into chunks terminated by any of the given elements. -- -- Equivalent to @'splitting' '.' 'dropFinalBlank' '.' 'dropDelims' '.' 'oneOf'@. --@@ -109,7 +105,7 @@ endingByOneOf s l f = coerce . traverse f . endByOneOf s . toListOf l {-# INLINE endingByOneOf #-} --- | Obtain a 'Fold' by splitting another 'Fold', 'Control.Lens.Type.Lens', 'Getter' or 'Control.Lens.Traversal.Traversal' into "words", with word boundaries indicated by the given predicate.+-- | Obtain a 'Fold' by splitting another 'Fold', 'Lens', 'Getter' or 'Traversal' into "words", with word boundaries indicated by the given predicate. -- -- Equivalent to @'splitting' '.' 'dropBlanks' '.' 'dropDelims' '.' 'whenElt'@. --@@ -120,7 +116,7 @@ wordingBy s l f = coerce . traverse f . wordsBy s . toListOf l {-# INLINE wordingBy #-} --- | Obtain a 'Fold' by splitting another 'Fold', 'Control.Lens.Type.Lens', 'Getter' or 'Control.Lens.Traversal.Traversal' into "lines", with line boundaries indicated by the given predicate.+-- | Obtain a 'Fold' by splitting another 'Fold', 'Lens', 'Getter' or 'Traversal' into "lines", with line boundaries indicated by the given predicate. -- -- Equivalent to @'splitting' '.' 'dropFinalBlank' '.' 'dropDelims' '.' 'whenElt'@. --@@ -131,7 +127,7 @@ liningBy s l f = coerce . traverse f . linesBy s . toListOf l {-# INLINE liningBy #-} --- | Obtain a 'Fold' by splitting another 'Fold', 'Control.Lens.Type.Lens', 'Getter' or 'Control.Lens.Traversal.Traversal' into length-@n@ pieces.+-- | Obtain a 'Fold' by splitting another 'Fold', 'Lens', 'Getter' or 'Traversal' into length-@n@ pieces. -- -- @ -- 'chunkingOf' :: 'Int' -> 'Fold' s a -> 'Fold' s [a]@@ -141,7 +137,7 @@ chunking s l f = coerce . traverse f . chunksOf s . toListOf l {-# INLINE chunking #-} --- | Obtain a 'Fold' by splitting another 'Fold', 'Control.Lens.Type.Lens', 'Getter' or 'Control.Lens.Traversal.Traversal' into chunks of the given lengths, .+-- | Obtain a 'Fold' by splitting another 'Fold', 'Lens', 'Getter' or 'Traversal' into chunks of the given lengths, . -- -- @ -- 'splittingPlaces' :: 'Integral' n => [n] -> 'Fold' s a -> 'Fold' s [a]@@ -150,7 +146,7 @@ splittingPlaces s l f = coerce . traverse f . splitPlaces s . toListOf l {-# INLINE splittingPlaces #-} --- | Obtain a 'Fold' by splitting another 'Fold', 'Control.Lens.Type.Lens', 'Getter' or 'Control.Lens.Traversal.Traversal' into chunks of the given lengths.  Unlike 'splittingPlaces', the output 'Fold' will always be the same length as the first input argument.+-- | Obtain a 'Fold' by splitting another 'Fold', 'Lens', 'Getter' or 'Traversal' into chunks of the given lengths.  Unlike 'splittingPlaces', the output 'Fold' will always be the same length as the first input argument. -- -- @ -- 'splittingPlacesBlanks' :: 'Integral' n => [n] -> 'Fold' s a -> 'Fold' s [a]@@ -159,37 +155,43 @@ splittingPlacesBlanks s l f = coerce . traverse f . splitPlacesBlanks s . toListOf l {-# INLINE splittingPlacesBlanks #-} - -- | Modify or retrieve the list of delimiters for a 'Splitter'. delimiters :: Lens (Splitter a) (Splitter b) [a -> Bool] [b -> Bool] delimiters f s@Splitter { delimiter = Delimiter ds } = f ds <&> \ds' -> s { delimiter = Delimiter ds' }+{-# INLINE delimiters #-}  -- | Modify or retrieve the policy for what a 'Splitter' to do with delimiters.-delimiting :: Simple Lens (Splitter a) DelimPolicy+delimiting :: Lens' (Splitter a) DelimPolicy delimiting f s@Splitter { delimPolicy = p } = f p <&> \p' -> s { delimPolicy = p' }+{-# INLINE delimiting #-}  -- | Modify or retrieve the policy for what a 'Splitter' should about consecutive delimiters.-condensing :: Simple Lens (Splitter a) Bool+condensing :: Lens' (Splitter a) Bool condensing f s@Splitter { condensePolicy = p } = f (o p) <&> \p' -> s { condensePolicy = i p' } where   i True = Condense   i False = KeepBlankFields   o Condense = True   o KeepBlankFields = False+{-# INLINE condensing #-}  -- | Modify or retrieve the policy for whether a 'Splitter' should drop an initial blank.-keepInitialBlanks :: Simple Lens (Splitter a) Bool+keepInitialBlanks :: Lens' (Splitter a) Bool keepInitialBlanks f s@Splitter { initBlankPolicy = p } = f (keeps p) <&> \p' -> s { initBlankPolicy = end p' }+{-# INLINE keepInitialBlanks #-}  -- | Modify or retrieve the policy for whether a 'Splitter' should drop a final blank.-keepFinalBlanks :: Simple Lens (Splitter a) Bool+keepFinalBlanks :: Lens' (Splitter a) Bool keepFinalBlanks f s@Splitter { finalBlankPolicy = p } = f (keeps p) <&> \p' -> s { finalBlankPolicy = end p' }+{-# INLINE keepFinalBlanks #-}  -- utilities  end :: Bool -> EndPolicy end True  = KeepBlank end False = DropBlank+{-# INLINE end #-}  keeps :: EndPolicy -> Bool keeps KeepBlank = True keeps DropBlank = False+{-# INLINE keeps #-}
src/Data/Sequence/Lens.hs view
@@ -1,10 +1,9 @@ {-# LANGUAGE Rank2Types #-}-{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleContexts #-} ----------------------------------------------------------------------------- -- | -- Module      :  Data.Sequence.Lens--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  experimental@@ -12,10 +11,7 @@ -- ---------------------------------------------------------------------------- module Data.Sequence.Lens-  ( ordinal-  , viewL, viewR-  , _head, _tail-  , _last, _init+  ( viewL, viewR   , sliced, slicedTo, slicedFrom   ) where @@ -30,21 +26,6 @@ -- >>> let f :: Expr -> Expr; f = Debug.SimpleReflect.Vars.f -- >>> let g :: Expr -> Expr; g = Debug.SimpleReflect.Vars.g --- | A 'Lens' that can access the @n@th element of a 'Seq'.------ >>> Seq.fromList [a,b,c,d] & ordinal 2 %~ f--- fromList [a,b,f c,d]------ >>> Seq.fromList [a,b,c,d] & ordinal 2 .~ e--- fromList [a,b,e,d]------ >>> Seq.fromList [a,b,c,d] ^. ordinal 2--- c------ *NB:* This is only a legal lens if there is already such an element!-ordinal :: Int -> SimpleIndexedLens Int (Seq a) a-ordinal i = indexed $ \ f m -> f i (index m i) <&> \a -> update i a m- -- * Sequence isomorphisms  -- | A 'Seq' is isomorphic to a 'ViewL'@@ -60,13 +41,12 @@ -- >>> EmptyL ^. from viewL -- fromList [] ----- >>> from viewL ^$ a :< fromList [b,c]+-- >>> review viewL $ a :< fromList [b,c] -- fromList [a,b,c]--- viewL :: Iso (Seq a) (Seq b) (ViewL a) (ViewL b) viewL = iso viewl $ \ xs -> case xs of   EmptyL ->  mempty-  a :< as -> a <| as+  a :< as -> a Seq.<| as {-# INLINE viewL #-}  -- | A 'Seq' is isomorphic to a 'ViewR'@@ -82,80 +62,14 @@ -- >>> EmptyR ^. from viewR -- fromList [] ----- >>> from viewR ^$ fromList [a,b] :> c+-- >>> review viewR $ fromList [a,b] :> c -- fromList [a,b,c] viewR :: Iso (Seq a) (Seq b) (ViewR a) (ViewR b) viewR = iso viewr $ \xs -> case xs of   EmptyR  -> mempty-  as :> a -> as |> a+  as :> a -> as Seq.|> a {-# INLINE viewR #-} --- * Traversals---- | Traverse the head of a 'Seq'------ >>> fromList [a,b,c,d] & _head %~ f--- fromList [f a,b,c,d]------ >>> fromList [] ^? _head--- Nothing------ >>> fromList [a,b,c,d] ^? _head--- Just a-_head :: SimpleIndexedTraversal Int (Seq a) a-_head = indexed $ \f m -> case viewl m of-  a :< as -> (<| as) <$> f (0::Int) a-  EmptyL  -> pure m-{-# INLINE _head #-}---- | Traverse the tail of a 'Seq'------ >>> fromList [a,b] & _tail .~ fromList [c,d,e]--- fromList [a,c,d,e]------ >>> fromList [a,b,c] ^? _tail--- Just (fromList [b,c])------ >>> fromList [] ^? _tail--- Nothing-_tail :: SimpleTraversal (Seq a) (Seq a)-_tail f m = case viewl m of-  a :< as -> (a <|) <$> f as-  EmptyL  -> pure m-{-# INLINE _tail #-}---- | Traverse the last element of a 'Seq'------ >>> fromList [a,b,c,d] & _last %~ f--- fromList [a,b,c,f d]------ >>> fromList [a,b,c,d] ^? _last--- Just d------ >>> fromList [] ^? _last--- Nothing-_last :: SimpleIndexedTraversal Int (Seq a) a-_last = indexed $ \f m ->  case viewr m of-  as :> a -> (as |>) <$> f (Seq.length as) a-  EmptyR  -> pure m-{-# INLINE _last #-}---- | Traverse all but the last element of a 'Seq'------ >>> fromList [1,2,3] ^? _init--- Just (fromList [1,2])------ >>> fromList [a,b,c,d] & _init.traverse %~ f--- fromList [f a,f b,f c,d]------ >>> fromList [] & _init .~ fromList [a,b,c]--- fromList []-_init :: SimpleTraversal (Seq a) (Seq a)-_init f m = case viewr m of-  as :> a -> (|> a) <$> f as-  EmptyR  -> pure m-{-# INLINE _init #-}- -- | Traverse the first @n@ elements of a 'Seq' -- -- >>> fromList [a,b,c,d,e] ^.. slicedTo 2@@ -166,9 +80,9 @@ -- -- >>> fromList [a,b,c,d,e] & slicedTo 10 .~ x -- fromList [x,x,x,x,x]-slicedTo :: Int -> SimpleIndexedTraversal Int (Seq a) a-slicedTo n = indexed $ \f m -> case Seq.splitAt n m of-  (l,r) -> (>< r) <$> itraverse f l+slicedTo :: Int -> IndexedTraversal' Int (Seq a) a+slicedTo n f m = case Seq.splitAt n m of+  (l,r) -> (>< r) <$> itraverse (indexed f) l {-# INLINE slicedTo #-}  -- | Traverse all but the first @n@ elements of a 'Seq'@@ -181,9 +95,9 @@ -- -- >>> fromList [a,b,c,d,e] & slicedFrom 10 .~ x -- fromList [a,b,c,d,e]-slicedFrom :: Int -> SimpleIndexedTraversal Int (Seq a) a-slicedFrom n = indexed $ \ f m -> case Seq.splitAt n m of-  (l,r) -> (l ><) <$> itraverse (f . (+n)) r+slicedFrom :: Int -> IndexedTraversal' Int (Seq a) a+slicedFrom n f m = case Seq.splitAt n m of+  (l,r) -> (l ><) <$> itraverse (indexed f . (+n)) r {-# INLINE slicedFrom #-}  -- | Traverse all the elements numbered from @i@ to @j@ of a 'Seq'@@ -196,8 +110,8 @@ -- -- >>> fromList [a,b,c,d,e] & sliced 1 3 .~ x -- fromList [a,x,x,b,e]-sliced :: Int -> Int -> SimpleIndexedTraversal Int (Seq a) a-sliced i j = indexed $ \ f s -> case Seq.splitAt i s of+sliced :: Int -> Int -> IndexedTraversal' Int (Seq a) a+sliced i j f s = case Seq.splitAt i s of   (l,mr) -> case Seq.splitAt (j-i) mr of-     (m, r) -> itraverse (f . (+i)) m <&> \n -> l >< n >< r+     (m, r) -> itraverse (indexed f . (+i)) m <&> \n -> l >< n >< r {-# INLINE sliced #-}
src/Data/Set/Lens.hs view
@@ -2,7 +2,7 @@ ----------------------------------------------------------------------------- -- | -- Module      :  Data.Set.Lens--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  provisional@@ -15,7 +15,8 @@   ) where  import Control.Lens.Getter ( Getting, views )-import Control.Lens.Setter ( Setter, sets )+import Control.Lens.Setter ( setting )+import Control.Lens.Type import Data.Set as Set  -- $setup@@ -24,26 +25,29 @@ -- | This 'Setter' can be used to change the type of a 'Set' by mapping -- the elements to new values. ----- Sadly, you can't create a valid 'Control.Lens.Traversal.Traversal' for a 'Set', but you can+-- Sadly, you can't create a valid 'Traversal' for a 'Set', but you can -- manipulate it by reading using 'Control.Lens.Fold.folded' and reindexing it via 'setmapped'. -- -- >>> over setmapped (+1) (fromList [1,2,3,4]) -- fromList [2,3,4,5]-setmapped :: (Ord i, Ord j) => Setter (Set i) (Set j) i j-setmapped = sets Set.map+setmapped :: (Ord i, Ord j) => IndexPreservingSetter (Set i) (Set j) i j+setmapped = setting Set.map {-# INLINE setmapped #-} --- | Construct a set from a 'Getter', 'Control.Lens.Fold.Fold', 'Control.Lens.Traversal.Traversal', 'Control.Lens.Type.Lens' or 'Control.Lens.Iso.Iso'.+-- | Construct a set from a 'Getter', 'Control.Lens.Fold.Fold', 'Control.Lens.Traversal.Traversal', 'Control.Lens.Lens.Lens' or 'Control.Lens.Iso.Iso'. --+-- >>> setOf folded ["hello","world"]+-- fromList ["hello","world"]+-- -- >>> setOf (folded._2) [("hello",1),("world",2),("!!!",3)] -- fromList [1,2,3] -- -- @--- 'setOf' ::          'Getter' s a           -> s -> 'Set' a--- 'setOf' :: 'Ord' a => 'Control.Lens.Fold.Fold' s a             -> s -> 'Set' a--- 'setOf' ::          'Control.Lens.Type.Simple' 'Control.Lens.Iso.Iso' s a       -> s -> 'Set' a--- 'setOf' ::          'Control.Lens.Type.Simple' 'Control.Lens.Type.Lens' s a      -> s -> 'Set' a--- 'setOf' :: 'Ord' a => 'Control.Lens.Type.Simple' 'Control.Lens.Traversal.Traversal' s a -> s -> 'Set' a+-- 'setOf' ::          'Getter' s a     -> s -> 'Set' a+-- 'setOf' :: 'Ord' a => 'Fold' s a       -> s -> 'Set' a+-- 'setOf' ::          'Iso'' s a       -> s -> 'Set' a+-- 'setOf' ::          'Lens'' s a      -> s -> 'Set' a+-- 'setOf' :: 'Ord' a => 'Traversal'' s a -> s -> 'Set' a -- @ setOf :: Getting (Set a) s t a b -> s -> Set a setOf l = views l Set.singleton
src/Data/Text/Lazy/Lens.hs view
@@ -1,5 +1,4 @@ {-# LANGUAGE CPP #-}-{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} #ifdef TRUSTWORTHY@@ -8,7 +7,7 @@ ----------------------------------------------------------------------------- -- | -- Module      :  Data.Text.Lazy.Lens--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-2013 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  experimental@@ -18,10 +17,12 @@ module Data.Text.Lazy.Lens   ( packed   , text+  , builder   ) where  import Control.Lens import Data.Text.Lazy+import Data.Text.Lazy.Builder  -- | Pack (or unpack) lazy 'Text'. --@@ -29,13 +30,23 @@ -- 'pack' x = x '^.' 'packed' -- 'unpack' x = x '^.' 'from' 'packed' -- @-packed :: Simple Iso String Text+packed :: Iso' String Text packed = iso pack unpack {-# INLINE packed #-} +-- | Convert between lazy 'Text' and 'Builder' .+--+-- @+-- 'fromLazyText' x = x '^.' 'builder'+-- 'toLazyText' x = x '^.' 'from' 'builder'+-- @+builder :: Iso' Text Builder+builder = iso fromLazyText toLazyText+{-# INLINE builder #-}+ -- | Traverse the individual characters in a 'Text'. -- -- > anyOf text (=='c') :: Text -> Bool-text :: SimpleIndexedTraversal Int Text Char-text = from packed .> itraversed+text :: IndexedTraversal' Int Text Char+text = from packed . itraversed {-# INLINE text #-}
src/Data/Text/Lens.hs view
@@ -1,5 +1,4 @@ {-# LANGUAGE CPP #-}-{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleContexts #-} #ifdef TRUSTWORTHY {-# LANGUAGE Trustworthy #-}@@ -7,7 +6,7 @@ ----------------------------------------------------------------------------- -- | -- Module      :  Data.Text.Lens--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  experimental@@ -23,6 +22,7 @@ import qualified Data.Text.Strict.Lens as Strict import           Data.Text.Lazy as Lazy import qualified Data.Text.Lazy.Lens as Lazy+import           Data.Text.Lazy.Builder  -- | Traversals for strict or lazy 'Text' class IsText t where@@ -32,21 +32,33 @@   -- 'pack' x = x '^.' 'packed'   -- 'unpack' x = x '^.' 'from' 'packed'   -- @-  packed :: Simple Iso String t+  packed :: Iso' String t +  -- | Convert between strict or lazy 'Text' and a 'Builder'.+  --+  -- @+  -- 'fromText' x = x '^.' 'builder'+  -- @+  builder :: Iso' t Builder+   -- | Traverse the individual characters in strict or lazy 'Text'.-  text :: SimpleIndexedTraversal Int t Char-  text = from packed .> itraversed+  text :: IndexedTraversal' Int t Char+  text = from packed . itraversed   {-# INLINE text #-}  instance IsText Strict.Text where   packed = Strict.packed   {-# INLINE packed #-}+  builder = Strict.builder+  {-# INLINE builder #-}   text = Strict.text   {-# INLINE text #-}  instance IsText Lazy.Text where   packed = Lazy.packed   {-# INLINE packed #-}+  builder = Lazy.builder+  {-# INLINE builder #-}   text = Lazy.text   {-# INLINE text #-}+
src/Data/Text/Strict/Lens.hs view
@@ -1,5 +1,4 @@ {-# LANGUAGE CPP #-}-{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleContexts #-} #ifdef TRUSTWORTHY {-# LANGUAGE Trustworthy #-}@@ -7,7 +6,7 @@ ----------------------------------------------------------------------------- -- | -- Module      :  Data.Text.Strict.Lens--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-2013 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  experimental@@ -16,26 +15,40 @@ ---------------------------------------------------------------------------- module Data.Text.Strict.Lens   ( packed+  , builder   , text   ) where  import Control.Lens import Data.Text+import Data.Text.Lazy (toStrict)+import Data.Text.Lazy.Builder  -- | 'pack' (or 'unpack') strict 'Text'. -- -- @--- 'pack' x = x '^.' 'packed'--- 'unpack' x = x '^.' 'from' 'packed'+-- 'pack' x ≡ x '^.' 'packed'+-- 'unpack' x ≡ x '^.' 'from' 'packed' -- @-packed :: Simple Iso String Text+packed :: Iso' String Text packed = iso pack unpack {-# INLINE packed #-} ++-- | Convert between strict 'Text' and 'Builder' .+--+-- @+-- 'fromText' x ≡ x '^.' 'builder'+-- 'toStrict' ('toLazyText' x) ≡ x '^.' 'from' 'builder'+-- @+builder :: Iso' Text Builder+builder = iso fromText (toStrict . toLazyText)+{-# INLINE builder #-}+ -- | Traverse the individual characters in strict 'Text'. -- -- >>> anyOf text (=='o') $ "hello"^.packed -- True-text :: SimpleIndexedTraversal Int Text Char-text = from packed .> itraversed+text :: IndexedTraversal' Int Text Char+text = from packed . itraversed {-# INLINE text #-}
src/Data/Tree/Lens.hs view
@@ -2,7 +2,7 @@ ----------------------------------------------------------------------------- -- | -- Module      :  Data.Tree.Lens--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  provisional@@ -23,13 +23,13 @@ -- -- >>> view root $ Node 42 [] -- 42-root :: SimpleLens (Tree a) a+root :: Lens' (Tree a) a root f (Node a as) = (`Node` as) <$> f a {-# INLINE root #-}  -- | A 'Lens' returning the direct descendants of the root of a 'Tree' -- -- @'view' 'branches' ≡ 'subForest'@-branches :: SimpleLens (Tree a) [Tree a]+branches :: Lens' (Tree a) [Tree a] branches f (Node a as) = Node a <$> f as {-# INLINE branches #-}
src/Data/Typeable/Lens.hs view
@@ -6,7 +6,7 @@ ----------------------------------------------------------------------------- -- | -- Module      :  Data.Typeable.Lens--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  experimental@@ -23,15 +23,15 @@ import Data.Typeable import Data.Maybe --- | A 'Simple' 'Traversal' for working with a 'cast' of a 'Typeable' value.-_cast :: (Typeable s, Typeable a) => Simple Traversal s a+-- | A 'Traversal'' for working with a 'cast' of a 'Typeable' value.+_cast :: (Typeable s, Typeable a) => Traversal' s a _cast f s = case cast s of   Just a  -> fromMaybe (error "_cast: recast failed") . cast <$> f a   Nothing -> pure s {-# INLINE _cast #-} --- | A 'Simple' 'Traversal' for working with a 'gcast' of a 'Typeable' value.-_gcast :: (Typeable s, Typeable a) => Simple Traversal (c s) (c a)+-- | A 'Traversal'' for working with a 'gcast' of a 'Typeable' value.+_gcast :: (Typeable s, Typeable a) => Traversal' (c s) (c a) _gcast f s = case gcast s of   Just a  -> fromMaybe (error "_gcast: recast failed") . gcast <$> f a   Nothing -> pure s
src/Data/Vector/Generic/Lens.hs view
@@ -1,22 +1,20 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE Rank2Types #-}-{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE LiberalTypeSynonyms #-}-{-# LANGUAGE MultiParamTypeClasses #-} #ifdef TRUSTWORTHY {-# LANGUAGE Trustworthy #-} #endif ------------------------------------------------------------------------------- -- | -- Module      :  Data.Vector.Generic.Lens--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-2013 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  provisional -- Portability :  non-portable ----- This module provides lenses and traversals for working with generic vectors.+-- This module provides lenses and traversals for working with generic+-- vectors. ------------------------------------------------------------------------------- module Data.Vector.Generic.Lens   ( toVectorOf@@ -28,127 +26,101 @@   , cloned   , reversed   -- * Lenses-  , _head-  , _tail-  , _last-  , _init   , sliced   -- * Traversal of individual indices-  , ordinal   , ordinals   ) where +import Control.Applicative import Control.Lens import Data.List (nub) import Data.Monoid import Data.Vector.Generic as V hiding (zip, filter, indexed) import Data.Vector.Fusion.Stream (Stream) import Data.Vector.Generic.New (New)-import Prelude hiding ((++), length, head, tail, init, last, map, reverse)+import Prelude hiding ((++), length, null, head, tail, init, last, map, reverse)  -- $setup -- >>> import Data.Vector as Vector --- | A lens reading and writing to the 'head' of a /non-empty/ 'Vector'------ Attempting to read or write to the 'head' of an /empty/ 'Vector' will result in an 'error'.------ >>> Vector.fromList [1,2,3]^._head--- 1-_head :: Vector v a => SimpleLens (v a) a-_head f v = f (head v) <&> \a -> v // [(0,a)]-{-# INLINE _head #-}---- | A 'Lens' reading and writing to the 'last' element of a /non-empty/ 'Vector'------ Attempting to read or write to the 'last' element of an /empty/ 'Vector' will result in an 'error'.------ >>> Vector.fromList [1,2]^._last--- 2-_last :: Vector v a => SimpleLens (v a) a-_last f v = f (last v) <&> \a -> v // [(length v - 1, a)]-{-# INLINE _last #-}---- | A lens reading and writing to the 'tail' of a /non-empty/ 'Vector'------ Attempting to read or write to the 'tail' of an /empty/ 'Vector' will result in an 'error'.------ >>> _tail .~ Vector.fromList [3,4,5] $ Vector.fromList [1,2]--- fromList [1,3,4,5]-_tail :: Vector v a => SimpleLens (v a) (v a)-_tail f v = f (tail v) <&> cons (head v)-{-# INLINE _tail #-}---- | A 'Lens' reading and replacing all but the a 'last' element of a /non-empty/ 'Vector'+-- | @sliced i n@ provides a 'Lens' that edits the @n@ elements starting+-- at index @i@ from a 'Lens'. ----- Attempting to read or write to all but the 'last' element of an /empty/ 'Vector' will result in an 'error'.+-- This is only a valid 'Lens' if you do not change the length of the+-- resulting 'Vector'. ----- >>> Vector.fromList [1,2,3,4]^._init--- fromList [1,2,3]-_init :: Vector v a => SimpleLens (v a) (v a)-_init f v = f (init v) <&> \i -> snoc i (last v)-{-# INLINE _init #-}---- | @sliced i n@ provides a lens that edits the @n@ elements starting at index @i@ from a lens.+-- Attempting to return a longer or shorter vector will result in+-- violations of the 'Lens' laws. ----- This is only a valid lens if you do not change the length of the resulting 'Vector'.+-- >>> Vector.fromList [1..10] ^. sliced 2 5+-- fromList [3,4,5,6,7] ----- Attempting to return a longer or shorter vector will result in violations of the 'Lens' laws.-sliced :: Vector v a => Int -- ^ @i@ starting index-          -> Int -- ^ @n@ length-          -> SimpleLens (v a) (v a)+-- >>> Vector.fromList [1..10] & sliced 2 5 . mapped .~ 0+-- fromList [1,2,0,0,0,0,0,8,9,10]+sliced :: Vector v a+       => Int -- ^ @i@ starting index+       -> Int -- ^ @n@ length+       -> Lens' (v a) (v a) sliced i n f v = f (slice i n v) <&> \ v0 -> v // zip [i..i+n-1] (V.toList v0) {-# INLINE sliced #-}  -- | Similar to 'toListOf', but returning a 'Vector'.+--+-- >>> toVectorOf both (8,15) :: Vector.Vector Int+-- fromList [8,15] toVectorOf :: Vector v a => Getting (Endo [a]) s t a b -> s -> v a toVectorOf l s = fromList (toListOf l s) {-# INLINE toVectorOf #-} --- | Convert a list to a 'Vector' (or back)-vector :: Vector v a => Simple Iso [a] (v a)+-- | Convert a list to a 'Vector' (or back.)+--+-- >>> [1,2,3] ^. vector :: Vector.Vector Int+-- fromList [1,2,3]+--+-- >>> Vector.fromList [0,8,15] ^. from vector+-- [0,8,15]+vector :: Vector v a => Iso' [a] (v a) vector = iso fromList V.toList {-# INLINE vector #-} --- | Convert a 'Vector' to a finite 'Stream' (or back)-asStream :: Vector v a => Simple Iso (v a) (Stream a)+-- | Convert a 'Vector' to a finite 'Stream' (or back.)+asStream :: Vector v a => Iso' (v a) (Stream a) asStream = iso stream unstream {-# INLINE asStream #-} --- | Convert a 'Vector' to a finite 'Stream' from right to left (or back)-asStreamR :: Vector v a => Simple Iso (v a) (Stream a)+-- | Convert a 'Vector' to a finite 'Stream' from right to left (or+-- back.)+asStreamR :: Vector v a => Iso' (v a) (Stream a) asStreamR = iso streamR unstreamR {-# INLINE asStreamR #-} --- | Convert a 'Vector' back and forth to an initializer that when run produces a copy of the 'Vector'.-cloned :: Vector v a => Simple Iso (v a) (New v a)+-- | Convert a 'Vector' back and forth to an initializer that when run+-- produces a copy of the 'Vector'.+cloned :: Vector v a => Iso' (v a) (New v a) cloned = iso clone new {-# INLINE cloned #-} --- | Convert a 'Vector' to a version that doesn't retain any extra memory.-forced :: Vector v a => Simple Iso (v a) (v a)+-- | Convert a 'Vector' to a version that doesn't retain any extra+-- memory.+forced :: Vector v a => Iso' (v a) (v a) forced = iso force force {-# INLINE forced #-} --- | Convert a 'Vector' to a version with all the elements in the reverse order-reversed :: Vector v a => Simple Iso (v a) (v a)+-- | Convert a 'Vector' to a version with all the elements in the+-- reverse order.+--+-- >>> Vector.fromList [1,2,3] ^. reversed+-- fromList [3,2,1]+reversed :: Vector v a => Iso' (v a) (v a) reversed = iso reverse reverse {-# INLINE reversed #-} --- | This is a more efficient version of 'element' that works for any 'Vector'.------ @ordinal n@ is only a valid 'Lens' into a 'Vector' with 'length' at least @n + 1@.-ordinal :: Vector v a => Int -> SimpleIndexedLens Int (v a) a-ordinal i = indexed $ \ f v -> f i (v ! i) <&> \ a -> v // [(i, a)]-{-# INLINE ordinal #-}---- | This 'Traversal' will ignore any duplicates in the supplied list of indices.+-- | This 'Traversal' will ignore any duplicates in the supplied list+-- of indices. -- -- >>> toListOf (ordinals [1,3,2,5,9,10]) $ Vector.fromList [2,4..40] -- [4,8,6,12,20,22]-ordinals :: Vector v a => [Int] -> SimpleIndexedTraversal Int (v a) a-ordinals is = indexed $ \ f v -> let-     l = length v-     is' = nub $ filter (<l) is-  in fmap ((v //) . zip is') . traverse (uncurry f) . zip is $ fmap (v !) is'+ordinals :: Vector v a => [Int] -> IndexedTraversal' Int (v a) a+ordinals is f v = fmap (v //) $ traverse (\i -> (,) i <$> indexed f i (v ! i)) $ nub $ filter (\i -> 0 <= i && i < l) is where+  l = length v {-# INLINE ordinals #-}
src/Data/Vector/Lens.hs view
@@ -1,8 +1,6 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE Rank2Types #-}-{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE LiberalTypeSynonyms #-} {-# LANGUAGE MultiParamTypeClasses #-} #ifdef TRUSTWORTHY {-# LANGUAGE Trustworthy #-}@@ -10,13 +8,14 @@ ------------------------------------------------------------------------------- -- | -- Module      :  Data.Vector.Lens--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  provisional -- Portability :  non-portable ----- This module provides lenses and traversals for working with generic vectors.+-- This module provides lenses and traversals for working with generic+-- vectors. ------------------------------------------------------------------------------- module Data.Vector.Lens   ( toVectorOf@@ -25,107 +24,82 @@   , reversed   , forced   -- * Lenses-  , _head-  , _tail-  , _last-  , _init   , sliced   -- * Traversal of individual indices-  , ordinal   , ordinals   ) where +import Control.Applicative import Control.Lens import Data.Vector as Vector hiding (zip, filter, indexed)-import Prelude hiding ((++), length, head, tail, init, last, map, reverse)+import Prelude hiding ((++), length, null, head, tail, init, last, map, reverse) import Data.List (nub) import Data.Monoid --- | A lens reading and writing to the 'head' of a /non-empty/ 'Vector'------ Attempting to read or write to the 'head' of an /empty/ 'Vector' will result in an 'error'.------ >>> Vector.fromList [1,2,3]^._head--- 1-_head :: SimpleLens (Vector a) a-_head f v = f (head v) <&> \a -> v // [(0,a)]-{-# INLINE _head #-}---- | A 'Lens' reading and writing to the 'last' element of a /non-empty/ 'Vector'------ Attempting to read or write to the 'last' element of an /empty/ 'Vector' will result in an 'error'.------ >>> Vector.fromList [1,2]^._last--- 2-_last :: SimpleLens (Vector a) a-_last f v = f (last v) <&> \a -> v // [(length v - 1, a)]-{-# INLINE _last #-}---- | A lens reading and writing to the 'tail' of a /non-empty/ 'Vector'------ Attempting to read or write to the 'tail' of an /empty/ 'Vector' will result in an 'error'.------ >>> _tail .~ Vector.fromList [3,4,5] $ Vector.fromList [1,2]--- fromList [1,3,4,5]-_tail :: SimpleLens (Vector a) (Vector a)-_tail f v = f (tail v) <&> cons (head v)-{-# INLINE _tail #-}---- | A 'Lens' reading and replacing all but the a 'last' element of a /non-empty/ 'Vector'+-- | @sliced i n@ provides a 'Lens' that edits the @n@ elements starting+-- at index @i@ from a 'Lens'. ----- Attempting to read or write to all but the 'last' element of an /empty/ 'Vector' will result in an 'error'.+-- This is only a valid 'Lens' if you do not change the length of the+-- resulting 'Vector'. ----- >>> Vector.fromList [1,2,3,4]^._init--- fromList [1,2,3]-_init :: SimpleLens (Vector a) (Vector a)-_init f v = f (init v) <&> (`snoc` last v)-{-# INLINE _init #-}---- | @sliced i n@ provides a lens that edits the @n@ elements starting at index @i@ from a lens.+-- Attempting to return a longer or shorter vector will result in+-- violations of the 'Lens' laws. ----- This is only a valid lens if you do not change the length of the resulting 'Vector'.+-- >>> Vector.fromList [1..10] ^. sliced 2 5+-- fromList [3,4,5,6,7] ----- Attempting to return a longer or shorter vector will result in violations of the 'Lens' laws.+-- >>> Vector.fromList [1..10] & sliced 2 5 . mapped .~ 0+-- fromList [1,2,0,0,0,0,0,8,9,10] sliced :: Int -- ^ @i@ starting index        -> Int -- ^ @n@ length-       -> SimpleLens (Vector a) (Vector a)+       -> Lens' (Vector a) (Vector a) sliced i n f v = f (slice i n v) <&> \ v0 -> v // zip [i..i+n-1] (toList v0) {-# INLINE sliced #-}  -- | Similar to 'toListOf', but returning a 'Vector'.+--+-- >>> toVectorOf both (8,15)+-- fromList [8,15] toVectorOf :: Getting (Endo [a]) s t a b -> s -> Vector a toVectorOf l s = fromList (toListOf l s) {-# INLINE toVectorOf #-}  -- | Convert a list to a 'Vector' (or back)+--+-- >>> [1,2,3] ^. vector+-- fromList [1,2,3]+--+-- >>> [1,2,3] ^. vector . from vector+-- [1,2,3]+--+-- >>> Vector.fromList [0,8,15] ^. from vector . vector+-- fromList [0,8,15] vector :: Iso [a] [b] (Vector a) (Vector b) vector = iso fromList toList {-# INLINE vector #-} --- | Convert a 'Vector' to a version with all the elements in the reverse order+-- | Convert a 'Vector' to a version with all the elements in the+-- reverse order.+--+-- >>> Vector.fromList [1,2,3] ^. reversed+-- fromList [3,2,1] reversed :: Iso (Vector a) (Vector b) (Vector a) (Vector b) reversed = iso reverse reverse {-# INLINE reversed #-} --- | Convert a 'Vector' to a version that doesn't retain any extra memory.+-- | Convert a 'Vector' to a version that doesn't retain any extra+-- memory. forced :: Iso (Vector a) (Vector b) (Vector a) (Vector b) forced = iso force force {-# INLINE forced #-} --- | This is a more efficient version of 'element' that works for any 'Vector'.------ @ordinal n@ is only a valid 'Lens' into a 'Vector' with 'length' at least @n + 1@.-ordinal :: Int -> SimpleIndexedLens Int (Vector a) a-ordinal i = indexed $ \ f v -> f i (v ! i) <&> \ a -> v // [(i, a)]-{-# INLINE ordinal #-}---- | This 'Traversal' will ignore any duplicates in the supplied list of indices.+-- | This 'Traversal' will ignore any duplicates in the supplied list+-- of indices. -- -- >>> toListOf (ordinals [1,3,2,5,9,10]) $ Vector.fromList [2,4..40] -- [4,8,6,12,20,22]-ordinals :: [Int] -> SimpleIndexedTraversal Int (Vector a) a-ordinals is = indexed $ \ f v -> let-     l = length v-     is' = nub $ filter (<l) is-  in fmap ((v //) . zip is') . traverse (uncurry f) . zip is $ fmap (v !) is'+ordinals :: [Int] -> IndexedTraversal' Int (Vector a) a+ordinals is f v = fmap (v //) $ traverse (\i -> (,) i <$> indexed f i (v ! i)) $ nub $ filter (\i -> 0 <= i && i < l) is where+  l = length v {-# INLINE ordinals #-}+
src/GHC/Generics/Lens.hs view
@@ -1,13 +1,11 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE Rank2Types #-}-{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE LiberalTypeSynonyms #-} ----------------------------------------------------------------------------- -- | -- Module      :  GHC.Generics.Lens--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  experimental@@ -41,7 +39,7 @@   ) where  import           Control.Applicative-import           Control.Lens hiding (Rep)+import           Control.Lens import           Data.Maybe (fromJust) import           Data.Typeable #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702@@ -57,12 +55,14 @@ -- >>> "hello"^.generic.from generic :: String -- "hello" ---generic :: Generic a => Simple Iso a (Rep a b)+generic :: Generic a => Iso' a (Rep a b) generic = iso Generic.from Generic.to+{-# INLINE generic #-}  -- | Convert from the data type to its representation (or back)-generic1 :: Generic1 f => Simple Iso (f a) (Rep1 f a)+generic1 :: Generic1 f => Iso' (f a) (Rep1 f a) generic1 = iso from1 to1+{-# INLINE generic1 #-}  -- | A 'GHC.Generics.Generic' 'Traversal' that visits every occurrence -- of something 'Typeable' anywhere in a container.@@ -73,35 +73,43 @@ -- >>> mapMOf_ tinplate putStrLn ("hello",[(2 :: Int, "world!")]) -- hello -- world!-tinplate :: (Generic a, GTraversal (Rep a), Typeable b) => Simple Traversal a b+tinplate :: (Generic a, GTraversal (Rep a), Typeable b) => Traversal' a b tinplate = generic . tinplated True+{-# INLINE tinplate #-}  maybeArg1Of :: Maybe c -> (c -> d) -> Maybe c maybeArg1Of = const+{-# INLINE maybeArg1Of #-}  -- | Used to traverse 'Generic' data by 'uniplate'. class GTraversal f where-  tinplated :: Typeable b => Bool -> Simple Traversal (f a) b+  tinplated :: Typeable b => Bool -> Traversal' (f a) b  instance (Generic a, GTraversal (Rep a), Typeable a) => GTraversal (K1 i a) where   tinplated rec f (K1 a) = case cast a `maybeArg1Of` f of     Just b  -> K1 . fromJust . cast <$> f b     Nothing | rec       -> K1 <$> fmap generic (tinplated False) f a             | otherwise -> pure $ K1 a+  {-# INLINE tinplated #-}  instance GTraversal U1 where   tinplated _ _ U1 = pure U1+  {-# INLINE tinplated #-}  instance (GTraversal f, GTraversal g) => GTraversal (f :*: g) where   tinplated _ f (x :*: y) = (:*:) <$> tinplated True f x <*> tinplated True f y+  {-# INLINE tinplated #-}  instance (GTraversal f, GTraversal g) => GTraversal (f :+: g) where   tinplated _ f (L1 x) = L1 <$> tinplated True f x   tinplated _ f (R1 x) = R1 <$> tinplated True f x+  {-# INLINE tinplated #-}  instance GTraversal a => GTraversal (M1 i c a) where   tinplated rec f (M1 x) = M1 <$> tinplated rec f x+  {-# INLINE tinplated #-}  -- ? instance (Traversable f, GTraversal g) => GTraversal (f :.: g) where   tinplated _ f (Comp1 fgp) = Comp1 <$> traverse (tinplated True f) fgp+  {-# INLINE tinplated #-}
src/Language/Haskell/TH/Lens.hs view
@@ -6,7 +6,7 @@ ----------------------------------------------------------------------------- -- | -- Module      :  Language.Haskell.TH.Lens--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-2013 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  experimental@@ -18,20 +18,19 @@   ( HasName(..)   , HasTypeVars(..)   , SubstType(..)-  , typeVars      -- :: HasTypeVars t => Simple Traversal t Name+  , typeVars      -- :: HasTypeVars t => Traversal' t Name   , substTypeVars -- :: HasTypeVars t => Map Name Name -> t -> t   , conFields   , conNamedFields   ) where  import Control.Applicative+import Control.Lens.At import Control.Lens.Getter import Control.Lens.Setter import Control.Lens.Fold-import Control.Lens.IndexedLens-import Control.Lens.IndexedTraversal+import Control.Lens.Lens import Control.Lens.Tuple-import Control.Lens.Type import Control.Lens.Traversal import Data.Map as Map hiding (toList,map) import Data.Maybe (fromMaybe)@@ -44,7 +43,7 @@ -- | Has a 'Name' class HasName t where   -- | Extract (or modify) the 'Name' of something-  name :: Simple Lens t Name+  name :: Lens' t Name  instance HasName TyVarBndr where   name f (PlainTV n) = PlainTV <$> f n@@ -64,7 +63,7 @@   -- | When performing substitution into this traversal you're not allowed   -- to substitute in a name that is bound internally or you'll violate   -- the 'Traversal' laws, when in doubt generate your names with 'newName'.-  typeVarsEx :: Set Name -> Simple Traversal t Name+  typeVarsEx :: Set Name -> Traversal' t Name  instance HasTypeVars TyVarBndr where   typeVarsEx s f b@@ -100,7 +99,7 @@   typeVarsEx s = traverse . typeVarsEx s  -- | Traverse /free/ type variables-typeVars :: HasTypeVars t => Simple Traversal t Name+typeVars :: HasTypeVars t => Traversal' t Name typeVars = typeVarsEx mempty  -- | Substitute using a map of names in for /free/ type variables@@ -128,7 +127,7 @@   substType m (EqualP l r)  = substType m (EqualP l r)  -- | Provides a 'Traversal' of the types of each field of a constructor.-conFields :: Simple Traversal Con StrictType+conFields :: Traversal' Con StrictType conFields f (NormalC n fs)      = NormalC n <$> traverse f fs conFields f (RecC n fs)         = RecC n <$> traverse sans_var fs   where sans_var (fn,s,t) = (\(s', t') -> (fn,s',t')) <$> f (s, t)@@ -136,6 +135,6 @@ conFields f (ForallC bds ctx c) = ForallC bds ctx <$> conFields f c  -- | 'Traversal' of the types of the /named/ fields of a constructor.-conNamedFields :: Simple Traversal Con VarStrictType+conNamedFields :: Traversal' Con VarStrictType conNamedFields f (RecC n fs) = RecC n <$> traverse f fs conNamedFields _ c = pure c
+ src/Numeric/Lens.hs view
@@ -0,0 +1,86 @@+{-# LANGUAGE Rank2Types #-}+--------------------------------------------------------------------------------+-- |+-- Module      :  Numeric.Lens+-- Copyright   :  (C) 2012-13 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  provisional+-- Portability :  portable+-------------------------------------------------------------------------------+module Numeric.Lens (base, integral) where++import Control.Lens+import Data.Char (chr, ord, isAsciiLower, isAsciiUpper, isDigit)+import Data.Maybe (fromMaybe)+import Numeric (readInt, showIntAtBase)++-- | This 'Prism' extracts can be used to model the fact that every 'Integral'+-- type is a subset of 'Integer'.+--+-- Embedding through the 'Prism' only succeeds if the 'Integer' would pass+-- through unmodified when re-extracted.+integral :: (Integral a, Integral b) => Prism Integer Integer a b+integral = prism toInteger $ \ i -> let a = fromInteger i in+  if toInteger a == i+  then Right a+  else Left i++-- | A prism that shows and reads integers in base-2 through base-36+--+-- >>> "100" ^? base 16+-- Just 256+--+-- >>> 1767707668033969 ^. re (base 36)+-- "helloworld"+base :: (Integral a, Show a) => a -> Prism' String a+base b+  | b < 2 || b > 36 = error ("base: Invalid base " ++ show b)+  | otherwise       = prism intShow intRead+  where+    intShow n = showSigned' (showIntAtBase b intToDigit') n ""++    intRead s =+      case readSigned' (readInt b (isDigit' b) digitToInt') s of+        [(n,"")] -> Right n+        _ -> Left s+{-# INLINE base #-}++-- | Like 'Data.Char.intToDigit', but handles up to base-36+intToDigit' :: Int -> Char+intToDigit' i+  | i >= 0  && i < 10 = chr (ord '0' + i)+  | i >= 10 && i < 36 = chr (ord 'a' + i - 10)+  | otherwise = error ("intToDigit': Invalid int " ++ show i)++-- | Like 'Data.Char.digitToInt', but handles up to base-36+digitToInt' :: Char -> Int+digitToInt' c = fromMaybe (error ("digitToInt': Invalid digit " ++ show c))+                          (digitToIntMay c)++-- | A safe variant of 'digitToInt''+digitToIntMay :: Char -> Maybe Int+digitToIntMay c+  | isDigit c      = Just (ord c - ord '0')+  | isAsciiLower c = Just (ord c - ord 'a' + 10)+  | isAsciiUpper c = Just (ord c - ord 'A' + 10)+  | otherwise = Nothing++-- | Select digits that fall into the given base+isDigit' :: Integral a => a -> Char -> Bool+isDigit' b c = case digitToIntMay c of+  Just i | fromIntegral i < b -> True+  _ -> False++-- | A simpler variant of 'Numeric.showSigned' that only prepends a dash and+-- doesn't know about parentheses+showSigned' :: Real a => (a -> ShowS) -> a -> ShowS+showSigned' f n+  | n < 0     = showChar '-' . f (negate n)+  | otherwise = f n++-- | A simpler variant of 'Numeric.readSigned' that supports any base, only+-- recognizes an initial dash and doesn't know about parentheses+readSigned' :: Real a => ReadS a -> ReadS a+readSigned' f ('-':xs) = f xs & mapped . _1 %~ negate+readSigned' f xs       = f xs
+ src/System/Exit/Lens.hs view
@@ -0,0 +1,65 @@+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FlexibleInstances #-}+-----------------------------------------------------------------------------+-- |+-- Module      :  System.Exit.Lens+-- Copyright   :  (C) 2013 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  provisional+-- Portability :  Control.Exception+--+-- These prisms can be used with the combinators in "Control.Exception.Lens".+----------------------------------------------------------------------------+module System.Exit.Lens+  ( AsExitCode(..)+  , _ExitFailure+  , _ExitSuccess+  ) where++import Control.Applicative+import Control.Exception+import Control.Exception.Lens+import Control.Lens+import System.Exit++-- | Exit codes that a program can return with:+class AsExitCode p f t where+  -- |+  -- @+  -- '_ExitCode' :: 'Equality'' 'ExitCode'      'ExitCode'+  -- '_ExitCode' :: 'Prism''    'SomeException' 'ExitCode'+  -- @+  _ExitCode :: Overloaded' p f t ExitCode++instance AsExitCode p f ExitCode where+  _ExitCode = id+  {-# INLINE _ExitCode #-}++instance (Choice p, Applicative f) => AsExitCode p f SomeException where+  _ExitCode = exception+  {-# INLINE _ExitCode #-}++-- | indicates successful termination;+--+-- @+-- '_ExitSuccess' :: 'Prism'' 'ExitCode'      ()+-- '_ExitSuccess' :: 'Prism'' 'SomeException' ()+-- @+_ExitSuccess :: (AsExitCode p f t, Choice p, Applicative f) => Overloaded' p f t ()+_ExitSuccess = _ExitCode . dimap seta (either id id) . right' . rmap (ExitSuccess <$) where+  seta ExitSuccess = Right ()+  seta t           = Left  (pure t)+{-# INLINE _ExitSuccess #-}++-- | indicates program failure with an exit code. The exact interpretation of the code is operating-system dependent. In particular, some values may be prohibited (e.g. 0 on a POSIX-compliant system).+--+-- @+-- '_ExitFailure' :: 'Prism'' 'ExitCode'      'Int'+-- '_ExitFailure' :: 'Prism'' 'SomeException' 'Int'+-- @+_ExitFailure :: (AsExitCode p f t, Choice p, Applicative f) => Overloaded' p f t Int+_ExitFailure = _ExitCode . dimap seta (either id id) . right' . rmap (fmap ExitFailure) where+  seta (ExitFailure i) = Right i+  seta t               = Left  (pure t)+{-# INLINE _ExitFailure #-}
src/System/FilePath/Lens.hs view
@@ -1,7 +1,7 @@ ----------------------------------------------------------------------------- -- | -- Module      :  System.FilePath.Lens--- Copyright   :  (C) 2012 Edward Kmett+-- Copyright   :  (C) 2012-13 Edward Kmett -- License     :  BSD-style (see the file LICENSE) -- Maintainer  :  Edward Kmett <ekmett@gmail.com> -- Stability   :  experimental@@ -42,7 +42,7 @@ -- ('</>~') :: 'Lens' s a 'FilePath' 'FilePath' -> 'FilePath' -> s -> a -- ('</>~') :: 'Traversal' s a 'FilePath' 'FilePath' -> 'FilePath' -> s -> a -- @-(</>~) :: Setting s t FilePath FilePath -> FilePath -> s -> t+(</>~) :: ASetter s t FilePath FilePath -> FilePath -> s -> t l </>~ n = over l (</> n) {-# INLINE (</>~) #-} @@ -53,12 +53,12 @@ -- ("hello/bin","world/bin") -- -- @--- ('</>=') :: 'MonadState' s m => 'Simple' 'Setter' s 'FilePath' -> 'FilePath' -> m ()--- ('</>=') :: 'MonadState' s m => 'Simple' 'Iso' s 'FilePath' -> 'FilePath' -> m ()--- ('</>=') :: 'MonadState' s m => 'Simple' 'Lens' s 'FilePath' -> 'FilePath' -> m ()--- ('</>=') :: 'MonadState' s m => 'Simple' 'Traversal' s 'FilePath' -> 'FilePath' -> m ()+-- ('</>=') :: 'MonadState' s m => 'Setter'' s 'FilePath' -> 'FilePath' -> m ()+-- ('</>=') :: 'MonadState' s m => 'Iso'' s 'FilePath' -> 'FilePath' -> m ()+-- ('</>=') :: 'MonadState' s m => 'Lens'' s 'FilePath' -> 'FilePath' -> m ()+-- ('</>=') :: 'MonadState' s m => 'Traversal'' s 'FilePath' -> 'FilePath' -> m () -- @-(</>=) :: MonadState s m => SimpleSetting s FilePath -> FilePath -> m ()+(</>=) :: MonadState s m => ASetter' s FilePath -> FilePath -> m () l </>= b = State.modify (l </>~ b) {-# INLINE (</>=) #-} @@ -75,7 +75,7 @@ -- your monad's state and return the result. -- -- When you do not need the result of the operation, ('</>=') is more flexible.-(<</>=) :: MonadState s m => SimpleLensLike ((,)FilePath) s FilePath -> FilePath -> m FilePath+(<</>=) :: MonadState s m => LensLike' ((,)FilePath) s FilePath -> FilePath -> m FilePath l <</>= r = l <%= (</> r) {-# INLINE (<</>=) #-} @@ -91,7 +91,7 @@ -- ('<.>~') :: 'Lens' s a 'FilePath' 'FilePath' -> 'String' -> s -> a -- ('<.>~') :: 'Traversal' s a 'FilePath' 'FilePath' -> 'String' -> s -> a -- @-(<.>~) :: Setting s a FilePath FilePath -> String -> s -> a+(<.>~) :: ASetter s a FilePath FilePath -> String -> s -> a l <.>~ n = over l (<.> n) {-# INLINE (<.>~) #-} @@ -101,12 +101,12 @@ -- ("hello.txt","world.txt") -- -- @--- ('<.>=') :: 'MonadState' s m => 'Simple' 'Setter' s 'FilePath' -> 'String' -> m ()--- ('<.>=') :: 'MonadState' s m => 'Simple' 'Iso' s 'FilePath' -> 'String' -> m ()--- ('<.>=') :: 'MonadState' s m => 'Simple' 'Lens' s 'FilePath' -> 'String' -> m ()--- ('<.>=') :: 'MonadState' s m => 'Simple' 'Traversal' s 'FilePath' -> 'String' -> m ()+-- ('<.>=') :: 'MonadState' s m => 'Setter'' s 'FilePath' -> 'String' -> m ()+-- ('<.>=') :: 'MonadState' s m => 'Iso'' s 'FilePath' -> 'String' -> m ()+-- ('<.>=') :: 'MonadState' s m => 'Lens'' s 'FilePath' -> 'String' -> m ()+-- ('<.>=') :: 'MonadState' s m => 'Traversal'' s 'FilePath' -> 'String' -> m () -- @-(<.>=) :: MonadState s m => SimpleSetting s FilePath -> String -> m ()+(<.>=) :: MonadState s m => ASetter' s FilePath -> String -> m () l <.>= b = State.modify (l <.>~ b) {-# INLINE (<.>=) #-} @@ -128,7 +128,7 @@ -- "hello.txt" -- -- When you do not need the result of the operation, ('<.>=') is more flexible.-(<<.>=) :: MonadState s m => SimpleLensLike ((,)FilePath) s FilePath -> String -> m FilePath+(<<.>=) :: MonadState s m => LensLike' ((,)FilePath) s FilePath -> String -> m FilePath l <<.>= r = l <%= (<.> r) {-# INLINE (<<.>=) #-} @@ -137,7 +137,7 @@ -- -- >>> basename .~ "filename" $ "path/name.png" -- "path/filename.png"-basename :: Simple Lens FilePath FilePath+basename :: Lens' FilePath FilePath basename f p = (<.> takeExtension p) . (takeDirectory p </>) <$> f (takeBaseName p) {-# INLINE basename #-} @@ -146,7 +146,7 @@ -- -- >>> "long/path/name.txt" ^. directory -- "long/path"-directory :: Simple Lens FilePath FilePath+directory :: Lens' FilePath FilePath directory f p = (</> takeFileName p) <$> f (takeDirectory p) {-# INLINE directory #-} @@ -155,7 +155,7 @@ -- -- >>> extension .~ ".png" $ "path/name.txt" -- "path/name.png"-extension :: Simple Lens FilePath FilePath+extension :: Lens' FilePath FilePath extension f p = (n <.>) <$> f e  where   (n, e) = splitExtension p@@ -166,6 +166,6 @@ -- -- >>> filename .~ "name.txt" $ "path/name.png" -- "path/name.txt"-filename :: Simple Lens FilePath FilePath+filename :: Lens' FilePath FilePath filename f p = (takeDirectory p </>) <$> f (takeFileName p) {-# INLINE filename #-}
+ src/System/IO/Error/Lens.hs view
@@ -0,0 +1,93 @@+{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+-----------------------------------------------------------------------------+-- |+-- Module      :  System.IO.Error.Lens+-- Copyright   :  (C) 2012-2013 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  experimental+-- Portability :  Rank2Types+--+----------------------------------------------------------------------------+module System.IO.Error.Lens where++import Control.Lens+import Control.Exception.Lens+import GHC.IO.Exception+import System.IO+import Foreign.C.Types++-- * IOException Lenses++-- | Where the error happened.+--+-- @+-- 'location' :: 'Lens''      'IOException'   'String'+-- 'location' :: 'Traversal'' 'SomeException' 'String'+-- @+location :: (AsIOException (->) f t, Functor f) => LensLike' f t String+location f = _IOException $ \s -> f (ioe_location s) <&> \e -> s { ioe_location = e }+{-# INLINE location #-}++-- | Error type specific information.+--+-- @+-- 'description' :: 'Lens''      'IOException'   'String'+-- 'description' :: 'Traversal'' 'SomeException' 'String'+-- @+description :: (AsIOException (->) f t, Functor f) => LensLike' f t String+description f = _IOException $ \s -> f (ioe_description s) <&> \e -> s { ioe_description = e }+{-# INLINE description #-}++-- | The handle used by the action flagging this error.+--+-- @+-- 'handle' :: 'Lens''      'IOException'   ('Maybe' 'Handle')+-- 'handle' :: 'Traversal'' 'SomeException' ('Maybe' 'Handle')+-- @+handle :: (AsIOException (->) f t, Functor f) => LensLike' f t (Maybe Handle)+handle f = _IOException $ \s -> f (ioe_handle s) <&> \e -> s { ioe_handle = e }+{-# INLINE handle #-}++-- | 'fileName' the error is related to.+--+-- @+-- 'fileName' :: 'Lens''      'IOException'   ('Maybe' 'FilePath')+-- 'fileName' :: 'Traversal'' 'SomeException' ('Maybe' 'FilePath')+-- @+fileName :: (AsIOException (->) f t, Functor f) => LensLike' f t (Maybe FilePath)+fileName f = _IOException $ \s -> f (ioe_filename s) <&> \e -> s { ioe_filename = e }+{-# INLINE fileName #-}++-- | 'errno' leading to this error, if any.+--+-- @+-- 'errno' :: 'Lens''      'IOException'   ('Maybe' 'FilePath')+-- 'errno' :: 'Traversal'' 'SomeException' ('Maybe' 'FilePath')+-- @+errno :: (AsIOException (->) f t, Functor f) => LensLike' f t (Maybe CInt)+errno f = _IOException $ \s -> f (ioe_errno s) <&> \e -> s { ioe_errno = e }+{-# INLINE errno #-}++------------------------------------------------------------------------------+-- Error Types+------------------------------------------------------------------------------++-- | What type of error it is+--+-- @+-- 'errorType' :: 'Lens''      'IOException'   'IOErrorType'+-- 'errorType' :: 'Traversal'' 'SomeException' 'IOErrorType'+-- @+errorType :: (AsIOException (->) f t, Functor f) => LensLike' f t IOErrorType+errorType f = _IOException $ \s -> f (ioe_type s) <&> \e -> s { ioe_type = e }+{-# INLINE errorType #-}++-- * IOErrorType Prisms+--+-- (These prisms are generated automatically)++makePrisms ''IOErrorType
− tests/doctests.hs
@@ -1,30 +0,0 @@-module Main where--import Build_doctests (deps)-import Control.Applicative-import Control.Monad-import Data.List-import System.Directory-import System.FilePath-import Test.DocTest--main :: IO ()-main = getSources >>= \sources -> doctest $-    "-isrc"-  : "-idist/build/autogen"-  : "-optP-include"-  : "-optPdist/build/autogen/cabal_macros.h"-  : "-hide-all-packages"-  : map ("-package="++) deps ++ sources--getSources :: IO [FilePath]-getSources = filter (isSuffixOf ".hs") <$> go "src"-  where-    go dir = do-      (dirs, files) <- getFilesAndDirectories dir-      (files ++) . concat <$> mapM go dirs--getFilesAndDirectories :: FilePath -> IO ([FilePath], [FilePath])-getFilesAndDirectories dir = do-  c <- map (dir </>) . filter (`notElem` ["..", "."]) <$> getDirectoryContents dir-  (,) <$> filterM doesDirectoryExist c <*> filterM doesFileExist c
+ tests/doctests.hsc view
@@ -0,0 +1,71 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE ForeignFunctionInterface #-}+-----------------------------------------------------------------------------+-- |+-- Module      :  Main (doctests)+-- Copyright   :  (C) 2012-13 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  provisional+-- Portability :  portable+--+-- This module provides doctests for a project based on the actual versions+-- of the packages it was built with. It requires a corresponding Setup.lhs+-- to be added to the project+-----------------------------------------------------------------------------+module Main where++import Build_doctests (deps)+import Control.Applicative+import Control.Monad+import Data.List+import System.Directory+import System.FilePath+import Test.DocTest++##if defined(i386_HOST_ARCH)+##define USE_CP+import Control.Applicative+import Control.Exception+import Foreign.C.Types+foreign import stdcall "windows.h SetConsoleCP" c_SetConsoleCP :: CUInt -> IO Bool+foreign import stdcall "windows.h GetConsoleCP" c_GetConsoleCP :: IO CUInt+##elif defined(x64_64_HOST_ARCH)+##define USE_CP+import Control.Applicative+import Control.Exception+import Foreign.C.Types+foreign import ccall "windows.h SetConsoleCP" c_SetConsoleCP :: CUInt -> IO Bool+foreign import ccall "windows.h GetConsoleCP" c_GetConsoleCP :: IO CUInt+##endif++-- | Run in a modified codepage where we can print UTF-8 values on Windows.+withUnicode :: IO a -> IO a+##ifdef USE_CP+withUnicode m = do+  cp <- c_GetConsoleCP+  (c_SetConsoleCP 65001 >> m) `finally` c_SetConsoleCP cp+##else+withUnicode m = m+##endif++main :: IO ()+main = withUnicode $ getSources >>= \sources -> doctest $+    "-isrc"+  : "-idist/build/autogen"+  : "-optP-include"+  : "-optPdist/build/autogen/cabal_macros.h"+  : "-hide-all-packages"+  : map ("-package="++) deps ++ sources++getSources :: IO [FilePath]+getSources = filter (isSuffixOf ".hs") <$> go "src"+  where+    go dir = do+      (dirs, files) <- getFilesAndDirectories dir+      (files ++) . concat <$> mapM go dirs++getFilesAndDirectories :: FilePath -> IO ([FilePath], [FilePath])+getFilesAndDirectories dir = do+  c <- map (dir </>) . filter (`notElem` ["..", "."]) <$> getDirectoryContents dir+  (,) <$> filterM doesDirectoryExist c <*> filterM doesFileExist c
tests/hunit.hs view
@@ -1,5 +1,21 @@-{-# LANGUAGE TypeFamilies #-}+{-# OPTIONS_GHC -fno-warn-missing-signatures #-} {-# LANGUAGE TemplateHaskell #-}+-----------------------------------------------------------------------------+-- |+-- Module      :  Main (hunit)+-- Copyright   :  (C) 2012-13 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  provisional+-- Portability :  portable+--+-- This module provides a simple hunit test suite for lens.+--+-- The code attempts to enumerate common use cases rather than give an example+-- of each available lens function. The tests here merely scratch the surface+-- of what is possible using the lens package; there are a great many use cases+-- (and lens functions) that aren't covered.+----------------------------------------------------------------------------- module Main where  import Control.Lens@@ -11,12 +27,8 @@ import Test.Framework.Providers.HUnit import Test.Framework.TH import Test.Framework-import Test.HUnit+import Test.HUnit hiding (test) --- The code attempts to enumerate common use cases rather than give an example--- of each available lens function. The tests here merely scratch the surface--- of what is possible using the lens package; there are a great many use cases--- (and lens functions) that aren't covered.  data Point =   Point@@ -227,13 +239,13 @@   runState test trig @?= (Just "Origin", trig)   where test = use $ labels.at origin -case_read_map_entry = trig^.labels._at origin @?= "Origin"+case_read_map_entry = trig^.labels.ix origin @?= "Origin"  case_read_state_map_entry = runState test trig @?= ("Origin", trig)-  where test = use $ labels._at origin+  where test = use $ labels.ix origin  case_modify_map_entry =-  (trig & labels._at origin %~ List.map toUpper)+  (trig & labels.ix origin %~ List.map toUpper)     @?= trig { _labels = fromList [ (Point { _x = 0, _y = 0 }, "ORIGIN")                                   , (Point { _x = 4, _y = 7 }, "Peak") ] } 
tests/properties.hs view
@@ -1,41 +1,55 @@+{-# OPTIONS_GHC -fno-warn-missing-signatures #-} {-# LANGUAGE Rank2Types #-}-{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE ExtendedDefaultRules #-} {-# LANGUAGE LiberalTypeSynonyms #-} {-# LANGUAGE ScopedTypeVariables #-}+-----------------------------------------------------------------------------+-- |+-- Module      :  Main (properties)+-- Copyright   :  (C) 2012-13 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  experimental+-- Portability :  non-portable+--+-- This module provides a set of QuickCheck properties that can be run through+-- test-framework to validate a number of expected behaviors of the library.+----------------------------------------------------------------------------- module Main where + import Control.Applicative-import Control.Monad import Control.Lens-import Data.Functor.Identity-import System.Exit import Test.QuickCheck import Test.QuickCheck.Function import Test.Framework.TH import Test.Framework.Providers.QuickCheck2+import Data.Char (isAlphaNum, isAscii, toUpper) import Data.Text.Strict.Lens+import Data.Maybe import Data.List.Lens import Data.Functor.Compose+import Numeric (showHex, showOct, showSigned)+import Numeric.Lens   -- The first setter law:-setter_id :: Eq s => Simple Setter s a -> s -> Bool+setter_id :: Eq s => Setter' s a -> s -> Bool setter_id l s = over l id s == s  --  The second setter law:-setter_composition :: Eq s => Simple Setter s a -> s -> Fun a a -> Fun a a -> Bool+setter_composition :: Eq s => Setter' s a -> s -> Fun a a -> Fun a a -> Bool setter_composition l s (Fun _ f) (Fun _ g) = over l f (over l g s) == over l (f . g) s -lens_set_view :: Eq s => Simple Lens s a -> s -> Bool+lens_set_view :: Eq s => Lens' s a -> s -> Bool lens_set_view l s = set l (view l s) s == s -lens_view_set :: Eq a => Simple Lens s a -> s -> a -> Bool+lens_view_set :: Eq a => Lens' s a -> s -> a -> Bool lens_view_set l s a = view l (set l a s) == a -setter_set_set :: Eq s => Simple Setter s a -> s -> a -> a -> Bool+setter_set_set :: Eq s => Setter' s a -> s -> a -> a -> Bool setter_set_set l s a b = set l b (set l a s) == set l b s  iso_hither :: Eq s => Simple AnIso s a -> s -> Bool@@ -44,31 +58,31 @@ iso_yon :: Eq a => Simple AnIso s a -> a -> Bool iso_yon l a = a^.from l.cloneIso l == a -prism_yin :: Eq a => Simple Prism s a -> a -> Bool+prism_yin :: Eq a => Prism' s a -> a -> Bool prism_yin l a = preview l (review l a) == Just a -prism_yang :: Eq s => Simple Prism s a -> s -> Bool+prism_yang :: Eq s => Prism' s a -> s -> Bool prism_yang l s = maybe s (review l) (preview l s) == s -traverse_pure :: forall f s a. (Applicative f, Eq (f s)) => SimpleLensLike f s a -> s -> Bool+traverse_pure :: forall f s a. (Applicative f, Eq (f s)) => LensLike' f s a -> s -> Bool traverse_pure l s = l pure s == (pure s :: f s) -traverse_pureMaybe :: Eq s => SimpleLensLike Maybe s a -> s -> Bool+traverse_pureMaybe :: Eq s => LensLike' Maybe s a -> s -> Bool traverse_pureMaybe = traverse_pure -traverse_pureList :: Eq s => SimpleLensLike [] s a -> s -> Bool+traverse_pureList :: Eq s => LensLike' [] s a -> s -> Bool traverse_pureList = traverse_pure  traverse_compose :: (Applicative f, Applicative g, Eq (f (g s)))-                    => Simple Traversal s a -> (a -> g a) -> (a -> f a) -> s -> Bool+                    => Traversal' s a -> (a -> g a) -> (a -> f a) -> s -> Bool traverse_compose t f g s = (fmap (t f) . t g) s == (getCompose . t (Compose . fmap f . g)) s  isSetter :: (Arbitrary s, Arbitrary a, CoArbitrary a, Show s, Show a, Eq s, Function a)-         => Simple Setter s a -> Property+         => Setter' s a -> Property isSetter l = setter_id l .&. setter_composition l .&. setter_set_set l  isTraversal :: (Arbitrary s, Arbitrary a, CoArbitrary a, Show s, Show a, Eq s, Function a)-         => Simple Traversal s a -> Property+         => Traversal' s a -> Property isTraversal l = isSetter l .&. traverse_pureMaybe l .&. traverse_pureList l                   .&. do as <- arbitrary                          bs <- arbitrary@@ -77,32 +91,32 @@                                                        (\x -> if t then Just x else Nothing)  isLens :: (Arbitrary s, Arbitrary a, CoArbitrary a, Show s, Show a, Eq s, Eq a, Function a)-       => Simple Lens s a -> Property+       => Lens' s a -> Property isLens l = lens_set_view l .&. lens_view_set l .&. isTraversal l  isIso :: (Arbitrary s, Arbitrary a, CoArbitrary s, CoArbitrary a, Show s, Show a, Eq s, Eq a, Function s, Function a)-      => Simple Iso s a -> Property+      => Iso' s a -> Property isIso l = iso_hither l .&. iso_yon l .&. isLens l .&. isLens (from l)  isPrism :: (Arbitrary s, Arbitrary a, CoArbitrary a, Show s, Show a, Eq s, Eq a, Function a)-      => Simple Prism s a -> Property+      => Prism' s a -> Property isPrism l = isTraversal l .&. prism_yin l .&. prism_yang l  -- an illegal lens-bad :: Simple Lens (Int,Int) Int+bad :: Lens' (Int,Int) Int bad f (a,b) = (,) b <$> f a -badIso :: Simple Iso Int Bool+badIso :: Iso' Int Bool badIso = iso even fromEnum  -- Control.Lens.Type-prop_1                               = isLens (_1 :: Simple Lens (Int,Double,()) Int)-prop_2                               = isLens (_2 :: Simple Lens (Int,Bool) Bool)-prop_3                               = isLens (_3 :: Simple Lens (Int,Bool,()) ())-prop_4                               = isLens (_4 :: Simple Lens (Int,Bool,(),Maybe Int) (Maybe Int))-prop_5                               = isLens (_5 :: Simple Lens ((),(),(),(),Int) Int)+prop_1                               = isLens (_1 :: Lens' (Int,Double,()) Int)+prop_2                               = isLens (_2 :: Lens' (Int,Bool) Bool)+prop_3                               = isLens (_3 :: Lens' (Int,Bool,()) ())+prop_4                               = isLens (_4 :: Lens' (Int,Bool,(),Maybe Int) (Maybe Int))+prop_5                               = isLens (_5 :: Lens' ((),(),(),(),Int) Int) -prop_2_2                             = isLens (_2._2 :: Simple Lens (Int,(Int,Bool),Double) Bool)+prop_2_2                             = isLens (_2._2 :: Lens' (Int,(Int,Bool),Double) Bool)  -- prop_illegal_lens                    = expectFailure $ isLens bad -- prop_illegal_traversal               = expectFailure $ isTraversal bad@@ -110,27 +124,72 @@ -- prop_illegal_iso                     = expectFailure $ isIso badIso  -- Control.Lens.Setter-prop_mapped                          = isSetter (mapped :: Simple Setter [Int] Int)-prop_mapped_mapped                   = isSetter (mapped.mapped :: Simple Setter [Maybe Int] Int)+prop_mapped                          = isSetter (mapped :: Setter' [Int] Int)+prop_mapped_mapped                   = isSetter (mapped.mapped :: Setter' [Maybe Int] Int) -prop_both                            = isTraversal (both    :: Simple Traversal (Int,Int) Int)-prop_value (Fun _ k :: Fun Int Bool) = isTraversal (value k :: Simple Traversal (Int,Int) Int)-prop_traverseLeft                    = isTraversal (_left   :: Simple Traversal (Either Int Bool) Int)-prop_traverseRight                   = isTraversal (_right  :: Simple Traversal (Either Int Bool) Bool)+prop_both                            = isTraversal (both           :: Traversal' (Int,Int) Int)+prop_value (Fun _ k :: Fun Int Bool) = isTraversal (each.indices k :: Traversal' (Int, Int) Int)+prop_traverseLeft                    = isTraversal (_Left          :: Traversal' (Either Int Bool) Int)+prop_traverseRight                   = isTraversal (_Right         :: Traversal' (Either Int Bool) Bool) -prop_simple                          = isIso (simple :: Simple Iso Int Int)---prop_enum                            = isIso (enum :: Simple Iso Int Char)+prop_simple                          = isIso (simple :: Iso' Int Int)+--prop_enum                            = isIso (enum :: Iso' Int Char) -prop__left                           = isPrism (_left :: Simple Prism (Either Int Bool) Int)-prop__right                          = isPrism (_right :: Simple Prism (Either Int Bool) Bool)-prop__just                           = isPrism (_just :: Simple Prism (Maybe Int) Int)+prop__Left                           = isPrism (_Left :: Prism' (Either Int Bool) Int)+prop__Right                          = isPrism (_Right :: Prism' (Either Int Bool) Bool)+prop__Just                           = isPrism (_Just :: Prism' (Maybe Int) Int)  -- Data.List.Lens-prop_strippingPrefix s               = isPrism (strippingPrefix s :: Simple Prism String String)+prop_strippingPrefix s               = isPrism (strippingPrefix s :: Prism' String String)  -- Data.Text.Lens prop_text s                          = s^.packed.from packed == s --prop_text                           = isIso packed++-- Numeric.Lens+prop_base_show (n :: Integer) =+  conjoin [ show n == n ^. re (base 10)+          , showSigned showOct 0 n "" == n ^. re (base 8)+          , showSigned showHex 0 n "" == n ^. re (base 16)+          ]+prop_base_read (n :: Integer) =+  conjoin [ show n ^? base 10 == Just n+          , showSigned showOct 0 n "" ^? base 8  == Just n+          , showSigned showHex 0 n "" ^? base 16 == Just n+          , map toUpper (showSigned showHex 0 n "") ^? base 16 == Just n+          ]+prop_base_readFail (s :: String) =+  forAll (choose (2,36)) $ \b ->+    not isValid ==> s ^? base b == Nothing+  where+    isValid = (not . null) sPos && all isValidChar sPos+    sPos = case s of { ('-':s') -> s'; _ -> s }+    isValidChar c = isAscii c && isAlphaNum c++-- Control.Lens.Zipper++prop_zipper_id (NonEmpty (s :: String)) =+  (zipper s & fromWithin traverse & rezip) == s &&+  over traverse id s == s++prop_zipper_Rightmost (NonEmpty (s :: String)) =+  (zipper s & fromWithin traverse & rightmost & view focus) ==+  (zipper s & fromWithin traverse & farthest rightward & view focus)++prop_zipper_Leftmost (NonEmpty (s :: String)) =+  (zipper s & fromWithin traverse & leftmost & view focus) ==+  (zipper s & fromWithin traverse & farthest leftward & view focus)++prop_zipper_Rightward_fails (NonEmpty (s :: String)) =+  isNothing (zipper s & rightmost & rightward) &&+  isNothing (zipper s & fromWithin traverse & rightmost & rightward)++prop_zipper_Leftward_fails (NonEmpty (s :: String)) =+  isNothing (zipper s & leftmost & leftward) &&+  isNothing (zipper s & fromWithin traverse & leftmost & leftward)++prop_zipper_tooth_id (NonEmpty (s :: String)) =+  let z = zipper s in isJust (jerkTo (tooth z) z)  main :: IO () main = $defaultMainGenerator
tests/templates.hs view
@@ -1,10 +1,22 @@-{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE FlexibleInstances #-}--- | The commented code summarizes what will be auto-generated below+-----------------------------------------------------------------------------+-- |+-- Module      :  Main (templates)+-- Copyright   :  (C) 2012-13 Edward Kmett+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Edward Kmett <ekmett@gmail.com>+-- Stability   :  experimental+-- Portability :  non-portable+--+-- This test suite validates that we are able to generate usable lenses with +-- template haskell.+--+-- The commented code summarizes what will be auto-generated below+----------------------------------------------------------------------------- module Main where  import Control.Lens
+ travis/cabal-apt-install view
@@ -0,0 +1,16 @@+#!/bin/sh+set -eu++sudo apt-get -q update+sudo apt-get -q -y install dctrl-tools++# Try installing some of the build-deps with apt-get for speed.+eval "$(+  printf '%s' "grep-aptavail -n -sPackage '(' -FFALSE -X FALSE ')'"+  2>/dev/null cabal install "$@" --dry-run -v | \+  sed -nre "s/^([^ ]+)-[0-9.]+ \(.*$/ -o '(' -FPackage -X libghc-\1-dev ')'/p" | \+  xargs -d'\n'+)" | sort -u | xargs -d'\n' sudo apt-get -q -y install -- libghc-quickcheck2-dev++# Install whatever is still needed with cabal.+cabal install "$@"
+ travis/config view
@@ -0,0 +1,16 @@+-- This provides a custom ~/.cabal/config file for use when hackage is down that should work on unix+--+-- This is particularly useful for travis-ci to get it to stop complaining+-- about a broken build when everything is still correct on our end.+--+-- This uses Luite Stegeman's mirror of hackage provided by his 'hdiff' site instead+--+-- To enable this, uncomment the before_script in .travis.yml++remote-repo: hdiff.luite.com:http://hdiff.luite.com/packages/archive+remote-repo-cache: ~/.cabal/packages+world-file: ~/.cabal/world+build-summary: ~/.cabal/logs/build.log+remote-build-reporting: anonymous+install-dirs user+install-dirs global