lens-family-1.0.1: Lens Families

Lens.Family2.Stock

Description

This module contains lenses and traversals for common structures in Haskell. It also contains the combinators for lenses and traversals.

Synopsis

# Lens Combinators

choosing :: Functor f => LensLike f a a' c c' -> LensLike f b b' c c' -> LensLike f (Either a b) (Either a' b') c c'

``` choosing :: Lens a a' c c' -> Lens b b' c c' -> Lens (Either a b) (Either a' b') c c'
```
``` choosing :: Traversal a a' c c' -> Traversal b b' c c' -> Traversal (Either a b) (Either a' b') c c'
```
``` choosing :: Getter a a' c c' -> Getter b b' c c' -> Getter (Either a b) (Either a' b') c c'
```
``` choosing :: Fold a a' c c' -> Fold b b' c c' -> Fold (Either a b) (Either a' b') c c'
```
``` choosing :: Setter a a' c c' -> Setter b b' c c' -> Setter (Either a b) (Either a' b') c c'
```

Given two lens/traversal/getter/fold/setter families with the same substructure, make a new lens/traversal/getter/fold/setter on `Either`.

alongside :: Functor f => LensLike (AlongsideLeft f b2') a1 a1' b1 b1' -> LensLike (AlongsideRight f a1') a2 a2' b2 b2' -> LensLike f (a1, a2) (a1', a2') (b1, b2) (b1', b2')

``` alongside :: Lens a1 a1' b1 b1' -> Lens a2 a2' b2 b2' -> Lens (a1, a2) (a1', a2') (b1, b2) (b1', b2')
```
``` alongside :: Getter a1 a1' b1 b1' -> Getter a2 a2' b2 b2' -> Getter (a1, a2) (a1', a2') (b1, b2) (b1', b2')
```

Given two lens/getter families, make a new lens/getter on their product.

beside :: Applicative f => LensLike f a a' c c' -> LensLike f b b' c c' -> LensLike f (a, b) (a', b') c c'

``` beside :: Traversal a a' c c' -> Traversal b' b' c c' -> Traversal (a,b) (a',b') c c'
```
``` beside :: Fold a a' c c' -> Fold b' b' c c' -> Fold (a,b) (a',b') c c'
```
``` beside :: Setter a a' c c' -> Setter b' b' c c' -> Setter (a,b) (a',b') c c'
```

Given two traversals/folds/setters referencing a type `c`, create a traversal/fold/setter on the pair referencing `c`.

# Stock Lenses

_1 :: Lens (a, b) (a', b) a a'Source

Lens on the first element of a pair.

_2 :: Lens (a, b) (a, b') b b'Source

Lens on the second element of a pair.

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

Traversals on both elements of a pair `(a,a)`.

chosen :: Lens (Either a a) (Either b b) a bSource

Lens on the Left or Right element of an (`Either` a a).

ix :: Eq k => k -> Lens' (k -> v) vSource

Lens on a given point of a function.

at :: Ord k => k -> Lens' (Map k v) (Maybe v)Source

Lens on a given point of a `Map`.

intAt :: Int -> Lens' (IntMap v) (Maybe v)Source

Lens on a given point of a `IntMap`.

contains :: Ord k => k -> Lens' (Set k) BoolSource

Lens on a given point of a `Set`.

Lens on a given point of a `IntSet`.

# Stock Traversals

_Left :: Traversal (Either a b) (Either a' b) a a'Source

Traversal on the `Left` element of an `Either`.

_Right :: Traversal (Either a b) (Either a b') b b'Source

Traversal on the `Right` element of an `Either`.

_Just :: Traversal (Maybe a) (Maybe a') a a'Source

Traversal on the `Just` element of a `Maybe`.

_Nothing :: Traversal' (Maybe a) ()Source

Traversal on the `Nothing` element of a `Maybe`.

ignored :: Traversal a a b b'Source

The empty traveral on any type.

# Types

data AlongsideLeft f b a

Instances

 Functor f => Functor (AlongsideLeft f a) Phantom f => Phantom (AlongsideLeft f a)

data AlongsideRight f a b

Instances

 Functor f => Functor (AlongsideRight f a) Phantom f => Phantom (AlongsideRight f a)

# Re-exports

type Lens a a' b b' = forall f. Functor f => LensLike f a a' b b'Source

type Lens' a b = Lens a a b bSource

type Traversal a a' b b' = forall f. Applicative f => LensLike f a a' b b'Source

type Traversal' a b = Traversal a a b bSource

type LensLike f a a' b b' = (b -> f b') -> a -> f a'

type LensLike' f a b = (b -> f b) -> a -> f a

class Functor f => Applicative f

A functor with application, providing operations to

• embed pure expressions (`pure`), and
• sequence computations and combine their results (`<*>`).

A minimal complete definition must include implementations of these functions satisfying the following laws:

identity
`pure id <*> v = v`
composition
`pure (.) <*> u <*> v <*> w = u <*> (v <*> w)`
homomorphism
`pure f <*> pure x = pure (f x)`
interchange
`u <*> pure y = pure (\$ y) <*> u`

The other methods have the following default definitions, which may be overridden with equivalent specialized implementations:

```      u `*>` v = `pure` (`const` `id`) `<*>` u `<*>` v
u `<*` v = `pure` `const` `<*>` u `<*>` v
```

As a consequence of these laws, the `Functor` instance for `f` will satisfy

```      `fmap` f x = `pure` f `<*>` x
```

If `f` is also a `Monad`, it should satisfy `pure = return` and `(<*>) = ap` (which implies that `pure` and `<*>` satisfy the applicative functor laws).

Instances

 Applicative [] Applicative IO Applicative ZipList Applicative STM Applicative ReadPrec Applicative ReadP Applicative Maybe Applicative Setting Applicative Identity Applicative ((->) a) Applicative (Either e) Monoid a => Applicative ((,) a) Applicative (ST s) Monoid m => Applicative (Const m) Monad m => Applicative (WrappedMonad m) Applicative (ST s) Arrow a => Applicative (ArrowMonad a) Monoid c => Applicative (Getting c) Applicative f => Applicative (Backwards f) Apply `f`-actions in the reverse order. Applicative m => Applicative (ListT m) (Functor m, Monad m) => Applicative (MaybeT m) Applicative m => Applicative (IdentityT m) Arrow a => Applicative (WrappedArrow a b) (Monoid c, Monad m) => Applicative (Zooming m c) (Functor m, Monad m) => Applicative (StateT s m) (Functor m, Monad m) => Applicative (StateT s m) Applicative (ContT r m) (Functor m, Monad m) => Applicative (ErrorT e m) Applicative m => Applicative (ReaderT r m) (Monoid w, Applicative m) => Applicative (WriterT w m) (Monoid w, Applicative m) => Applicative (WriterT w m) (Monoid w, Functor m, Monad m) => Applicative (RWST r w s m) (Monoid w, Functor m, Monad m) => Applicative (RWST r w s m)