lens-4.17.1: Lenses, Folds and Traversals

Copyright | (C) 2012-16 Edward Kmett
License | BSD-style (see the file LICENSE)
Maintainer | Edward Kmett <ekmett@gmail.com>
Stability | provisional
Portability | Rank2Types
Safe Haskell | Trustworthy
Language | Haskell2010

Control.Lens.Traversal

Contents

- Traversals
- Traversing and Lensing
- Monomorphic Traversals
- Parts and Holes
- Common Traversals
- Indexed Traversals
  - Common
  - Combinators
- Reflection
- Implementation Details
- Fusion

Description

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

    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

A `Traversal` can be used as a `Fold`. Any `Traversal` can be used for `Getting` like a `Fold`, because given a `Monoid` `m`, we have an `Applicative` for `(`Const` m)`. Everything you know how to do with a `Traversable` container, you can with a `Traversal`, and here we provide combinators that generalize the usual `Traversable` operations.

Synopsis

- type Traversal s t a b = forall f. Applicative f => (a -> f b) -> s -> f t
- type Traversal' s a = Traversal s s a a
- type Traversal1 s t a b = forall f. Apply f => (a -> f b) -> s -> f t
- type Traversal1' s a = Traversal1 s s a a
- 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 s a = IndexedTraversal i s s a a
- type IndexedTraversal1 i s t a b = forall p f. (Indexable i p, Apply f) => p a (f b) -> s -> f t
- type IndexedTraversal1' i s a = IndexedTraversal1 i s s a a
- type ATraversal s t a b = LensLike (Bazaar (->) a b) s t a b
- type ATraversal' s a = ATraversal s s a a
- type ATraversal1 s t a b = LensLike (Bazaar1 (->) a b) s t a b
- type ATraversal1' s a = ATraversal1 s s a a
- type AnIndexedTraversal i s t a b = Over (Indexed i) (Bazaar (Indexed i) a b) s t a b
- type AnIndexedTraversal' i s a = AnIndexedTraversal i s s a a
- type AnIndexedTraversal1 i s t a b = Over (Indexed i) (Bazaar1 (Indexed i) a b) s t a b
- type AnIndexedTraversal1' i s a = AnIndexedTraversal1 i s s a a
- type Traversing p f s t a b = Over p (BazaarT p f a b) s t a b
- type Traversing' p f s a = Traversing p f s s a a
- type Traversing1 p f s t a b = Over p (BazaarT1 p f a b) s t a b
- type Traversing1' p f s a = Traversing1 p f s s a a
- traverseOf :: LensLike f s t a b -> (a -> f b) -> s -> f t
- forOf :: LensLike f s t a b -> s -> (a -> f b) -> f t
- sequenceAOf :: LensLike f s t (f b) b -> s -> f t
- mapMOf :: LensLike (WrappedMonad m) s t a b -> (a -> m b) -> s -> m t
- forMOf :: LensLike (WrappedMonad m) s t a b -> s -> (a -> m b) -> m t
- sequenceOf :: LensLike (WrappedMonad m) s t (m b) b -> s -> m t
- transposeOf :: LensLike ZipList s t [a] a -> s -> [t]
- mapAccumLOf :: LensLike (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)
- scanr1Of :: LensLike (Backwards (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
- failover :: Alternative m => LensLike ((,) Any) s t a b -> (a -> b) -> s -> m t
- ifailover :: Alternative m => Over (Indexed i) ((,) Any) s t a b -> (i -> a -> b) -> s -> m t
- cloneTraversal :: ATraversal s t a b -> Traversal s t a b
- cloneIndexPreservingTraversal :: ATraversal s t a b -> IndexPreservingTraversal s t a b
- cloneIndexedTraversal :: AnIndexedTraversal i s t a b -> IndexedTraversal i s t a b
- cloneTraversal1 :: ATraversal1 s t a b -> Traversal1 s t a b
- cloneIndexPreservingTraversal1 :: ATraversal1 s t a b -> IndexPreservingTraversal1 s t a b
- cloneIndexedTraversal1 :: AnIndexedTraversal1 i s t a b -> IndexedTraversal1 i s t a b
- partsOf :: Functor f => Traversing (->) f s t a a -> LensLike f s t [a] [a]
- partsOf' :: ATraversal s t a a -> Lens s t [a] [a]
- unsafePartsOf :: Functor f => Traversing (->) f s t a b -> LensLike f s t [a] [b]
- unsafePartsOf' :: ATraversal s t a b -> Lens s t [a] [b]
- holesOf :: Conjoined p => Over p (Bazaar p a a) s t a a -> s -> [Pretext p a a t]
- holes1Of :: Conjoined p => Over p (Bazaar1 p a a) s t a a -> s -> NonEmpty (Pretext p a a t)
- singular :: (HasCallStack, Conjoined p, Functor f) => Traversing p f s t a a -> Over p f s t a a
- unsafeSingular :: (HasCallStack, Conjoined p, Functor f) => Traversing p f s t a b -> Over p f s t a b
- class (Functor t, Foldable t) => Traversable (t :: Type -> Type) where
  - traverse :: Applicative f => (a -> f b) -> t a -> f (t b)
- class (Foldable1 t, Traversable t) => Traversable1 (t :: Type -> Type) where
  - traverse1 :: Apply f => (a -> f b) -> t a -> f (t b)
- both :: Bitraversable r => Traversal (r a a) (r b b) a b
- both1 :: Bitraversable1 r => Traversal1 (r a a) (r b b) a b
- beside :: (Representable q, Applicative (Rep q), Applicative f, Bitraversable r) => Optical p q f s t a b -> Optical p q f s' t' a b -> Optical p q f (r s s') (r t t') a b
- taking :: (Conjoined p, Applicative f) => Int -> Traversing p f s t a a -> Over p f s t a a
- dropping :: (Conjoined p, Applicative f) => Int -> Over p (Indexing f) s t a a -> Over p f s t a a
- failing :: (Conjoined p, Applicative f) => Traversing p f s t a b -> Over p f s t a b -> Over p f s t a b
- deepOf :: (Conjoined p, Applicative f) => LensLike f s t s t -> Traversing p f s t a b -> Over p f s t a b
- ignored :: Applicative f => pafb -> s -> f s
- class Ord k => TraverseMin k m | m -> k where
  - traverseMin :: IndexedTraversal' k (m v) v
- class Ord k => TraverseMax k m | m -> k where
  - traverseMax :: IndexedTraversal' k (m v) v
- traversed :: Traversable f => IndexedTraversal Int (f a) (f b) a b
- traversed1 :: Traversable1 f => IndexedTraversal1 Int (f a) (f b) a b
- traversed64 :: Traversable f => IndexedTraversal Int64 (f a) (f b) a b
- elementOf :: Applicative f => LensLike (Indexing f) s t a a -> Int -> IndexedLensLike Int f s t a a
- element :: Traversable t => Int -> IndexedTraversal' Int (t a) a
- elementsOf :: Applicative f => LensLike (Indexing f) s t a a -> (Int -> Bool) -> IndexedLensLike Int f s t a a
- elements :: Traversable t => (Int -> Bool) -> IndexedTraversal' Int (t a) a
- ipartsOf :: forall i p f s t a. (Indexable [i] p, Functor f) => Traversing (Indexed i) f s t a a -> Over p f s t [a] [a]
- ipartsOf' :: 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]
- iunsafePartsOf :: forall i p f s t a b. (Indexable [i] p, Functor f) => Traversing (Indexed i) f s t a b -> Over p f s t [a] [b]
- iunsafePartsOf' :: forall i s t a b. Over (Indexed i) (Bazaar (Indexed i) a b) s t a b -> IndexedLens [i] s t [a] [b]
- itraverseOf :: (Indexed i a (f b) -> s -> f t) -> (i -> a -> f b) -> s -> f t
- iforOf :: (Indexed i a (f b) -> s -> f t) -> s -> (i -> a -> f b) -> f t
- imapMOf :: Over (Indexed i) (WrappedMonad m) s t a b -> (i -> a -> m b) -> s -> m t
- iforMOf :: (Indexed i a (WrappedMonad m b) -> s -> WrappedMonad m t) -> s -> (i -> a -> m b) -> m t
- imapAccumROf :: Over (Indexed i) (Backwards (State acc)) s t a b -> (i -> acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
- imapAccumLOf :: Over (Indexed i) (State acc) s t a b -> (i -> acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
- traverseBy :: Traversable t => (forall x. x -> f x) -> (forall x y. f (x -> y) -> f x -> f y) -> (a -> f b) -> t a -> f (t b)
- traverseByOf :: Traversal s t a b -> (forall x. x -> f x) -> (forall x y. f (x -> y) -> f x -> f y) -> (a -> f b) -> s -> f t
- sequenceBy :: Traversable t => (forall x. x -> f x) -> (forall x y. f (x -> y) -> f x -> f y) -> t (f a) -> f (t a)
- sequenceByOf :: Traversal s t (f b) b -> (forall x. x -> f x) -> (forall x y. f (x -> y) -> f x -> f y) -> s -> f t
- newtype Bazaar p a b t = Bazaar {
  - runBazaar :: forall f. Applicative f => p a (f b) -> f t
  }
- type Bazaar' p a = Bazaar p a a
- newtype Bazaar1 p a b t = Bazaar1 {
  - runBazaar1 :: forall f. Apply f => p a (f b) -> f t
  }
- type Bazaar1' p a = Bazaar1 p a a
- loci :: Traversal (Bazaar (->) a c s) (Bazaar (->) b c s) a b
- iloci :: IndexedTraversal i (Bazaar (Indexed i) a c s) (Bazaar (Indexed i) b c s) a b
- confusing :: Applicative f => LensLike (Curried (Yoneda f) (Yoneda f)) s t a b -> LensLike f s t a b

# Traversals

type Traversal s t a b = forall f. Applicative f => (a -> f b) -> s -> f t Source #

A `Traversal` can be used directly as a `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

    traverse :: Traversable f => Traversal (f a) (f b) a b

and the more evocative name suggests their application.

Most of the time the `Traversal` you will want to use is just `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`.

The laws for a `Traversal` `t` follow from the laws for `Traversable` as stated in "The Essence of the Iterator Pattern".

    t pure ≡ pure
    fmap (t f) . t g ≡ getCompose . t (Compose . fmap f . g)

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 a = Traversal s s a a Source #

    type Traversal' = Simple Traversal

type Traversal1 s t a b = forall f. Apply f => (a -> f b) -> s -> f t Source #

type Traversal1' s a = Traversal1 s s a a Source #

type IndexedTraversal i s t a b = forall p f. (Indexable i p, Applicative f) => p a (f b) -> s -> f t Source #

Every `IndexedTraversal` is a valid `Traversal` or `IndexedFold`.

The `Indexed` constraint is used to allow an `IndexedTraversal` to be used directly as a `Traversal`.

The `Traversal` laws are still required to hold.

In addition, the index `i` should satisfy the requirement that it stays unchanged even when modifying the value `a`, otherwise traversals like `indices` break the `Traversal` laws.

type IndexedTraversal' i s a = IndexedTraversal i s s a a Source #

    type IndexedTraversal' i = Simple (IndexedTraversal i)

type IndexedTraversal1 i s t a b = forall p f. (Indexable i p, Apply f) => p a (f b) -> s -> f t Source #

type IndexedTraversal1' i s a = IndexedTraversal1 i s s a a Source #

type ATraversal s t a b = LensLike (Bazaar (->) a b) s t a b Source #

When you see this as an argument to a function, it expects a `Traversal`.

type ATraversal' s a = ATraversal s s a a Source #

    type ATraversal' = Simple ATraversal

type ATraversal1 s t a b = LensLike (Bazaar1 (->) a b) s t a b Source #

When you see this as an argument to a function, it expects a `Traversal1`.

type ATraversal1' s a = ATraversal1 s s a a Source #

    type ATraversal1' = Simple ATraversal1

type AnIndexedTraversal i s t a b = Over (Indexed i) (Bazaar (Indexed i) a b) s t a b Source #

When you see this as an argument to a function, it expects an `IndexedTraversal`.

type AnIndexedTraversal' i s a = AnIndexedTraversal i s s a a Source #

    type AnIndexedTraversal' = Simple (AnIndexedTraversal i)

type AnIndexedTraversal1 i s t a b = Over (Indexed i) (Bazaar1 (Indexed i) a b) s t a b Source #

When you see this as an argument to a function, it expects an `IndexedTraversal1`.

type AnIndexedTraversal1' i s a = AnIndexedTraversal1 i s s a a Source #

    type AnIndexedTraversal1' = Simple (AnIndexedTraversal1 i)

type Traversing p f s t a b = Over p (BazaarT p f a b) s t a b Source #

When you see this as an argument to a function, it expects

- to be indexed if `p` is an instance of `Indexed` i,
- to be unindexed if `p` is `(->)`,
- a `Traversal` if `f` is `Applicative`,
- a `Getter` if `f` is only a `Functor` and `Contravariant`,
- a `Lens` if `f` is only a `Functor`,
- a `Fold` if `f` is `Applicative` and `Contravariant`.

type Traversing' p f s a = Traversing p f s s a a Source #

    type Traversing' f = Simple (Traversing f)

type Traversing1 p f s t a b = Over p (BazaarT1 p f a b) s t a b Source #

type Traversing1' p f s a = Traversing1 p f s s a a Source #

# Traversing and Lensing

traverseOf :: LensLike f s t a b -> (a -> f b) -> s -> f t Source #

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 each print (1,2,3)
    1
    2
    3
    ((),(),())

    traverseOf ≡ id
    itraverseOf l ≡ traverseOf l . Indexed
    itraverseOf itraversed ≡ itraverse

This yields the obvious law:

    traverse ≡ traverseOf traverse

    traverseOf :: Functor f     => Iso s t a b        -> (a -> f b) -> s -> f t
    traverseOf :: Functor f     => Lens s t a b       -> (a -> f b) -> s -> f t
    traverseOf :: Apply f       => Traversal1 s t a b -> (a -> f b) -> s -> f t
    traverseOf :: Applicative f => Traversal s t a b  -> (a -> f b) -> s -> f t

forOf :: LensLike f s t a b -> s -> (a -> f b) -> f t Source #

A version of `traverseOf` with the arguments flipped, such that:

    >>> forOf each (1,2,3) print
    1
    2
    3
    ((),(),())

This function is only provided for consistency, `flip` is strictly more general.

    forOf ≡ flip
    forOf ≡ flip . traverseOf

    for ≡ forOf traverse
    ifor l s ≡ for l s . Indexed

    forOf :: Functor f => Iso s t a b -> s -> (a -> f b) -> f t
    forOf :: Functor f => Lens s t a b -> s -> (a -> f b) -> f t
    forOf :: Applicative f => Traversal s t a b -> s -> (a -> f b) -> f t

sequenceAOf :: LensLike f s t (f b) b -> s -> f t Source #

Evaluate each action in the structure from left to right, and collect the results.

    >>> sequenceAOf both ([1,2],[3,4])
    [(1,3),(1,4),(2,3),(2,4)]

    sequenceA ≡ sequenceAOf traverse ≡ traverse id
    sequenceAOf l ≡ traverseOf l id ≡ l id

    sequenceAOf :: Functor f => Iso s t (f b) b       -> s -> f t
    sequenceAOf :: Functor f => Lens s t (f b) b      -> s -> f t
    sequenceAOf :: Applicative f => Traversal s t (f b) b -> s -> f t

mapMOf :: LensLike (WrappedMonad m) s t a b -> (a -> m b) -> s -> m t Source #

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.

    >>> mapMOf both (\x -> [x, x + 1]) (1,3)
    [(1,3),(1,4),(2,3),(2,4)]

    mapM ≡ mapMOf traverse
    imapMOf l ≡ forM l . Indexed

    mapMOf :: Monad m => Iso s t a b       -> (a -> m b) -> s -> m t
    mapMOf :: Monad m => 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

forMOf :: LensLike (WrappedMonad m) s t a b -> s -> (a -> m b) -> m t Source #

`forMOf` is a flipped version of `mapMOf`, consistent with the definition of `forM`.

    >>> forMOf both (1,3) $ \x -> [x, x + 1]
    [(1,3),(1,4),(2,3),(2,4)]

    forM ≡ forMOf traverse
    forMOf l ≡ flip (mapMOf l)
    iforMOf l s ≡ forM l s . Indexed

    forMOf :: Monad m => Iso s t a b       -> s -> (a -> m b) -> m t
    forMOf :: Monad m => 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

sequenceOf :: LensLike (WrappedMonad m) s t (m b) b -> s -> m t Source #

Sequence the (monadic) effects targeted by a `Lens` in a container from left to right.

    >>> sequenceOf each ([1,2],[3,4],[5,6])
    [(1,3,5),(1,3,6),(1,4,5),(1,4,6),(2,3,5),(2,3,6),(2,4,5),(2,4,6)]

    sequence ≡ sequenceOf traverse
    sequenceOf l ≡ mapMOf l id
    sequenceOf l ≡ unwrapMonad . l WrapMonad

    sequenceOf :: Monad m => Iso s t (m b) b       -> s -> m t
    sequenceOf :: Monad m => Lens s t (m b) b      -> s -> m t
    sequenceOf :: Monad m => Traversal s t (m b) b -> s -> m t

transposeOf :: LensLike ZipList s t [a] a -> s -> [t] Source #

This generalizes `transpose` to an arbitrary `Traversal`.

Note: `transpose` handles ragged inputs more intelligently, but for non-ragged inputs:

    >>> transposeOf traverse [[1,2,3],[4,5,6]]
    [[1,4],[2,5],[3,6]]

    transpose ≡ transposeOf traverse

Since every `Lens` is a `Traversal`, we can use this as a form of monadic strength as well:

    transposeOf _2 :: (b, [a]) -> [(b, a)]

mapAccumLOf :: LensLike (State acc) s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t) Source #

This generalizes `mapAccumL` to an arbitrary `Traversal`.

    mapAccumL ≡ mapAccumLOf traverse

`mapAccumLOf` accumulates `State` from left to right.

    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 (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)

mapAccumROf :: LensLike (Backwards (State acc)) s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t) Source #

This generalizes `mapAccumR` to an arbitrary `Traversal`.

    mapAccumR ≡ mapAccumROf traverse

`mapAccumROf` accumulates `State` from right to left.

    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 (State acc)) s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)

scanr1Of :: LensLike (Backwards (State (Maybe a))) s t a a -> (a -> a -> a) -> s -> t Source #

This permits the use of `scanr1` over an arbitrary `Traversal` or `Lens`.

    scanr1 ≡ scanr1Of traverse

    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

scanl1Of :: LensLike (State (Maybe a)) s t a a -> (a -> a -> a) -> s -> t Source #

This permits the use of `scanl1` over an arbitrary `Traversal` or `Lens`.

    scanl1 ≡ scanl1Of traverse

    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

failover :: Alternative m => LensLike ((,) Any) s t a b -> (a -> b) -> s -> m t Source #

Try to map a function over this `Traversal`, failing if the `Traversal` has no targets.

    >>> failover (element 3) (*2) [1,2] :: Maybe [Int]
    Nothing

    >>> failover _Left (*2) (Right 4) :: Maybe (Either Int Int)
    Nothing

    >>> failover _Right (*2) (Right 4) :: Maybe (Either Int Int)
    Just (Right 8)

    failover :: Alternative m => Traversal s t a b -> (a -> b) -> s -> m t

ifailover :: Alternative m => Over (Indexed i) ((,) Any) s t a b -> (i -> a -> b) -> s -> m t Source #

Try to map a function which uses the index over this `IndexedTraversal`, failing if the `IndexedTraversal` has no targets.

    ifailover :: Alternative m => IndexedTraversal i s t a b -> (i -> a -> b) -> s -> m t

# Monomorphic Traversals

cloneTraversal :: ATraversal s t a b -> Traversal s t a b Source #

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 `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`.

Note: It is usually better to use `ReifiedTraversal` and `runTraversal` 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 (getting (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

cloneIndexPreservingTraversal :: ATraversal s t a b -> IndexPreservingTraversal s t a b Source #

Clone a `Traversal` yielding an `IndexPreservingTraversal` that passes through whatever index it is composed with.

cloneIndexedTraversal :: AnIndexedTraversal i s t a b -> IndexedTraversal i s t a b Source #

Clone an `IndexedTraversal` yielding an `IndexedTraversal` with the same index.

cloneTraversal1 :: ATraversal1 s t a b -> Traversal1 s t a b Source #

A `Traversal1` is completely characterized by its behavior on a `Bazaar1`.

cloneIndexPreservingTraversal1 :: ATraversal1 s t a b -> IndexPreservingTraversal1 s t a b Source #

Clone a `Traversal1` yielding an `IndexPreservingTraversal1` that passes through whatever index it is composed with.

cloneIndexedTraversal1 :: AnIndexedTraversal1 i s t a b -> IndexedTraversal1 i s t a b Source #

Clone an `IndexedTraversal1` yielding an `IndexedTraversal1` with the same index.

# Parts and Holes

partsOf :: Functor f => Traversing (->) f s t a a -> LensLike f s t [a] [a] Source #

`partsOf` turns a `Traversal` into a `Lens` that resembles an early version of the `uniplate` (or `biplate`) type.

Note: You should really try to maintain the invariant of the number of children in the list.

    >>> (a,b,c) & partsOf each .~ [x,y,z]
    (x,y,z)

Any extras will be lost. If you do not supply enough, then the remainder will come from the original structure.

    >>> (a,b,c) & partsOf each .~ [w,x,y,z]
    (w,x,y)

    >>> (a,b,c) & partsOf each .~ [x,y]
    (x,y,c)

    >>> ('b', 'a', 'd', 'c') & partsOf each %~ sort
    ('a','b','c','d')

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 `Getter`.

    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' :: ATraversal s t a a -> Lens s t [a] [a] Source #

A type-restricted version of `partsOf` that can only be used with a `Traversal`.

unsafePartsOf :: Functor f => Traversing (->) f s t a b -> LensLike f s t [a] [b] Source #

`unsafePartsOf` turns a `Traversal` into a `uniplate` (or `biplate`) family.

If you do not need the types of `s` and `t` to be different, it is recommended that you use `partsOf`.

It is generally safer to traverse with the `Bazaar` rather than use this combinator. However, it is sometimes convenient.

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 `Getter` (and becomes safe).

    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          -> Getter s [a]
    unsafePartsOf :: Getter s a        -> Getter s [a]

unsafePartsOf' :: ATraversal s t a b -> Lens s t [a] [b] Source #

holesOf :: Conjoined p => Over p (Bazaar p a a) s t a a -> s -> [Pretext p a a t] Source #

The one-level version of `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.

    propChildren l x = toListOf l x == map pos (holesOf l x)
    propId l x = all (== x) [extract w | w <- holesOf l x]

    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]

holes1Of :: Conjoined p => Over p (Bazaar1 p a a) s t a a -> s -> NonEmpty (Pretext p a a t) Source #

The non-empty version of `holesOf`. This extract a non-empty list of immediate children accroding to a given `Traversal1` as editable contexts.

    >>> let head1 f s = runPretext (NonEmpty.head $ holes1Of traversed1 s) f
    >>> ('a' :| "bc") ^. head1
    'a'

    >>> ('a' :| "bc") & head1 %~ toUpper
    'A' :| "bc"

    holes1Of :: Iso' s a                 -> s -> NonEmpty (Pretext' (->) a s)
    holes1Of :: Lens' s a                -> s -> NonEmpty (Pretext' (->) a s)
    holes1Of :: Traversal1' s a          -> s -> NonEmpty (Pretext' (->) a s)
    holes1Of :: IndexedLens' i s a       -> s -> NonEmpty (Pretext' (Indexed i) a s)
    holes1Of :: IndexedTraversal1' i s a -> s -> NonEmpty (Pretext' (Indexed i) a s)

singular :: (HasCallStack, Conjoined p, Functor f) => Traversing p f s t a a -> Over p f s t a a Source #

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 `Getter`.

The resulting `Lens` or `Getter` will be partial if the supplied `Traversal` returns no results.

    >>> [1,2,3] ^. singular _head
    1

    >>> Left (ErrorCall "singular: empty traversal") <- try (evaluate ([] ^. singular _head)) :: IO (Either ErrorCall ())

    >>> Left 4 ^. singular _Left
    4

    >>> [1..10] ^. singular (ix 7)
    8

    >>> [] & singular traverse .~ 0
    []

    singular :: Traversal s t a a          -> Lens s t a a
    singular :: Fold s a                   -> Getter s a
    singular :: IndexedTraversal i s t a a -> IndexedLens i s t a a
    singular :: IndexedFold i s a          -> IndexedGetter i s a

unsafeSingular :: (HasCallStack, Conjoined p, Functor f) => Traversing p f s t a b -> Over p f s t a b Source #

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 `Getter`.

The resulting `Lens` or `Getter` will be partial if the `Traversal` targets nothing or more than one element.

    >>> Left (ErrorCall "unsafeSingular: empty traversal") <- try (evaluate ([] & unsafeSingular traverse .~ 0)) :: IO (Either ErrorCall [Integer])

    unsafeSingular :: Traversal s t a b          -> Lens s t a b
    unsafeSingular :: Fold s a                   -> Getter s a
    unsafeSingular :: IndexedTraversal i s t a b -> IndexedLens i s t a b
    unsafeSingular :: IndexedFold i s a          -> IndexedGetter i s a

# Common Traversals

class (Functor t, Foldable t) => Traversable (t :: Type -> Type) where Source #

Functors representing data structures that can be traversed from left to right.

A definition of `traverse` must satisfy the following laws:

naturality
  `t . `traverse` f = `traverse` (t . f)` for every applicative transformation `t`
identity
  ``traverse` Identity = Identity`
composition
  ``traverse` (Compose . `fmap` g . f) = Compose . `fmap` (`traverse` g) . `traverse` f`

A definition of `sequenceA` must satisfy the following laws:

naturality
  `t . `sequenceA` = `sequenceA` . `fmap` t` for every applicative transformation `t`
identity
  ``sequenceA` . `fmap` Identity = Identity`
composition
  ``sequenceA` . `fmap` Compose = Compose . `fmap` `sequenceA` . `sequenceA``

where an applicative transformation is a function

    t :: (Applicative f, Applicative g) => f a -> g a

preserving the `Applicative` operations, i.e.

-     t (pure x) = pure x

-     t (x <*> y) = t x <*> t y

and the identity functor `Identity` and composition of functors `Compose` are defined as

      newtype Identity a = Identity a

      instance Functor Identity where
        fmap f (Identity x) = Identity (f x)

      instance Applicative Identity where
        pure x = Identity x
        Identity f <*> Identity x = Identity (f x)

      newtype Compose f g a = Compose (f (g a))

      instance (Functor f, Functor g) => Functor (Compose f g) where
        fmap f (Compose x) = Compose (fmap (fmap f) x)

      instance (Applicative f, Applicative g) => Applicative (Compose f g) where
        pure x = Compose (pure (pure x))
        Compose f <*> Compose x = Compose ((<*>) <$> f <*> x)

(The naturality law is implied by parametricity.)

Instances are similar to `Functor`, e.g. given a data type

    data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a)

a suitable instance would be

    instance Traversable Tree where
       traverse f Empty = pure Empty
       traverse f (Leaf x) = Leaf <$> f x
       traverse f (Node l k r) = Node <$> traverse f l <*> f k <*> traverse f r

This is suitable even for abstract types, as the laws for `<*>` imply a form of associativity.

The superclass instances should satisfy the following:

- In the `Functor` instance, `fmap` should be equivalent to traversal with the identity applicative functor (`fmapDefault`).
- In the `Foldable` instance, `foldMap` should be equivalent to traversal with a constant applicative functor (`foldMapDefault`).

Minimal complete definition

traverse | sequenceA

Methods

traverse :: Applicative f => (a -> f b) -> t a -> f (t b) Source #

Map each element of a structure to an action, evaluate these actions from left to right, and collect the results. For a version that ignores the results see `traverse_`.

Instances

Traversable [] | Since: base-2.1
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> [a] -> f [b] Source # sequenceA :: Applicative f => [f a] -> f [a] Source # mapM :: Monad m => (a -> m b) -> [a] -> m [b] Source # sequence :: Monad m => [m a] -> m [a] Source #
Traversable Maybe | Since: base-2.1
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> Maybe a -> f (Maybe b) Source # sequenceA :: Applicative f => Maybe (f a) -> f (Maybe a) Source # mapM :: Monad m => (a -> m b) -> Maybe a -> m (Maybe b) Source # sequence :: Monad m => Maybe (m a) -> m (Maybe a) Source #
Traversable Par1 | Since: base-4.9.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> Par1 a -> f (Par1 b) Source # sequenceA :: Applicative f => Par1 (f a) -> f (Par1 a) Source # mapM :: Monad m => (a -> m b) -> Par1 a -> m (Par1 b) Source # sequence :: Monad m => Par1 (m a) -> m (Par1 a) Source #
Traversable Complex | Since: base-4.9.0.0
Instance details Defined in Data.Complex Methods traverse :: Applicative f => (a -> f b) -> Complex a -> f (Complex b) Source # sequenceA :: Applicative f => Complex (f a) -> f (Complex a) Source # mapM :: Monad m => (a -> m b) -> Complex a -> m (Complex b) Source # sequence :: Monad m => Complex (m a) -> m (Complex a) Source #
Traversable Min | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup Methods traverse :: Applicative f => (a -> f b) -> Min a -> f (Min b) Source # sequenceA :: Applicative f => Min (f a) -> f (Min a) Source # mapM :: Monad m => (a -> m b) -> Min a -> m (Min b) Source # sequence :: Monad m => Min (m a) -> m (Min a) Source #
Traversable Max | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup Methods traverse :: Applicative f => (a -> f b) -> Max a -> f (Max b) Source # sequenceA :: Applicative f => Max (f a) -> f (Max a) Source # mapM :: Monad m => (a -> m b) -> Max a -> m (Max b) Source # sequence :: Monad m => Max (m a) -> m (Max a) Source #
Traversable First | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup Methods traverse :: Applicative f => (a -> f b) -> First a -> f (First b) Source # sequenceA :: Applicative f => First (f a) -> f (First a) Source # mapM :: Monad m => (a -> m b) -> First a -> m (First b) Source # sequence :: Monad m => First (m a) -> m (First a) Source #
Traversable Last | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup Methods traverse :: Applicative f => (a -> f b) -> Last a -> f (Last b) Source # sequenceA :: Applicative f => Last (f a) -> f (Last a) Source # mapM :: Monad m => (a -> m b) -> Last a -> m (Last b) Source # sequence :: Monad m => Last (m a) -> m (Last a) Source #
Traversable Option | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup Methods traverse :: Applicative f => (a -> f b) -> Option a -> f (Option b) Source # sequenceA :: Applicative f => Option (f a) -> f (Option a) Source # mapM :: Monad m => (a -> m b) -> Option a -> m (Option b) Source # sequence :: Monad m => Option (m a) -> m (Option a) Source #
Traversable ZipList | Since: base-4.9.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> ZipList a -> f (ZipList b) Source # sequenceA :: Applicative f => ZipList (f a) -> f (ZipList a) Source # mapM :: Monad m => (a -> m b) -> ZipList a -> m (ZipList b) Source # sequence :: Monad m => ZipList (m a) -> m (ZipList a) Source #
Traversable Identity | Since: base-4.9.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> Identity a -> f (Identity b) Source # sequenceA :: Applicative f => Identity (f a) -> f (Identity a) Source # mapM :: Monad m => (a -> m b) -> Identity a -> m (Identity b) Source # sequence :: Monad m => Identity (m a) -> m (Identity a) Source #
Traversable First | Since: base-4.8.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> First a -> f (First b) Source # sequenceA :: Applicative f => First (f a) -> f (First a) Source # mapM :: Monad m => (a -> m b) -> First a -> m (First b) Source # sequence :: Monad m => First (m a) -> m (First a) Source #
Traversable Last | Since: base-4.8.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> Last a -> f (Last b) Source # sequenceA :: Applicative f => Last (f a) -> f (Last a) Source # mapM :: Monad m => (a -> m b) -> Last a -> m (Last b) Source # sequence :: Monad m => Last (m a) -> m (Last a) Source #
Traversable Dual | Since: base-4.8.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> Dual a -> f (Dual b) Source # sequenceA :: Applicative f => Dual (f a) -> f (Dual a) Source # mapM :: Monad m => (a -> m b) -> Dual a -> m (Dual b) Source # sequence :: Monad m => Dual (m a) -> m (Dual a) Source #
Traversable Sum | Since: base-4.8.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> Sum a -> f (Sum b) Source # sequenceA :: Applicative f => Sum (f a) -> f (Sum a) Source # mapM :: Monad m => (a -> m b) -> Sum a -> m (Sum b) Source # sequence :: Monad m => Sum (m a) -> m (Sum a) Source #
Traversable Product | Since: base-4.8.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> Product a -> f (Product b) Source # sequenceA :: Applicative f => Product (f a) -> f (Product a) Source # mapM :: Monad m => (a -> m b) -> Product a -> m (Product b) Source # sequence :: Monad m => Product (m a) -> m (Product a) Source #
Traversable Down | Since: base-4.12.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> Down a -> f (Down b) Source # sequenceA :: Applicative f => Down (f a) -> f (Down a) Source # mapM :: Monad m => (a -> m b) -> Down a -> m (Down b) Source # sequence :: Monad m => Down (m a) -> m (Down a) Source #
Traversable NonEmpty | Since: base-4.9.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> NonEmpty a -> f (NonEmpty b) Source # sequenceA :: Applicative f => NonEmpty (f a) -> f (NonEmpty a) Source # mapM :: Monad m => (a -> m b) -> NonEmpty a -> m (NonEmpty b) Source # sequence :: Monad m => NonEmpty (m a) -> m (NonEmpty a) Source #
Traversable IntMap |
Instance details Defined in Data.IntMap.Internal Methods traverse :: Applicative f => (a -> f b) -> IntMap a -> f (IntMap b) Source # sequenceA :: Applicative f => IntMap (f a) -> f (IntMap a) Source # mapM :: Monad m => (a -> m b) -> IntMap a -> m (IntMap b) Source # sequence :: Monad m => IntMap (m a) -> m (IntMap a) Source #
Traversable Tree |
Instance details Defined in Data.Tree Methods traverse :: Applicative f => (a -> f b) -> Tree a -> f (Tree b) Source # sequenceA :: Applicative f => Tree (f a) -> f (Tree a) Source # mapM :: Monad m => (a -> m b) -> Tree a -> m (Tree b) Source # sequence :: Monad m => Tree (m a) -> m (Tree a) Source #
Traversable Seq |
Instance details Defined in Data.Sequence.Internal Methods traverse :: Applicative f => (a -> f b) -> Seq a -> f (Seq b) Source # sequenceA :: Applicative f => Seq (f a) -> f (Seq a) Source # mapM :: Monad m => (a -> m b) -> Seq a -> m (Seq b) Source # sequence :: Monad m => Seq (m a) -> m (Seq a) Source #
Traversable FingerTree |
Instance details Defined in Data.Sequence.Internal Methods traverse :: Applicative f => (a -> f b) -> FingerTree a -> f (FingerTree b) Source # sequenceA :: Applicative f => FingerTree (f a) -> f (FingerTree a) Source # mapM :: Monad m => (a -> m b) -> FingerTree a -> m (FingerTree b) Source # sequence :: Monad m => FingerTree (m a) -> m (FingerTree a) Source #
Traversable Digit |
Instance details Defined in Data.Sequence.Internal Methods traverse :: Applicative f => (a -> f b) -> Digit a -> f (Digit b) Source # sequenceA :: Applicative f => Digit (f a) -> f (Digit a) Source # mapM :: Monad m => (a -> m b) -> Digit a -> m (Digit b) Source # sequence :: Monad m => Digit (m a) -> m (Digit a) Source #
Traversable Node |
Instance details Defined in Data.Sequence.Internal Methods traverse :: Applicative f => (a -> f b) -> Node a -> f (Node b) Source # sequenceA :: Applicative f => Node (f a) -> f (Node a) Source # mapM :: Monad m => (a -> m b) -> Node a -> m (Node b) Source # sequence :: Monad m => Node (m a) -> m (Node a) Source #
Traversable Elem |
Instance details Defined in Data.Sequence.Internal Methods traverse :: Applicative f => (a -> f b) -> Elem a -> f (Elem b) Source # sequenceA :: Applicative f => Elem (f a) -> f (Elem a) Source # mapM :: Monad m => (a -> m b) -> Elem a -> m (Elem b) Source # sequence :: Monad m => Elem (m a) -> m (Elem a) Source #
Traversable ViewL |
Instance details Defined in Data.Sequence.Internal Methods traverse :: Applicative f => (a -> f b) -> ViewL a -> f (ViewL b) Source # sequenceA :: Applicative f => ViewL (f a) -> f (ViewL a) Source # mapM :: Monad m => (a -> m b) -> ViewL a -> m (ViewL b) Source # sequence :: Monad m => ViewL (m a) -> m (ViewL a) Source #
Traversable ViewR |
Instance details Defined in Data.Sequence.Internal Methods traverse :: Applicative f => (a -> f b) -> ViewR a -> f (ViewR b) Source # sequenceA :: Applicative f => ViewR (f a) -> f (ViewR a) Source # mapM :: Monad m => (a -> m b) -> ViewR a -> m (ViewR b) Source # sequence :: Monad m => ViewR (m a) -> m (ViewR a) Source #
Traversable Vector |
Instance details Defined in Data.Vector Methods traverse :: Applicative f => (a -> f b) -> Vector a -> f (Vector b) Source # sequenceA :: Applicative f => Vector (f a) -> f (Vector a) Source # mapM :: Monad m => (a -> m b) -> Vector a -> m (Vector b) Source # sequence :: Monad m => Vector (m a) -> m (Vector a) Source #
Traversable Array |
Instance details Defined in Data.Primitive.Array Methods traverse :: Applicative f => (a -> f b) -> Array a -> f (Array b) Source # sequenceA :: Applicative f => Array (f a) -> f (Array a) Source # mapM :: Monad m => (a -> m b) -> Array a -> m (Array b) Source # sequence :: Monad m => Array (m a) -> m (Array a) Source #
Traversable SmallArray |
Instance details Defined in Data.Primitive.SmallArray Methods traverse :: Applicative f => (a -> f b) -> SmallArray a -> f (SmallArray b) Source # sequenceA :: Applicative f => SmallArray (f a) -> f (SmallArray a) Source # mapM :: Monad m => (a -> m b) -> SmallArray a -> m (SmallArray b) Source # sequence :: Monad m => SmallArray (m a) -> m (SmallArray a) Source #
Traversable Deque Source # |
Instance details Defined in Control.Lens.Internal.Deque Methods traverse :: Applicative f => (a -> f b) -> Deque a -> f (Deque b) Source # sequenceA :: Applicative f => Deque (f a) -> f (Deque a) Source # mapM :: Monad m => (a -> m b) -> Deque a -> m (Deque b) Source # sequence :: Monad m => Deque (m a) -> m (Deque a) Source #
Traversable (Either a) | Since: base-4.7.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a0 -> f b) -> Either a a0 -> f (Either a b) Source # sequenceA :: Applicative f => Either a (f a0) -> f (Either a a0) Source # mapM :: Monad m => (a0 -> m b) -> Either a a0 -> m (Either a b) Source # sequence :: Monad m => Either a (m a0) -> m (Either a a0) Source #
Traversable (V1 :: Type -> Type) | Since: base-4.9.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> V1 a -> f (V1 b) Source # sequenceA :: Applicative f => V1 (f a) -> f (V1 a) Source # mapM :: Monad m => (a -> m b) -> V1 a -> m (V1 b) Source # sequence :: Monad m => V1 (m a) -> m (V1 a) Source #
Traversable (U1 :: Type -> Type) | Since: base-4.9.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> U1 a -> f (U1 b) Source # sequenceA :: Applicative f => U1 (f a) -> f (U1 a) Source # mapM :: Monad m => (a -> m b) -> U1 a -> m (U1 b) Source # sequence :: Monad m => U1 (m a) -> m (U1 a) Source #
Traversable ((,) a) | Since: base-4.7.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a0 -> f b) -> (a, a0) -> f (a, b) Source # sequenceA :: Applicative f => (a, f a0) -> f (a, a0) Source # mapM :: Monad m => (a0 -> m b) -> (a, a0) -> m (a, b) Source # sequence :: Monad m => (a, m a0) -> m (a, a0) Source #
Ix i => Traversable (Array i) | Since: base-2.1
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> Array i a -> f (Array i b) Source # sequenceA :: Applicative f => Array i (f a) -> f (Array i a) Source # mapM :: Monad m => (a -> m b) -> Array i a -> m (Array i b) Source # sequence :: Monad m => Array i (m a) -> m (Array i a) Source #
Traversable (Arg a) | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup Methods traverse :: Applicative f => (a0 -> f b) -> Arg a a0 -> f (Arg a b) Source # sequenceA :: Applicative f => Arg a (f a0) -> f (Arg a a0) Source # mapM :: Monad m => (a0 -> m b) -> Arg a a0 -> m (Arg a b) Source # sequence :: Monad m => Arg a (m a0) -> m (Arg a a0) Source #
Traversable (Proxy :: Type -> Type) | Since: base-4.7.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> Proxy a -> f (Proxy b) Source # sequenceA :: Applicative f => Proxy (f a) -> f (Proxy a) Source # mapM :: Monad m => (a -> m b) -> Proxy a -> m (Proxy b) Source # sequence :: Monad m => Proxy (m a) -> m (Proxy a) Source #
Traversable (Map k) |
Instance details Defined in Data.Map.Internal Methods traverse :: Applicative f => (a -> f b) -> Map k a -> f (Map k b) Source # sequenceA :: Applicative f => Map k (f a) -> f (Map k a) Source # mapM :: Monad m => (a -> m b) -> Map k a -> m (Map k b) Source # sequence :: Monad m => Map k (m a) -> m (Map k a) Source #
Traversable f => Traversable (MaybeT f) |
Instance details Defined in Control.Monad.Trans.Maybe Methods traverse :: Applicative f0 => (a -> f0 b) -> MaybeT f a -> f0 (MaybeT f b) Source # sequenceA :: Applicative f0 => MaybeT f (f0 a) -> f0 (MaybeT f a) Source # mapM :: Monad m => (a -> m b) -> MaybeT f a -> m (MaybeT f b) Source # sequence :: Monad m => MaybeT f (m a) -> m (MaybeT f a) Source #
(Monad m, Traversable m) => Traversable (CatchT m) |
Instance details Defined in Control.Monad.Catch.Pure Methods traverse :: Applicative f => (a -> f b) -> CatchT m a -> f (CatchT m b) Source # sequenceA :: Applicative f => CatchT m (f a) -> f (CatchT m a) Source # mapM :: Monad m0 => (a -> m0 b) -> CatchT m a -> m0 (CatchT m b) Source # sequence :: Monad m0 => CatchT m (m0 a) -> m0 (CatchT m a) Source #
Traversable f => Traversable (Cofree f) |
Instance details Defined in Control.Comonad.Cofree Methods traverse :: Applicative f0 => (a -> f0 b) -> Cofree f a -> f0 (Cofree f b) Source # sequenceA :: Applicative f0 => Cofree f (f0 a) -> f0 (Cofree f a) Source # mapM :: Monad m => (a -> m b) -> Cofree f a -> m (Cofree f b) Source # sequence :: Monad m => Cofree f (m a) -> m (Cofree f a) Source #
Traversable w => Traversable (CoiterT w) |
Instance details Defined in Control.Comonad.Trans.Coiter Methods traverse :: Applicative f => (a -> f b) -> CoiterT w a -> f (CoiterT w b) Source # sequenceA :: Applicative f => CoiterT w (f a) -> f (CoiterT w a) Source # mapM :: Monad m => (a -> m b) -> CoiterT w a -> m (CoiterT w b) Source # sequence :: Monad m => CoiterT w (m a) -> m (CoiterT w a) Source #
Traversable f => Traversable (F f) |
Instance details Defined in Control.Monad.Free.Church Methods traverse :: Applicative f0 => (a -> f0 b) -> F f a -> f0 (F f b) Source # sequenceA :: Applicative f0 => F f (f0 a) -> f0 (F f a) Source # mapM :: Monad m => (a -> m b) -> F f a -> m (F f b) Source # sequence :: Monad m => F f (m a) -> m (F f a) Source #
Traversable f => Traversable (Free f) |
Instance details Defined in Control.Monad.Free Methods traverse :: Applicative f0 => (a -> f0 b) -> Free f a -> f0 (Free f b) Source # sequenceA :: Applicative f0 => Free f (f0 a) -> f0 (Free f a) Source # mapM :: Monad m => (a -> m b) -> Free f a -> m (Free f b) Source # sequence :: Monad m => Free f (m a) -> m (Free f a) Source #
(Monad m, Traversable m) => Traversable (IterT m) |
Instance details Defined in Control.Monad.Trans.Iter Methods traverse :: Applicative f => (a -> f b) -> IterT m a -> f (IterT m b) Source # sequenceA :: Applicative f => IterT m (f a) -> f (IterT m a) Source # mapM :: Monad m0 => (a -> m0 b) -> IterT m a -> m0 (IterT m b) Source # sequence :: Monad m0 => IterT m (m0 a) -> m0 (IterT m a) Source #
Traversable f => Traversable (Yoneda f) |
Instance details Defined in Data.Functor.Yoneda Methods traverse :: Applicative f0 => (a -> f0 b) -> Yoneda f a -> f0 (Yoneda f b) Source # sequenceA :: Applicative f0 => Yoneda f (f0 a) -> f0 (Yoneda f a) Source # mapM :: Monad m => (a -> m b) -> Yoneda f a -> m (Yoneda f b) Source # sequence :: Monad m => Yoneda f (m a) -> m (Yoneda f a) Source #
Traversable f => Traversable (ListT f) |
Instance details Defined in Control.Monad.Trans.List Methods traverse :: Applicative f0 => (a -> f0 b) -> ListT f a -> f0 (ListT f b) Source # sequenceA :: Applicative f0 => ListT f (f0 a) -> f0 (ListT f a) Source # mapM :: Monad m => (a -> m b) -> ListT f a -> m (ListT f b) Source # sequence :: Monad m => ListT f (m a) -> m (ListT f a) Source #
Traversable (HashMap k) |
Instance details Defined in Data.HashMap.Base Methods traverse :: Applicative f => (a -> f b) -> HashMap k a -> f (HashMap k b) Source # sequenceA :: Applicative f => HashMap k (f a) -> f (HashMap k a) Source # mapM :: Monad m => (a -> m b) -> HashMap k a -> m (HashMap k b) Source # sequence :: Monad m => HashMap k (m a) -> m (HashMap k a) Source #
Traversable f => Traversable (Lift f) |
Instance details Defined in Control.Applicative.Lift Methods traverse :: Applicative f0 => (a -> f0 b) -> Lift f a -> f0 (Lift f b) Source # sequenceA :: Applicative f0 => Lift f (f0 a) -> f0 (Lift f a) Source # mapM :: Monad m => (a -> m b) -> Lift f a -> m (Lift f b) Source # sequence :: Monad m => Lift f (m a) -> m (Lift f a) Source #
Traversable (Level i) Source # |
Instance details Defined in Control.Lens.Internal.Level Methods traverse :: Applicative f => (a -> f b) -> Level i a -> f (Level i b) Source # sequenceA :: Applicative f => Level i (f a) -> f (Level i a) Source # mapM :: Monad m => (a -> m b) -> Level i a -> m (Level i b) Source # sequence :: Monad m => Level i (m a) -> m (Level i a) Source #
Traversable f => Traversable (Rec1 f) | Since: base-4.9.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f0 => (a -> f0 b) -> Rec1 f a -> f0 (Rec1 f b) Source # sequenceA :: Applicative f0 => Rec1 f (f0 a) -> f0 (Rec1 f a) Source # mapM :: Monad m => (a -> m b) -> Rec1 f a -> m (Rec1 f b) Source # sequence :: Monad m => Rec1 f (m a) -> m (Rec1 f a) Source #
Traversable (URec Char :: Type -> Type) | Since: base-4.9.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> URec Char a -> f (URec Char b) Source # sequenceA :: Applicative f => URec Char (f a) -> f (URec Char a) Source # mapM :: Monad m => (a -> m b) -> URec Char a -> m (URec Char b) Source # sequence :: Monad m => URec Char (m a) -> m (URec Char a) Source #
Traversable (URec Double :: Type -> Type) | Since: base-4.9.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> URec Double a -> f (URec Double b) Source # sequenceA :: Applicative f => URec Double (f a) -> f (URec Double a) Source # mapM :: Monad m => (a -> m b) -> URec Double a -> m (URec Double b) Source # sequence :: Monad m => URec Double (m a) -> m (URec Double a) Source #
Traversable (URec Float :: Type -> Type) | Since: base-4.9.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> URec Float a -> f (URec Float b) Source # sequenceA :: Applicative f => URec Float (f a) -> f (URec Float a) Source # mapM :: Monad m => (a -> m b) -> URec Float a -> m (URec Float b) Source # sequence :: Monad m => URec Float (m a) -> m (URec Float a) Source #
Traversable (URec Int :: Type -> Type) | Since: base-4.9.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> URec Int a -> f (URec Int b) Source # sequenceA :: Applicative f => URec Int (f a) -> f (URec Int a) Source # mapM :: Monad m => (a -> m b) -> URec Int a -> m (URec Int b) Source # sequence :: Monad m => URec Int (m a) -> m (URec Int a) Source #
Traversable (URec Word :: Type -> Type) | Since: base-4.9.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> URec Word a -> f (URec Word b) Source # sequenceA :: Applicative f => URec Word (f a) -> f (URec Word a) Source # mapM :: Monad m => (a -> m b) -> URec Word a -> m (URec Word b) Source # sequence :: Monad m => URec Word (m a) -> m (URec Word a) Source #
Traversable (URec (Ptr ()) :: Type -> Type) | Since: base-4.9.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> URec (Ptr ()) a -> f (URec (Ptr ()) b) Source # sequenceA :: Applicative f => URec (Ptr ()) (f a) -> f (URec (Ptr ()) a) Source # mapM :: Monad m => (a -> m b) -> URec (Ptr ()) a -> m (URec (Ptr ()) b) Source # sequence :: Monad m => URec (Ptr ()) (m a) -> m (URec (Ptr ()) a) Source #
Traversable (Const m :: Type -> Type) | Since: base-4.7.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> Const m a -> f (Const m b) Source # sequenceA :: Applicative f => Const m (f a) -> f (Const m a) Source # mapM :: Monad m0 => (a -> m0 b) -> Const m a -> m0 (Const m b) Source # sequence :: Monad m0 => Const m (m0 a) -> m0 (Const m a) Source #
Traversable f => Traversable (Ap f) | Since: base-4.12.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f0 => (a -> f0 b) -> Ap f a -> f0 (Ap f b) Source # sequenceA :: Applicative f0 => Ap f (f0 a) -> f0 (Ap f a) Source # mapM :: Monad m => (a -> m b) -> Ap f a -> m (Ap f b) Source # sequence :: Monad m => Ap f (m a) -> m (Ap f a) Source #
Traversable f => Traversable (Alt f) | Since: base-4.12.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f0 => (a -> f0 b) -> Alt f a -> f0 (Alt f b) Source # sequenceA :: Applicative f0 => Alt f (f0 a) -> f0 (Alt f a) Source # mapM :: Monad m => (a -> m b) -> Alt f a -> m (Alt f b) Source # sequence :: Monad m => Alt f (m a) -> m (Alt f a) Source #
Bitraversable p => Traversable (Join p) |
Instance details Defined in Data.Bifunctor.Join Methods traverse :: Applicative f => (a -> f b) -> Join p a -> f (Join p b) Source # sequenceA :: Applicative f => Join p (f a) -> f (Join p a) Source # mapM :: Monad m => (a -> m b) -> Join p a -> m (Join p b) Source # sequence :: Monad m => Join p (m a) -> m (Join p a) Source #
Bitraversable p => Traversable (Fix p) |
Instance details Defined in Data.Bifunctor.Fix Methods traverse :: Applicative f => (a -> f b) -> Fix p a -> f (Fix p b) Source # sequenceA :: Applicative f => Fix p (f a) -> f (Fix p a) Source # mapM :: Monad m => (a -> m b) -> Fix p a -> m (Fix p b) Source # sequence :: Monad m => Fix p (m a) -> m (Fix p a) Source #
Traversable w => Traversable (EnvT e w) |
Instance details Defined in Control.Comonad.Trans.Env Methods traverse :: Applicative f => (a -> f b) -> EnvT e w a -> f (EnvT e w b) Source # sequenceA :: Applicative f => EnvT e w (f a) -> f (EnvT e w a) Source # mapM :: Monad m => (a -> m b) -> EnvT e w a -> m (EnvT e w b) Source # sequence :: Monad m => EnvT e w (m a) -> m (EnvT e w a) Source #
Traversable f => Traversable (IdentityT f) |
Instance details Defined in Control.Monad.Trans.Identity Methods traverse :: Applicative f0 => (a -> f0 b) -> IdentityT f a -> f0 (IdentityT f b) Source # sequenceA :: Applicative f0 => IdentityT f (f0 a) -> f0 (IdentityT f a) Source # mapM :: Monad m => (a -> m b) -> IdentityT f a -> m (IdentityT f b) Source # sequence :: Monad m => IdentityT f (m a) -> m (IdentityT f a) Source #
Traversable f => Traversable (ExceptT e f) |
Instance details Defined in Control.Monad.Trans.Except Methods traverse :: Applicative f0 => (a -> f0 b) -> ExceptT e f a -> f0 (ExceptT e f b) Source # sequenceA :: Applicative f0 => ExceptT e f (f0 a) -> f0 (ExceptT e f a) Source # mapM :: Monad m => (a -> m b) -> ExceptT e f a -> m (ExceptT e f b) Source # sequence :: Monad m => ExceptT e f (m a) -> m (ExceptT e f a) Source #
Traversable f => Traversable (FreeF f a) |
Instance details Defined in Control.Monad.Trans.Free Methods traverse :: Applicative f0 => (a0 -> f0 b) -> FreeF f a a0 -> f0 (FreeF f a b) Source # sequenceA :: Applicative f0 => FreeF f a (f0 a0) -> f0 (FreeF f a a0) Source # mapM :: Monad m => (a0 -> m b) -> FreeF f a a0 -> m (FreeF f a b) Source # sequence :: Monad m => FreeF f a (m a0) -> m (FreeF f a a0) Source #
(Monad m, Traversable m, Traversable f) => Traversable (FreeT f m) |
Instance details Defined in Control.Monad.Trans.Free Methods traverse :: Applicative f0 => (a -> f0 b) -> FreeT f m a -> f0 (FreeT f m b) Source # sequenceA :: Applicative f0 => FreeT f m (f0 a) -> f0 (FreeT f m a) Source # mapM :: Monad m0 => (a -> m0 b) -> FreeT f m a -> m0 (FreeT f m b) Source # sequence :: Monad m0 => FreeT f m (m0 a) -> m0 (FreeT f m a) Source #
Traversable f => Traversable (CofreeF f a) |
Instance details Defined in Control.Comonad.Trans.Cofree Methods traverse :: Applicative f0 => (a0 -> f0 b) -> CofreeF f a a0 -> f0 (CofreeF f a b) Source # sequenceA :: Applicative f0 => CofreeF f a (f0 a0) -> f0 (CofreeF f a a0) Source # mapM :: Monad m => (a0 -> m b) -> CofreeF f a a0 -> m (CofreeF f a b) Source # sequence :: Monad m => CofreeF f a (m a0) -> m (CofreeF f a a0) Source #
(Traversable f, Traversable w) => Traversable (CofreeT f w) |
Instance details Defined in Control.Comonad.Trans.Cofree Methods traverse :: Applicative f0 => (a -> f0 b) -> CofreeT f w a -> f0 (CofreeT f w b) Source # sequenceA :: Applicative f0 => CofreeT f w (f0 a) -> f0 (CofreeT f w a) Source # mapM :: Monad m => (a -> m b) -> CofreeT f w a -> m (CofreeT f w b) Source # sequence :: Monad m => CofreeT f w (m a) -> m (CofreeT f w a) Source #
Traversable f => Traversable (ErrorT e f) |
Instance details Defined in Control.Monad.Trans.Error Methods traverse :: Applicative f0 => (a -> f0 b) -> ErrorT e f a -> f0 (ErrorT e f b) Source # sequenceA :: Applicative f0 => ErrorT e f (f0 a) -> f0 (ErrorT e f a) Source # mapM :: Monad m => (a -> m b) -> ErrorT e f a -> m (ErrorT e f b) Source # sequence :: Monad m => ErrorT e f (m a) -> m (ErrorT e f a) Source #
Traversable f => Traversable (WriterT w f) |
Instance details Defined in Control.Monad.Trans.Writer.Lazy Methods traverse :: Applicative f0 => (a -> f0 b) -> WriterT w f a -> f0 (WriterT w f b) Source # sequenceA :: Applicative f0 => WriterT w f (f0 a) -> f0 (WriterT w f a) Source # mapM :: Monad m => (a -> m b) -> WriterT w f a -> m (WriterT w f b) Source # sequence :: Monad m => WriterT w f (m a) -> m (WriterT w f a) Source #
Traversable f => Traversable (WriterT w f) |
Instance details Defined in Control.Monad.Trans.Writer.Strict Methods traverse :: Applicative f0 => (a -> f0 b) -> WriterT w f a -> f0 (WriterT w f b) Source # sequenceA :: Applicative f0 => WriterT w f (f0 a) -> f0 (WriterT w f a) Source # mapM :: Monad m => (a -> m b) -> WriterT w f a -> m (WriterT w f b) Source # sequence :: Monad m => WriterT w f (m a) -> m (WriterT w f a) Source #
Traversable (Forget r a) |
Instance details Defined in Data.Profunctor.Types Methods traverse :: Applicative f => (a0 -> f b) -> Forget r a a0 -> f (Forget r a b) Source # sequenceA :: Applicative f => Forget r a (f a0) -> f (Forget r a a0) Source # mapM :: Monad m => (a0 -> m b) -> Forget r a a0 -> m (Forget r a b) Source # sequence :: Monad m => Forget r a (m a0) -> m (Forget r a a0) Source #
Traversable (Tagged s) |
Instance details Defined in Data.Tagged Methods traverse :: Applicative f => (a -> f b) -> Tagged s a -> f (Tagged s b) Source # sequenceA :: Applicative f => Tagged s (f a) -> f (Tagged s a) Source # mapM :: Monad m => (a -> m b) -> Tagged s a -> m (Tagged s b) Source # sequence :: Monad m => Tagged s (m a) -> m (Tagged s a) Source #
Traversable f => Traversable (Reverse f) | Traverse from right to left.
Instance details Defined in Data.Functor.Reverse Methods traverse :: Applicative f0 => (a -> f0 b) -> Reverse f a -> f0 (Reverse f b) Source # sequenceA :: Applicative f0 => Reverse f (f0 a) -> f0 (Reverse f a) Source # mapM :: Monad m => (a -> m b) -> Reverse f a -> m (Reverse f b) Source # sequence :: Monad m => Reverse f (m a) -> m (Reverse f a) Source #
Traversable (Constant a :: Type -> Type) |
Instance details Defined in Data.Functor.Constant Methods traverse :: Applicative f => (a0 -> f b) -> Constant a a0 -> f (Constant a b) Source # sequenceA :: Applicative f => Constant a (f a0) -> f (Constant a a0) Source # mapM :: Monad m => (a0 -> m b) -> Constant a a0 -> m (Constant a b) Source # sequence :: Monad m => Constant a (m a0) -> m (Constant a a0) Source #
Traversable f => Traversable (Backwards f) | Derived instance.
Instance details Defined in Control.Applicative.Backwards Methods traverse :: Applicative f0 => (a -> f0 b) -> Backwards f a -> f0 (Backwards f b) Source # sequenceA :: Applicative f0 => Backwards f (f0 a) -> f0 (Backwards f a) Source # mapM :: Monad m => (a -> m b) -> Backwards f a -> m (Backwards f b) Source # sequence :: Monad m => Backwards f (m a) -> m (Backwards f a) Source #
Traversable f => Traversable (AlongsideRight f a) Source # |

Instance details

Defined in Control.Lens.Internal.Getter

Methods

traverse :: Applicative f0 => (a0 -> f0 b) -> AlongsideRight f a a0 -> f0 (AlongsideRight f a b) Source #

sequenceA :: Applicative f0 => AlongsideRight f a (f0 a0) -> f0 (AlongsideRight f a a0) Source #

mapM :: Monad m => (a0 -> m b) -> AlongsideRight f a a0 -> m (AlongsideRight f a b) Source #

sequence :: Monad m => AlongsideRight f a (m a0) -> m (AlongsideRight f a a0) Source #

Traversable f => Traversable (AlongsideLeft f b) Source # |

Instance details

Defined in Control.Lens.Internal.Getter

Methods

traverse :: Applicative f0 => (a -> f0 b0) -> AlongsideLeft f b a -> f0 (AlongsideLeft f b b0) Source #

sequenceA :: Applicative f0 => AlongsideLeft f b (f0 a) -> f0 (AlongsideLeft f b a) Source #

mapM :: Monad m => (a -> m b0) -> AlongsideLeft f b a -> m (AlongsideLeft f b b0) Source #

sequence :: Monad m => AlongsideLeft f b (m a) -> m (AlongsideLeft f b a) Source #

Traversable (K1 i c :: Type -> Type) | Since: base-4.9.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> K1 i c a -> f (K1 i c b) Source # sequenceA :: Applicative f => K1 i c (f a) -> f (K1 i c a) Source # mapM :: Monad m => (a -> m b) -> K1 i c a -> m (K1 i c b) Source # sequence :: Monad m => K1 i c (m a) -> m (K1 i c a) Source #
(Traversable f, Traversable g) => Traversable (f :+: g) | Since: base-4.9.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f0 => (a -> f0 b) -> (f :+: g) a -> f0 ((f :+: g) b) Source # sequenceA :: Applicative f0 => (f :+: g) (f0 a) -> f0 ((f :+: g) a) Source # mapM :: Monad m => (a -> m b) -> (f :+: g) a -> m ((f :+: g) b) Source # sequence :: Monad m => (f :+: g) (m a) -> m ((f :+: g) a) Source #
(Traversable f, Traversable g) => Traversable (f :*: g) | Since: base-4.9.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f0 => (a -> f0 b) -> (f :*: g) a -> f0 ((f :*: g) b) Source # sequenceA :: Applicative f0 => (f :*: g) (f0 a) -> f0 ((f :*: g) a) Source # mapM :: Monad m => (a -> m b) -> (f :*: g) a -> m ((f :*: g) b) Source # sequence :: Monad m => (f :*: g) (m a) -> m ((f :*: g) a) Source #
(Traversable f, Traversable g) => Traversable (Product f g) | Since: base-4.9.0.0
Instance details Defined in Data.Functor.Product Methods traverse :: Applicative f0 => (a -> f0 b) -> Product f g a -> f0 (Product f g b) Source # sequenceA :: Applicative f0 => Product f g (f0 a) -> f0 (Product f g a) Source # mapM :: Monad m => (a -> m b) -> Product f g a -> m (Product f g b) Source # sequence :: Monad m => Product f g (m a) -> m (Product f g a) Source #
(Traversable f, Traversable g) => Traversable (Sum f g) | Since: base-4.9.0.0
Instance details Defined in Data.Functor.Sum Methods traverse :: Applicative f0 => (a -> f0 b) -> Sum f g a -> f0 (Sum f g b) Source # sequenceA :: Applicative f0 => Sum f g (f0 a) -> f0 (Sum f g a) Source # mapM :: Monad m => (a -> m b) -> Sum f g a -> m (Sum f g b) Source # sequence :: Monad m => Sum f g (m a) -> m (Sum f g a) Source #
Traversable (Magma i t b) Source # |
Instance details Defined in Control.Lens.Internal.Magma Methods traverse :: Applicative f => (a -> f b0) -> Magma i t b a -> f (Magma i t b b0) Source # sequenceA :: Applicative f => Magma i t b (f a) -> f (Magma i t b a) Source # mapM :: Monad m => (a -> m b0) -> Magma i t b a -> m (Magma i t b b0) Source # sequence :: Monad m => Magma i t b (m a) -> m (Magma i t b a) Source #
Traversable f => Traversable (M1 i c f) | Since: base-4.9.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f0 => (a -> f0 b) -> M1 i c f a -> f0 (M1 i c f b) Source # sequenceA :: Applicative f0 => M1 i c f (f0 a) -> f0 (M1 i c f a) Source # mapM :: Monad m => (a -> m b) -> M1 i c f a -> m (M1 i c f b) Source # sequence :: Monad m => M1 i c f (m a) -> m (M1 i c f a) Source #
(Traversable f, Traversable g) => Traversable (f :.: g) | Since: base-4.9.0.0
Instance details Defined in Data.Traversable Methods traverse :: Applicative f0 => (a -> f0 b) -> (f :.: g) a -> f0 ((f :.: g) b) Source # sequenceA :: Applicative f0 => (f :.: g) (f0 a) -> f0 ((f :.: g) a) Source # mapM :: Monad m => (a -> m b) -> (f :.: g) a -> m ((f :.: g) b) Source # sequence :: Monad m => (f :.: g) (m a) -> m ((f :.: g) a) Source #
(Traversable f, Traversable g) => Traversable (Compose f g) | Since: base-4.9.0.0
Instance details Defined in Data.Functor.Compose Methods traverse :: Applicative f0 => (a -> f0 b) -> Compose f g a -> f0 (Compose f g b) Source # sequenceA :: Applicative f0 => Compose f g (f0 a) -> f0 (Compose f g a) Source # mapM :: Monad m => (a -> m b) -> Compose f g a -> m (Compose f g b) Source # sequence :: Monad m => Compose f g (m a) -> m (Compose f g a) Source #
Bitraversable p => Traversable (WrappedBifunctor p a) |

Instance details

Defined in Data.Bifunctor.Wrapped

Methods

traverse :: Applicative f => (a0 -> f b) -> WrappedBifunctor p a a0 -> f (WrappedBifunctor p a b) Source #

sequenceA :: Applicative f => WrappedBifunctor p a (f a0) -> f (WrappedBifunctor p a a0) Source #

mapM :: Monad m => (a0 -> m b) -> WrappedBifunctor p a a0 -> m (WrappedBifunctor p a b) Source #

sequence :: Monad m => WrappedBifunctor p a (m a0) -> m (WrappedBifunctor p a a0) Source #

Traversable g => Traversable (Joker g a) |
Instance details Defined in Data.Bifunctor.Joker Methods traverse :: Applicative f => (a0 -> f b) -> Joker g a a0 -> f (Joker g a b) Source # sequenceA :: Applicative f => Joker g a (f a0) -> f (Joker g a a0) Source # mapM :: Monad m => (a0 -> m b) -> Joker g a a0 -> m (Joker g a b) Source # sequence :: Monad m => Joker g a (m a0) -> m (Joker g a a0) Source #
Bitraversable p => Traversable (Flip p a) |
Instance details Defined in Data.Bifunctor.Flip Methods traverse :: Applicative f => (a0 -> f b) -> Flip p a a0 -> f (Flip p a b) Source # sequenceA :: Applicative f => Flip p a (f a0) -> f (Flip p a a0) Source # mapM :: Monad m => (a0 -> m b) -> Flip p a a0 -> m (Flip p a b) Source # sequence :: Monad m => Flip p a (m a0) -> m (Flip p a a0) Source #
Traversable (Clown f a :: Type -> Type) |
Instance details Defined in Data.Bifunctor.Clown Methods traverse :: Applicative f0 => (a0 -> f0 b) -> Clown f a a0 -> f0 (Clown f a b) Source # sequenceA :: Applicative f0 => Clown f a (f0 a0) -> f0 (Clown f a a0) Source # mapM :: Monad m => (a0 -> m b) -> Clown f a a0 -> m (Clown f a b) Source # sequence :: Monad m => Clown f a (m a0) -> m (Clown f a a0) Source #
(Traversable f, Bitraversable p) => Traversable (Tannen f p a) |
Instance details Defined in Data.Bifunctor.Tannen Methods traverse :: Applicative f0 => (a0 -> f0 b) -> Tannen f p a a0 -> f0 (Tannen f p a b) Source # sequenceA :: Applicative f0 => Tannen f p a (f0 a0) -> f0 (Tannen f p a a0) Source # mapM :: Monad m => (a0 -> m b) -> Tannen f p a a0 -> m (Tannen f p a b) Source # sequence :: Monad m => Tannen f p a (m a0) -> m (Tannen f p a a0) Source #
(Bitraversable p, Traversable g) => Traversable (Biff p f g a) |
Instance details Defined in Data.Bifunctor.Biff Methods traverse :: Applicative f0 => (a0 -> f0 b) -> Biff p f g a a0 -> f0 (Biff p f g a b) Source # sequenceA :: Applicative f0 => Biff p f g a (f0 a0) -> f0 (Biff p f g a a0) Source # mapM :: Monad m => (a0 -> m b) -> Biff p f g a a0 -> m (Biff p f g a b) Source # sequence :: Monad m => Biff p f g a (m a0) -> m (Biff p f g a a0) Source #

class (Foldable1 t, Traversable t) => Traversable1 (t :: Type -> Type) where Source #

Minimal complete definition

traverse1 | sequence1

Methods

traverse1 :: Apply f => (a -> f b) -> t a -> f (t b) Source #

Instances

Traversable1 Par1 |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f => (a -> f b) -> Par1 a -> f (Par1 b) Source # sequence1 :: Apply f => Par1 (f b) -> f (Par1 b) Source #
Traversable1 Complex |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f => (a -> f b) -> Complex a -> f (Complex b) Source # sequence1 :: Apply f => Complex (f b) -> f (Complex b) Source #
Traversable1 Min |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f => (a -> f b) -> Min a -> f (Min b) Source # sequence1 :: Apply f => Min (f b) -> f (Min b) Source #
Traversable1 Max |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f => (a -> f b) -> Max a -> f (Max b) Source # sequence1 :: Apply f => Max (f b) -> f (Max b) Source #
Traversable1 First |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f => (a -> f b) -> First a -> f (First b) Source # sequence1 :: Apply f => First (f b) -> f (First b) Source #
Traversable1 Last |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f => (a -> f b) -> Last a -> f (Last b) Source # sequence1 :: Apply f => Last (f b) -> f (Last b) Source #
Traversable1 Identity |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f => (a -> f b) -> Identity a -> f (Identity b) Source # sequence1 :: Apply f => Identity (f b) -> f (Identity b) Source #
Traversable1 Dual |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f => (a -> f b) -> Dual a -> f (Dual b) Source # sequence1 :: Apply f => Dual (f b) -> f (Dual b) Source #
Traversable1 Sum |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f => (a -> f b) -> Sum a -> f (Sum b) Source # sequence1 :: Apply f => Sum (f b) -> f (Sum b) Source #
Traversable1 Product |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f => (a -> f b) -> Product a -> f (Product b) Source # sequence1 :: Apply f => Product (f b) -> f (Product b) Source #
Traversable1 NonEmpty |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f => (a -> f b) -> NonEmpty a -> f (NonEmpty b) Source # sequence1 :: Apply f => NonEmpty (f b) -> f (NonEmpty b) Source #
Traversable1 Tree |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f => (a -> f b) -> Tree a -> f (Tree b) Source # sequence1 :: Apply f => Tree (f b) -> f (Tree b) Source #
Traversable1 (V1 :: Type -> Type) |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f => (a -> f b) -> V1 a -> f (V1 b) Source # sequence1 :: Apply f => V1 (f b) -> f (V1 b) Source #
Traversable1 ((,) a) |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f => (a0 -> f b) -> (a, a0) -> f (a, b) Source # sequence1 :: Apply f => (a, f b) -> f (a, b) Source #
Traversable1 f => Traversable1 (Cofree f) |
Instance details Defined in Control.Comonad.Cofree Methods traverse1 :: Apply f0 => (a -> f0 b) -> Cofree f a -> f0 (Cofree f b) Source # sequence1 :: Apply f0 => Cofree f (f0 b) -> f0 (Cofree f b) Source #
Traversable1 f => Traversable1 (F f) |
Instance details Defined in Control.Monad.Free.Church Methods traverse1 :: Apply f0 => (a -> f0 b) -> F f a -> f0 (F f b) Source # sequence1 :: Apply f0 => F f (f0 b) -> f0 (F f b) Source #
Traversable1 f => Traversable1 (Free f) |
Instance details Defined in Control.Monad.Free Methods traverse1 :: Apply f0 => (a -> f0 b) -> Free f a -> f0 (Free f b) Source # sequence1 :: Apply f0 => Free f (f0 b) -> f0 (Free f b) Source #
(Monad m, Traversable1 m) => Traversable1 (IterT m) |
Instance details Defined in Control.Monad.Trans.Iter Methods traverse1 :: Apply f => (a -> f b) -> IterT m a -> f (IterT m b) Source # sequence1 :: Apply f => IterT m (f b) -> f (IterT m b) Source #
Traversable1 f => Traversable1 (Yoneda f) |
Instance details Defined in Data.Functor.Yoneda Methods traverse1 :: Apply f0 => (a -> f0 b) -> Yoneda f a -> f0 (Yoneda f b) Source # sequence1 :: Apply f0 => Yoneda f (f0 b) -> f0 (Yoneda f b) Source #
Traversable1 f => Traversable1 (Lift f) |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f0 => (a -> f0 b) -> Lift f a -> f0 (Lift f b) Source # sequence1 :: Apply f0 => Lift f (f0 b) -> f0 (Lift f b) Source #
Traversable1 f => Traversable1 (Rec1 f) |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f0 => (a -> f0 b) -> Rec1 f a -> f0 (Rec1 f b) Source # sequence1 :: Apply f0 => Rec1 f (f0 b) -> f0 (Rec1 f b) Source #
Traversable1 f => Traversable1 (Alt f) |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f0 => (a -> f0 b) -> Alt f a -> f0 (Alt f b) Source # sequence1 :: Apply f0 => Alt f (f0 b) -> f0 (Alt f b) Source #
Bitraversable1 p => Traversable1 (Join p) |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f => (a -> f b) -> Join p a -> f (Join p b) Source # sequence1 :: Apply f => Join p (f b) -> f (Join p b) Source #
Traversable1 f => Traversable1 (IdentityT f) |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f0 => (a -> f0 b) -> IdentityT f a -> f0 (IdentityT f b) Source # sequence1 :: Apply f0 => IdentityT f (f0 b) -> f0 (IdentityT f b) Source #
Traversable1 (Tagged a) |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f => (a0 -> f b) -> Tagged a a0 -> f (Tagged a b) Source # sequence1 :: Apply f => Tagged a (f b) -> f (Tagged a b) Source #
Traversable1 f => Traversable1 (Reverse f) |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f0 => (a -> f0 b) -> Reverse f a -> f0 (Reverse f b) Source # sequence1 :: Apply f0 => Reverse f (f0 b) -> f0 (Reverse f b) Source #
Traversable1 f => Traversable1 (Backwards f) |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f0 => (a -> f0 b) -> Backwards f a -> f0 (Backwards f b) Source # sequence1 :: Apply f0 => Backwards f (f0 b) -> f0 (Backwards f b) Source #
Traversable1 f => Traversable1 (AlongsideRight f a) Source # |
Instance details Defined in Control.Lens.Internal.Getter Methods traverse1 :: Apply f0 => (a0 -> f0 b) -> AlongsideRight f a a0 -> f0 (AlongsideRight f a b) Source # sequence1 :: Apply f0 => AlongsideRight f a (f0 b) -> f0 (AlongsideRight f a b) Source #
Traversable1 f => Traversable1 (AlongsideLeft f b) Source # |
Instance details Defined in Control.Lens.Internal.Getter Methods traverse1 :: Apply f0 => (a -> f0 b0) -> AlongsideLeft f b a -> f0 (AlongsideLeft f b b0) Source # sequence1 :: Apply f0 => AlongsideLeft f b (f0 b0) -> f0 (AlongsideLeft f b b0) Source #
(Traversable1 f, Traversable1 g) => Traversable1 (f :+: g) |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f0 => (a -> f0 b) -> (f :+: g) a -> f0 ((f :+: g) b) Source # sequence1 :: Apply f0 => (f :+: g) (f0 b) -> f0 ((f :+: g) b) Source #
(Traversable1 f, Traversable1 g) => Traversable1 (f :*: g) |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f0 => (a -> f0 b) -> (f :*: g) a -> f0 ((f :*: g) b) Source # sequence1 :: Apply f0 => (f :*: g) (f0 b) -> f0 ((f :*: g) b) Source #
(Traversable1 f, Traversable1 g) => Traversable1 (Product f g) |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f0 => (a -> f0 b) -> Product f g a -> f0 (Product f g b) Source # sequence1 :: Apply f0 => Product f g (f0 b) -> f0 (Product f g b) Source #
(Traversable1 f, Traversable1 g) => Traversable1 (Sum f g) |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f0 => (a -> f0 b) -> Sum f g a -> f0 (Sum f g b) Source # sequence1 :: Apply f0 => Sum f g (f0 b) -> f0 (Sum f g b) Source #
Traversable1 f => Traversable1 (M1 i c f) |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f0 => (a -> f0 b) -> M1 i c f a -> f0 (M1 i c f b) Source # sequence1 :: Apply f0 => M1 i c f (f0 b) -> f0 (M1 i c f b) Source #
(Traversable1 f, Traversable1 g) => Traversable1 (f :.: g) |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f0 => (a -> f0 b) -> (f :.: g) a -> f0 ((f :.: g) b) Source # sequence1 :: Apply f0 => (f :.: g) (f0 b) -> f0 ((f :.: g) b) Source #
(Traversable1 f, Traversable1 g) => Traversable1 (Compose f g) |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f0 => (a -> f0 b) -> Compose f g a -> f0 (Compose f g b) Source # sequence1 :: Apply f0 => Compose f g (f0 b) -> f0 (Compose f g b) Source #
Traversable1 g => Traversable1 (Joker g a) |
Instance details Defined in Data.Semigroup.Traversable.Class Methods traverse1 :: Apply f => (a0 -> f b) -> Joker g a a0 -> f (Joker g a b) Source # sequence1 :: Apply f => Joker g a (f b) -> f (Joker g a b) Source #

both :: Bitraversable r => Traversal (r a a) (r b b) a b Source #

Traverse both parts of a `Bitraversable` container with matching types.

Usually that type will be a pair.

    >>> (1,2) & both *~ 10
    (10,20)

    >>> over both length ("hello","world")
    (5,5)

    >>> ("hello","world")^.both
    "helloworld"

    both :: Traversal (a, a)       (b, b)       a b
    both :: Traversal (Either a a) (Either b b) a b

both1 :: Bitraversable1 r => Traversal1 (r a a) (r b b) a b Source #

Traverse both parts of a `Bitraversable1` container with matching types.

Usually that type will be a pair.

    both1 :: Traversal1 (a, a)       (b, b)       a b
    both1 :: Traversal1 (Either a a) (Either b b) a b

beside :: (Representable q, Applicative (Rep q), Applicative f, Bitraversable r) => Optical p q f s t a b -> Optical p q f s' t' a b -> Optical p q f (r s s') (r t t') a b Source #

Apply a different `Traversal` or `Fold` to each side of a `Bitraversable` container.

    beside :: Traversal s t a b                -> Traversal s' t' a b                -> Traversal (r s s') (r t t') a b
    beside :: IndexedTraversal i s t a b       -> IndexedTraversal i s' t' a b       -> IndexedTraversal i (r s s') (r t t') a b
    beside :: IndexPreservingTraversal s t a b -> IndexPreservingTraversal s' t' a b -> IndexPreservingTraversal (r s s') (r t t') a b

    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                        -> Fold (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               -> IndexedFold i (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         -> IndexPreservingFold (s,s') a

    >>> ("hello",["world","!!!"])^..beside id traverse
    ["hello","world","!!!"]

taking :: (Conjoined p, Applicative f) => Int -> Traversing p f s t a a -> Over p f s t a a Source #

Visit the first n targets of a `Traversal`, `Fold`, `Getter` or `Lens`.

    >>> [("hello","world"),("!!!","!!!")]^.. taking 2 (traverse.both)
    ["hello","world"]

    >>> timingOut $ [1..] ^.. taking 3 traverse
    [1,2,3]

    >>> over (taking 5 traverse) succ "hello world"
    "ifmmp world"

    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 -> 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

dropping :: (Conjoined p, Applicative f) => Int -> Over p (Indexing f) s t a a -> Over p f s t a a Source #

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
    Just 2

    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 -> 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

failing :: (Conjoined p, Applicative f) => Traversing p f s t a b -> Over p f s t a b -> Over p f s t a b infixl 5 Source #

Try the first `Traversal` (or `Fold`), falling back on the second `Traversal` (or `Fold`) if it returns no entries.

This is only a valid `Traversal` if the second `Traversal` is disjoint from the result of the first or returns exactly the same results. These conditions are trivially met when given a `Lens`, `Iso`, `Getter`, `Prism` or "affine" Traversal -- one that has 0 or 1 target.

Mutatis mutandis for `Fold`.

    >>> [0,1,2,3] ^? failing (ix 1) (ix 2)
    Just 1

    >>> [0,1,2,3] ^? failing (ix 42) (ix 2)
    Just 2

    failing :: Traversal s t a b -> Traversal s t a b -> Traversal s t a b
    failing :: Prism s t a b     -> Prism s t a b     -> Traversal s t a b
    failing :: Fold s a          -> Fold s a          -> Fold s a

These cases are also supported, trivially, but are boring, because the left hand side always succeeds.

    failing :: Lens s t a b      -> Traversal s t a b -> Traversal s t a b
    failing :: Iso s t a b       -> Traversal s t a b -> Traversal s t a b
    failing :: Equality s t a b  -> Traversal s t a b -> Traversal s t a b
    failing :: Getter s a        -> Fold s a          -> Fold s a

If both of the inputs are indexed, the result is also indexed, so you can apply this to a pair of indexed traversals or indexed folds, obtaining an indexed traversal or indexed fold.

    failing :: IndexedTraversal i s t a b -> IndexedTraversal i s t a b -> IndexedTraversal i s t a b
    failing :: IndexedFold i s a          -> IndexedFold i s a          -> IndexedFold i s a

These cases are also supported, trivially, but are boring, because the left hand side always succeeds.

    failing :: IndexedLens i s t a b      -> IndexedTraversal i s t a b -> IndexedTraversal i s t a b
    failing :: IndexedGetter i s a        -> IndexedGetter i s a        -> IndexedFold i s a

deepOf :: (Conjoined p, Applicative f) => LensLike f s t s t -> Traversing p f s t a b -> Over p f s t a b Source #

Try the second traversal. If it returns no entries, try again with all entries from the first traversal, recursively.

    deepOf :: Fold s s          -> Fold s a                   -> Fold s a
    deepOf :: Traversal' s s    -> Traversal' s a             -> Traversal' s a
    deepOf :: Traversal s t s t -> Traversal s t a b          -> Traversal s t a b
    deepOf :: Fold s s          -> IndexedFold i s a          -> IndexedFold i s a
    deepOf :: Traversal s t s t -> IndexedTraversal i s t a b -> IndexedTraversal i s t a b

# Indexed Traversals

## Common

ignored :: Applicative f => pafb -> s -> f s Source #

This is the trivial empty `Traversal`.

    ignored :: IndexedTraversal i s s a b

    ignored ≡ const pure

    >>> 6 & ignored %~ absurd
    6

class Ord k => TraverseMin k m | m -> k where Source #

Allows `IndexedTraversal` the value at the smallest index.

Methods

traverseMin :: IndexedTraversal' k (m v) v Source #

`IndexedTraversal` of the element with the smallest index.

Instances

TraverseMin Int IntMap Source # |
Instance details Defined in Control.Lens.Traversal Methods traverseMin :: IndexedTraversal' Int (IntMap v) v Source #
Ord k => TraverseMin k (Map k) Source # |
Instance details Defined in Control.Lens.Traversal Methods traverseMin :: IndexedTraversal' k (Map k v) v Source #

class Ord k => TraverseMax k m | m -> k where Source #

Allows `IndexedTraversal` of the value at the largest index.

Methods

traverseMax :: IndexedTraversal' k (m v) v Source #

`IndexedTraversal` of the element at the largest index.

Instances

TraverseMax Int IntMap Source # |
Instance details Defined in Control.Lens.Traversal Methods traverseMax :: IndexedTraversal' Int (IntMap v) v Source #
Ord k => TraverseMax k (Map k) Source # |
Instance details Defined in Control.Lens.Traversal Methods traverseMax :: IndexedTraversal' k (Map k v) v Source #

traversed :: Traversable f => IndexedTraversal Int (f a) (f b) a b Source #

Traverse any `Traversable` container. This is an `IndexedTraversal` that is indexed by ordinal position.

traversed1 :: Traversable1 f => IndexedTraversal1 Int (f a) (f b) a b Source #

Traverse any `Traversable1` container. This is an `IndexedTraversal1` that is indexed by ordinal position.

traversed64 :: Traversable f => IndexedTraversal Int64 (f a) (f b) a b Source #

Traverse any `Traversable` container. This is an `IndexedTraversal` that is indexed by ordinal position.

elementOf :: Applicative f => LensLike (Indexing f) s t a a -> Int -> IndexedLensLike Int f s t a a Source #

Traverse the nth `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

element :: Traversable t => Int -> IndexedTraversal' Int (t a) a Source #

Traverse the nth element of a `Traversable` container.

    element ≡ elementOf traverse

elementsOf :: Applicative f => LensLike (Indexing f) s t a a -> (Int -> Bool) -> IndexedLensLike Int f s t a a Source #

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

elements :: Traversable t => (Int -> Bool) -> IndexedTraversal' Int (t a) a Source #

Traverse elements of a `Traversable` container where their ordinal positions match a predicate.

    elements ≡ elementsOf traverse

## Combinators

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] Source #

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) => Over (Indexed i) (Bazaar' (Indexed i) a) s t a a -> Over p f s t [a] [a] Source #

A type-restricted version of `ipartsOf` that can only be used with an `IndexedTraversal`.

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] Source #

An indexed version of `unsafePartsOf` that receives the entire list of indices as its index.

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] Source #

itraverseOf :: (Indexed i a (f b) -> s -> f t) -> (i -> a -> f b) -> s -> f t Source #

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
    traverseOf l = itraverseOf l . const = id

    itraverseOf :: Functor f     => IndexedLens i s t a b       -> (i -> a -> f b) -> s -> f t
    itraverseOf :: Applicative f => IndexedTraversal i s t a b  -> (i -> a -> f b) -> s -> f t
    itraverseOf :: Apply f       => IndexedTraversal1 i s t a b -> (i -> a -> f b) -> s -> f t

iforOf :: (Indexed i a (f b) -> s -> f t) -> s -> (i -> a -> f b) -> f t Source #

Traverse with an index (and the arguments flipped).

    forOf l a ≡ iforOf l a . const
    iforOf ≡ flip . itraverseOf

    iforOf :: Functor f     => IndexedLens i s t a b       -> s -> (i -> a -> f b) -> f t
    iforOf :: Applicative f => IndexedTraversal i s t a b  -> s -> (i -> a -> f b) -> f t
    iforOf :: Apply f       => IndexedTraversal1 i s t a b -> s -> (i -> a -> f b) -> f t

imapMOf :: Over (Indexed i) (WrappedMonad m) s t a b -> (i -> a -> m b) -> s -> m t Source #

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.

    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 :: Bind  m => IndexedTraversal1 i s t a b -> (i -> a -> m b) -> s -> m t

iforMOf :: (Indexed i a (WrappedMonad m b) -> s -> WrappedMonad m t) -> s -> (i -> a -> m b) -> m t Source #

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).

    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

imapAccumROf :: Over (Indexed i) (Backwards (State acc)) s t a b -> (i -> acc -> a -> (acc, b)) -> acc -> s -> (acc, t) Source #

Generalizes `mapAccumR` to an arbitrary `IndexedTraversal` with access to the index.

`imapAccumROf` accumulates state from right to left.

    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)

imapAccumLOf :: Over (Indexed i) (State acc) s t a b -> (i -> acc -> a -> (acc, b)) -> acc -> s -> (acc, t) Source #

Generalizes `mapAccumL` to an arbitrary `IndexedTraversal` with access to the index.

`imapAccumLOf` accumulates state from left to right.

    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)

# Reflection

traverseBy :: Traversable t => (forall x. x -> f x) -> (forall x y. f (x -> y) -> f x -> f y) -> (a -> f b) -> t a -> f (t b) Source #

Traverse a container using its `Traversable` instance using explicitly provided `Applicative` operations. This is like `traverse` where the `Applicative` instance can be manually specified.

traverseByOf :: Traversal s t a b -> (forall x. x -> f x) -> (forall x y. f (x -> y) -> f x -> f y) -> (a -> f b) -> s -> f t Source #

Traverse a container using a specified `Applicative`.

This is like `traverseBy` where the `Traversable` instance can be specified by any `Traversal`

    traverseByOf traverse ≡ traverseBy

sequenceBy :: Traversable t => (forall x. x -> f x) -> (forall x y. f (x -> y) -> f x -> f y) -> t (f a) -> f (t a) Source #

Sequence a container using its `Traversable` instance using explicitly provided `Applicative` operations. This is like `sequence` where the `Applicative` instance can be manually specified.

sequenceByOf :: Traversal s t (f b) b -> (forall x. x -> f x) -> (forall x y. f (x -> y) -> f x -> f y) -> s -> f t Source #

Sequence a container using a specified `Applicative`.

This is like `traverseBy` where the `Traversable` instance can be specified by any `Traversal`

    sequenceByOf traverse ≡ sequenceBy

# Implementation Details

newtype Bazaar p a b t Source #

This is used to characterize a `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 `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`.

Constructors

Bazaar |

Fields

- runBazaar :: forall f. Applicative f => p a (f b) -> f t

Instances

Corepresentable p => Sellable p (Bazaar p) Source # |
Instance details Defined in Control.Lens.Internal.Bazaar Methods sell :: p a (Bazaar p a b b) Source #
Profunctor p => Bizarre p (Bazaar p) Source # |
Instance details Defined in Control.Lens.Internal.Bazaar Methods bazaar :: Applicative f => p a (f b) -> Bazaar p a b t -> f t Source #
Conjoined p => IndexedComonad (Bazaar p) Source # |
Instance details Defined in Control.Lens.Internal.Bazaar Methods iextract :: Bazaar p a a t -> t Source # iduplicate :: Bazaar p a c t -> Bazaar p a b (Bazaar p b c t) Source # iextend :: (Bazaar p b c t -> r) -> Bazaar p a c t -> Bazaar p a b r Source #
IndexedFunctor (Bazaar p) Source # |
Instance details Defined in Control.Lens.Internal.Bazaar Methods ifmap :: (s -> t) -> Bazaar p a b s -> Bazaar p a b t Source #
Functor (Bazaar p a b) Source # |
Instance details Defined in Control.Lens.Internal.Bazaar Methods fmap :: (a0 -> b0) -> Bazaar p a b a0 -> Bazaar p a b b0 Source # (<$) :: a0 -> Bazaar p a b b0 -> Bazaar p a b a0 Source #
Applicative (Bazaar p a b) Source # |

Instance details

Defined in Control.Lens.Internal.Bazaar

Methods

pure :: a0 -> Bazaar p a b a0 Source #

(<*>) :: Bazaar p a b (a0 -> b0) -> Bazaar p a b a0 -> Bazaar p a b b0 Source #

liftA2 :: (a0 -> b0 -> c) -> Bazaar p a b a0 -> Bazaar p a b b0 -> Bazaar p a b c Source #

(*>) :: Bazaar p a b a0 -> Bazaar p a b b0 -> Bazaar p a b b0 Source #

(<*) :: Bazaar p a b a0 -> Bazaar p a b b0 -> Bazaar p a b a0 Source #

(a ~ b, Conjoined p) => Comonad (Bazaar p a b) Source # |
Instance details Defined in Control.Lens.Internal.Bazaar Methods extract :: Bazaar p a b a0 -> a0 Source # duplicate :: Bazaar p a b a0 -> Bazaar p a b (Bazaar p a b a0) Source # extend :: (Bazaar p a b a0 -> b0) -> Bazaar p a b a0 -> Bazaar p a b b0 Source #
(a ~ b, Conjoined p) => ComonadApply (Bazaar p a b) Source # |
Instance details Defined in Control.Lens.Internal.Bazaar Methods (<@>) :: Bazaar p a b (a0 -> b0) -> Bazaar p a b a0 -> Bazaar p a b b0 Source # (@>) :: Bazaar p a b a0 -> Bazaar p a b b0 -> Bazaar p a b b0 Source # (<@) :: Bazaar p a b a0 -> Bazaar p a b b0 -> Bazaar p a b a0 Source #
Apply (Bazaar p a b) Source # |
Instance details Defined in Control.Lens.Internal.Bazaar Methods (<.>) :: Bazaar p a b (a0 -> b0) -> Bazaar p a b a0 -> Bazaar p a b b0 Source # (.>) :: Bazaar p a b a0 -> Bazaar p a b b0 -> Bazaar p a b b0 Source # (<.) :: Bazaar p a b a0 -> Bazaar p a b b0 -> Bazaar p a b a0 Source # liftF2 :: (a0 -> b0 -> c) -> Bazaar p a b a0 -> Bazaar p a b b0 -> Bazaar p a b c Source #

type Bazaar' p a = Bazaar p a a Source #

This alias is helpful when it comes to reducing repetition in type signatures.

    type Bazaar' p a t = Bazaar p a a t

newtype Bazaar1 p a b t Source #

This is used to characterize a `Traversal`.

a.k.a. indexed Cartesian store comonad, indexed Kleene store comonad, or an indexed `FunList`.

http://twanvl.nl/blog/haskell/non-regular1

A `Bazaar1` is like a `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 ``Bazaar1` a b t` holds `N` `a`s and a function from `N` `b`s to `t`, (where `N` might be infinite).

Mnemonically, a `Bazaar1` holds many stores and you can easily add more.

This is a final encoding of `Bazaar1`.

Constructors

Bazaar1 |

Fields

- runBazaar1 :: forall f. Apply f => p a (f b) -> f t

Instances

Corepresentable p => Sellable p (Bazaar1 p) Source # |
Instance details Defined in Control.Lens.Internal.Bazaar Methods sell :: p a (Bazaar1 p a b b) Source #
Profunctor p => Bizarre1 p (Bazaar1 p) Source # |
Instance details Defined in Control.Lens.Internal.Bazaar Methods bazaar1 :: Apply f => p a (f b) -> Bazaar1 p a b t -> f t Source #
Conjoined p => IndexedComonad (Bazaar1 p) Source # |
Instance details Defined in Control.Lens.Internal.Bazaar Methods iextract :: Bazaar1 p a a t -> t Source # iduplicate :: Bazaar1 p a c t -> Bazaar1 p a b (Bazaar1 p b c t) Source # iextend :: (Bazaar1 p b c t -> r) -> Bazaar1 p a c t -> Bazaar1 p a b r Source #
IndexedFunctor (Bazaar1 p) Source # |
Instance details Defined in Control.Lens.Internal.Bazaar Methods ifmap :: (s -> t) -> Bazaar1 p a b s -> Bazaar1 p a b t Source #
Functor (Bazaar1 p a b) Source # |
Instance details Defined in Control.Lens.Internal.Bazaar Methods fmap :: (a0 -> b0) -> Bazaar1 p a b a0 -> Bazaar1 p a b b0 Source # (<$) :: a0 -> Bazaar1 p a b b0 -> Bazaar1 p a b a0 Source #
(a ~ b, Conjoined p) => Comonad (Bazaar1 p a b) Source # |
Instance details Defined in Control.Lens.Internal.Bazaar Methods extract :: Bazaar1 p a b a0 -> a0 Source # duplicate :: Bazaar1 p a b a0 -> Bazaar1 p a b (Bazaar1 p a b a0) Source # extend :: (Bazaar1 p a b a0 -> b0) -> Bazaar1 p a b a0 -> Bazaar1 p a b b0 Source #
(a ~ b, Conjoined p) => ComonadApply (Bazaar1 p a b) Source # |
Instance details Defined in Control.Lens.Internal.Bazaar Methods (<@>) :: Bazaar1 p a b (a0 -> b0) -> Bazaar1 p a b a0 -> Bazaar1 p a b b0 Source # (@>) :: Bazaar1 p a b a0 -> Bazaar1 p a b b0 -> Bazaar1 p a b b0 Source # (<@) :: Bazaar1 p a b a0 -> Bazaar1 p a b b0 -> Bazaar1 p a b a0 Source #
Apply (Bazaar1 p a b) Source # |
Instance details Defined in Control.Lens.Internal.Bazaar Methods (<.>) :: Bazaar1 p a b (a0 -> b0) -> Bazaar1 p a b a0 -> Bazaar1 p a b b0 Source # (.>) :: Bazaar1 p a b a0 -> Bazaar1 p a b b0 -> Bazaar1 p a b b0 Source # (<.) :: Bazaar1 p a b a0 -> Bazaar1 p a b b0 -> Bazaar1 p a b a0 Source # liftF2 :: (a0 -> b0 -> c) -> Bazaar1 p a b a0 -> Bazaar1 p a b b0 -> Bazaar1 p a b c Source #

type Bazaar1' p a = Bazaar1 p a a Source #

This alias is helpful when it comes to reducing repetition in type signatures.

    type Bazaar1' p a t = Bazaar1 p a a t

loci :: Traversal (Bazaar (->) a c s) (Bazaar (->) b c s) a b Source #

This `Traversal` allows you to `traverse` the individual stores in a `Bazaar`.

iloci :: IndexedTraversal i (Bazaar (Indexed i) a c s) (Bazaar (Indexed i) b c s) a b Source #

This `IndexedTraversal` allows you to `traverse` the individual stores in a `Bazaar` with access to their indices.

# Fusion

confusing :: Applicative f => LensLike (Curried (Yoneda f) (Yoneda f)) s t a b -> LensLike f s t a b Source #

Fuse a `Traversal` by reassociating all of the `(`<*>`)` operations to the left and fusing all of the `fmap` calls into one. This is particularly useful when constructing a `Traversal` using operations from GHC.Generics.

Given a pair of `Traversal`s `foo` and `bar`,

    confusing (foo.bar) = foo.bar

However, `foo` and `bar` are each going to use the `Applicative` they are given.

`confusing` exploits the `Yoneda` lemma to merge their separate uses of `fmap` into a single `fmap`. and it further exploits an interesting property of the right Kan lift (or `Curried`) to left associate all of the uses of `(`<*>`)` to make it possible to fuse together more fmaps.

This is particularly effective when the choice of functor `f` is unknown at compile time or when the `Traversal` `foo.bar` in the above description is recursive or complex enough to prevent inlining.

`fusing` is a version of this combinator suitable for fusing lenses.

    confusing :: Traversal s t a b -> Traversal s t a b