Control.Lens.Tuple

lens-4.13.2.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 | None
Language | Haskell98

Control.Lens.Tuple

Contents

- Tuples
- Strict variations

Description

Synopsis

- class Field1 s t a b | s -> a, t -> b, s b -> t, t a -> s where
  - _1 :: Lens s t a b
- class Field2 s t a b | s -> a, t -> b, s b -> t, t a -> s where
  - _2 :: Lens s t a b
- class Field3 s t a b | s -> a, t -> b, s b -> t, t a -> s where
  - _3 :: Lens s t a b
- class Field4 s t a b | s -> a, t -> b, s b -> t, t a -> s where
  - _4 :: Lens s t a b
- class Field5 s t a b | s -> a, t -> b, s b -> t, t a -> s where
  - _5 :: Lens s t a b
- class Field6 s t a b | s -> a, t -> b, s b -> t, t a -> s where
  - _6 :: Lens s t a b
- class Field7 s t a b | s -> a, t -> b, s b -> t, t a -> s where
  - _7 :: Lens s t a b
- class Field8 s t a b | s -> a, t -> b, s b -> t, t a -> s where
  - _8 :: Lens s t a b
- class Field9 s t a b | s -> a, t -> b, s b -> t, t a -> s where
  - _9 :: Lens s t a b
- _1' :: Field1 s t a b => Lens s t a b
- _2' :: Field2 s t a b => Lens s t a b
- _3' :: Field3 s t a b => Lens s t a b
- _4' :: Field4 s t a b => Lens s t a b
- _5' :: Field5 s t a b => Lens s t a b
- _6' :: Field6 s t a b => Lens s t a b
- _7' :: Field7 s t a b => Lens s t a b
- _8' :: Field8 s t a b => Lens s t a b
- _9' :: Field9 s t a b => Lens s t a b

# Tuples

class Field1 s t a b | s -> a, t -> b, s b -> t, t a -> s where

Provides access to 1st field of a tuple.

Minimal complete definition

Nothing

Methods

_1 :: Lens s t a b

Access the 1st field of a tuple (and possibly change its type).

    >>> (1,2)^._1
    1

    >>> _1 .~ "hello" $ (1,2)
    ("hello",2)

    >>> (1,2) & _1 .~ "hello"
    ("hello",2)

    >>> _1 putStrLn ("hello","world")
    hello
    ((),"world")

This can also be used on larger tuples as well:

    >>> (1,2,3,4,5) & _1 +~ 41
    (42,2,3,4,5)

    _1 :: Lens (a,b) (a',b) a a'
    _1 :: Lens (a,b,c) (a',b,c) a a'
    _1 :: Lens (a,b,c,d) (a',b,c,d) a a'
    ...
    _1 :: Lens (a,b,c,d,e,f,g,h,i) (a',b,c,d,e,f,g,h,i) a a'

Instances

Field1 (Identity a) (Identity b) a b |
Field1 (a, b) (a', b) a a' |
    _1 k ~(a,b) = (\a' -> (a',b)) <$> k a
Field1 (a, b, c) (a', b, c) a a' |
Field1 ((:*:) f g p) ((:*:) f' g p) (f p) (f' p) |
Field1 (Product f g a) (Product f' g a) (f a) (f' a) |
Field1 (a, b, c, d) (a', b, c, d) a a' |
Field1 (a, b, c, d, e) (a', b, c, d, e) a a' |
Field1 (a, b, c, d, e, f) (a', b, c, d, e, f) a a' |
Field1 (a, b, c, d, e, f, g) (a', b, c, d, e, f, g) a a' |
Field1 (a, b, c, d, e, f, g, h) (a', b, c, d, e, f, g, h) a a' |
Field1 (a, b, c, d, e, f, g, h, i) (a', b, c, d, e, f, g, h, i) a a' |

class Field2 s t a b | s -> a, t -> b, s b -> t, t a -> s where

Provides access to the 2nd field of a tuple.

Minimal complete definition

Nothing

Methods

_2 :: Lens s t a b

Access the 2nd field of a tuple.

    >>> _2 .~ "hello" $ (1,(),3,4)
    (1,"hello",3,4)

    >>> (1,2,3,4) & _2 *~ 3
    (1,6,3,4)

    >>> _2 print (1,2)
    2
    (1,())

    anyOf _2 :: (s -> Bool) -> (a, s) -> Bool
    traverse . _2 :: (Applicative f, Traversable t) => (a -> f b) -> t (s, a) -> f (t (s, b))
    foldMapOf (traverse . _2) :: (Traversable t, Monoid m) => (s -> m) -> t (b, s) -> m

Instances

Field2 (a, b) (a, b') b b' |
    _2 k ~(a,b) = (\b' -> (a,b')) <$> k b
Field2 (a, b, c) (a, b', c) b b' |
Field2 ((:*:) f g p) ((:*:) f g' p) (g p) (g' p) |
Field2 (Product f g a) (Product f g' a) (g a) (g' a) |
Field2 (a, b, c, d) (a, b', c, d) b b' |
Field2 (a, b, c, d, e) (a, b', c, d, e) b b' |
Field2 (a, b, c, d, e, f) (a, b', c, d, e, f) b b' |
Field2 (a, b, c, d, e, f, g) (a, b', c, d, e, f, g) b b' |
Field2 (a, b, c, d, e, f, g, h) (a, b', c, d, e, f, g, h) b b' |
Field2 (a, b, c, d, e, f, g, h, i) (a, b', c, d, e, f, g, h, i) b b' |

class Field3 s t a b | s -> a, t -> b, s b -> t, t a -> s where

Provides access to the 3rd field of a tuple.

Minimal complete definition

Nothing

Methods

_3 :: Lens s t a b

Access the 3rd field of a tuple.

Instances

Field3 (a, b, c) (a, b, c') c c' |
Field3 (a, b, c, d) (a, b, c', d) c c' |
Field3 (a, b, c, d, e) (a, b, c', d, e) c c' |
Field3 (a, b, c, d, e, f) (a, b, c', d, e, f) c c' |
Field3 (a, b, c, d, e, f, g) (a, b, c', d, e, f, g) c c' |
Field3 (a, b, c, d, e, f, g, h) (a, b, c', d, e, f, g, h) c c' |
Field3 (a, b, c, d, e, f, g, h, i) (a, b, c', d, e, f, g, h, i) c c' |

class Field4 s t a b | s -> a, t -> b, s b -> t, t a -> s where

Provide access to the 4th field of a tuple.

Minimal complete definition

Nothing

Methods

_4 :: Lens s t a b

Access the 4th field of a tuple.

Instances

Field4 (a, b, c, d) (a, b, c, d') d d' |
Field4 (a, b, c, d, e) (a, b, c, d', e) d d' |
Field4 (a, b, c, d, e, f) (a, b, c, d', e, f) d d' |
Field4 (a, b, c, d, e, f, g) (a, b, c, d', e, f, g) d d' |
Field4 (a, b, c, d, e, f, g, h) (a, b, c, d', e, f, g, h) d d' |
Field4 (a, b, c, d, e, f, g, h, i) (a, b, c, d', e, f, g, h, i) d d' |

class Field5 s t a b | s -> a, t -> b, s b -> t, t a -> s where

Provides access to the 5th field of a tuple.

Minimal complete definition

Nothing

Methods

_5 :: Lens s t a b

Access the 5th field of a tuple.

Instances

Field5 (a, b, c, d, e) (a, b, c, d, e') e e' |
Field5 (a, b, c, d, e, f) (a, b, c, d, e', f) e e' |
Field5 (a, b, c, d, e, f, g) (a, b, c, d, e', f, g) e e' |
Field5 (a, b, c, d, e, f, g, h) (a, b, c, d, e', f, g, h) e e' |
Field5 (a, b, c, d, e, f, g, h, i) (a, b, c, d, e', f, g, h, i) e e' |

class Field6 s t a b | s -> a, t -> b, s b -> t, t a -> s where

Provides access to the 6th element of a tuple.

Minimal complete definition

Nothing

Methods

_6 :: Lens s t a b

Access the 6th field of a tuple.

Instances

Field6 (a, b, c, d, e, f) (a, b, c, d, e, f') f f' |
Field6 (a, b, c, d, e, f, g) (a, b, c, d, e, f', g) f f' |
Field6 (a, b, c, d, e, f, g, h) (a, b, c, d, e, f', g, h) f f' |
Field6 (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f', g, h, i) f f' |

class Field7 s t a b | s -> a, t -> b, s b -> t, t a -> s where

Provide access to the 7th field of a tuple.

Minimal complete definition

Nothing

Methods

_7 :: Lens s t a b

Access the 7th field of a tuple.

Instances

Field7 (a, b, c, d, e, f, g) (a, b, c, d, e, f, g') g g' |
Field7 (a, b, c, d, e, f, g, h) (a, b, c, d, e, f, g', h) g g' |
Field7 (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f, g', h, i) g g' |

class Field8 s t a b | s -> a, t -> b, s b -> t, t a -> s where

Provide access to the 8th field of a tuple.

Minimal complete definition

Nothing

Methods

_8 :: Lens s t a b

Access the 8th field of a tuple.

Instances

Field8 (a, b, c, d, e, f, g, h) (a, b, c, d, e, f, g, h') h h' |
Field8 (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f, g, h', i) h h' |

class Field9 s t a b | s -> a, t -> b, s b -> t, t a -> s where

Provides access to the 9th field of a tuple.

Minimal complete definition

Nothing

Methods

_9 :: Lens s t a b

Access the 9th field of a tuple.

Instances

Field9 (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f, g, h, i') i i' |

# Strict variations

_1' :: Field1 s t a b => Lens s t a b

Strict version of `_1`

_2' :: Field2 s t a b => Lens s t a b

Strict version of `_2`

_3' :: Field3 s t a b => Lens s t a b

Strict version of `_3`

_4' :: Field4 s t a b => Lens s t a b

Strict version of `_4`

_5' :: Field5 s t a b => Lens s t a b

Strict version of `_5`

_6' :: Field6 s t a b => Lens s t a b

Strict version of `_6`

_7' :: Field7 s t a b => Lens s t a b

Strict version of `_7`

_8' :: Field8 s t a b => Lens s t a b

Strict version of `_8`

_9' :: Field9 s t a b => Lens s t a b

Strict version of `_9`