optics-core-0.4.1: Optics as an abstract interface: core definitions
Safe Haskell None
Language Haskell2010

Data.Tuple.Optics

Description

This module defines Lens es for the fields of tuple types. These are overloaded using the Field1 to Field9 typeclasses, so that _1 can be used as a Lens for the first field of a tuple with any number of fields (up to the maximum supported tuple size, which is currently 9). For example:

>>> view _1 ('a','b','c')
'a'
>>> set _3 True ('a','b','c')
('a','b',True)

If a datatype has a Generic instance, the corresponding FieldN instances can be defined using their default methods:

>>> :set -XDeriveGeneric
>>> import GHC.Generics (Generic)
>>> data T a b = MkT a Int b deriving (Generic, Show)
>>> instance Field1 (T a c) (T b c) a b
>>> instance Field2 (T a b) (T a b) Int Int
>>> instance Field3 (T c a) (T c b) a b
>>> set _3 'x' (MkT False 1 ())
MkT False 1 'x'

For a generalization of this pattern see GPosition .

Synopsis

Tuples

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

Provides access to 1st field of a tuple.

Minimal complete definition

Nothing

Methods

_1 :: Lens s t a b Source #

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

>>> (1,2) ^. _1
1
>>> (1,2) & _1 .~ "hello"
("hello",2)
>>> traverseOf _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)

default _1 :: GPosition 1 s t a b => Lens s t a b Source #

Instances

Instances details
Field1 ( Identity a) ( Identity b) a b Source #
Instance details

Defined in Data.Tuple.Optics

Field1 (a, b) (a', b) a a' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

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

Field1 (a, b, c) (a', b, c) a a' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

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

Field1 (a, b, c, d) (a', b, c, d) a a' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_1 :: Lens (a, b, c, d) (a', b, c, d) a a' Source #

Field1 ((f :*: g) p) ((f' :*: g) p) (f p) (f' p) Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_1 :: Lens ((f :*: g) p) ((f' :*: g) p) (f p) (f' p) Source #

Field1 ( Product f g a) ( Product f' g a) (f a) (f' a) Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_1 :: Lens ( Product f g a) ( Product f' g a) (f a) (f' a) Source #

Field1 (a, b, c, d, e) (a', b, c, d, e) a a' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_1 :: Lens (a, b, c, d, e) (a', b, c, d, e) a a' Source #

Field1 (a, b, c, d, e, f) (a', b, c, d, e, f) a a' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_1 :: Lens (a, b, c, d, e, f) (a', b, c, d, e, f) a a' Source #

Field1 (a, b, c, d, e, f, g) (a', b, c, d, e, f, g) a a' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_1 :: Lens (a, b, c, d, e, f, g) (a', b, c, d, e, f, g) a a' Source #

Field1 (a, b, c, d, e, f, g, h) (a', b, c, d, e, f, g, h) a a' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_1 :: Lens (a, b, c, d, e, f, g, h) (a', b, c, d, e, f, g, h) a a' Source #

Field1 (a, b, c, d, e, f, g, h, i) (a', b, c, d, e, f, g, h, i) a a' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

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

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

Provides access to the 2nd field of a tuple.

Minimal complete definition

Nothing

Methods

_2 :: Lens s t a b Source #

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)
>>> traverseOf _2 print (1,2)
2
(1,())

default _2 :: GPosition 2 s t a b => Lens s t a b Source #

Instances

Instances details
Field2 (a, b) (a, b') b b' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

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

Field2 (a, b, c) (a, b', c) b b' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

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

Field2 (a, b, c, d) (a, b', c, d) b b' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_2 :: Lens (a, b, c, d) (a, b', c, d) b b' Source #

Field2 ((f :*: g) p) ((f :*: g') p) (g p) (g' p) Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_2 :: Lens ((f :*: g) p) ((f :*: g') p) (g p) (g' p) Source #

Field2 ( Product f g a) ( Product f g' a) (g a) (g' a) Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_2 :: Lens ( Product f g a) ( Product f g' a) (g a) (g' a) Source #

Field2 (a, b, c, d, e) (a, b', c, d, e) b b' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_2 :: Lens (a, b, c, d, e) (a, b', c, d, e) b b' Source #

Field2 (a, b, c, d, e, f) (a, b', c, d, e, f) b b' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_2 :: Lens (a, b, c, d, e, f) (a, b', c, d, e, f) b b' Source #

Field2 (a, b, c, d, e, f, g) (a, b', c, d, e, f, g) b b' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_2 :: Lens (a, b, c, d, e, f, g) (a, b', c, d, e, f, g) b b' Source #

Field2 (a, b, c, d, e, f, g, h) (a, b', c, d, e, f, g, h) b b' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_2 :: Lens (a, b, c, d, e, f, g, h) (a, b', c, d, e, f, g, h) b b' Source #

Field2 (a, b, c, d, e, f, g, h, i) (a, b', c, d, e, f, g, h, i) b b' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_2 :: Lens (a, b, c, d, e, f, g, h, i) (a, b', c, d, e, f, g, h, i) b b' Source #

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

Provides access to the 3rd field of a tuple.

Minimal complete definition

Nothing

Methods

_3 :: Lens s t a b Source #

Access the 3rd field of a tuple.

default _3 :: GPosition 3 s t a b => Lens s t a b Source #

Instances

Instances details
Field3 (a, b, c) (a, b, c') c c' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_3 :: Lens (a, b, c) (a, b, c') c c' Source #

Field3 (a, b, c, d) (a, b, c', d) c c' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_3 :: Lens (a, b, c, d) (a, b, c', d) c c' Source #

Field3 (a, b, c, d, e) (a, b, c', d, e) c c' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_3 :: Lens (a, b, c, d, e) (a, b, c', d, e) c c' Source #

Field3 (a, b, c, d, e, f) (a, b, c', d, e, f) c c' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_3 :: Lens (a, b, c, d, e, f) (a, b, c', d, e, f) c c' Source #

Field3 (a, b, c, d, e, f, g) (a, b, c', d, e, f, g) c c' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_3 :: Lens (a, b, c, d, e, f, g) (a, b, c', d, e, f, g) c c' Source #

Field3 (a, b, c, d, e, f, g, h) (a, b, c', d, e, f, g, h) c c' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_3 :: Lens (a, b, c, d, e, f, g, h) (a, b, c', d, e, f, g, h) c c' Source #

Field3 (a, b, c, d, e, f, g, h, i) (a, b, c', d, e, f, g, h, i) c c' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_3 :: Lens (a, b, c, d, e, f, g, h, i) (a, b, c', d, e, f, g, h, i) c c' Source #

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

Provide access to the 4th field of a tuple.

Minimal complete definition

Nothing

Methods

_4 :: Lens s t a b Source #

Access the 4th field of a tuple.

default _4 :: GPosition 4 s t a b => Lens s t a b Source #

Instances

Instances details
Field4 (a, b, c, d) (a, b, c, d') d d' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_4 :: Lens (a, b, c, d) (a, b, c, d') d d' Source #

Field4 (a, b, c, d, e) (a, b, c, d', e) d d' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_4 :: Lens (a, b, c, d, e) (a, b, c, d', e) d d' Source #

Field4 (a, b, c, d, e, f) (a, b, c, d', e, f) d d' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_4 :: Lens (a, b, c, d, e, f) (a, b, c, d', e, f) d d' Source #

Field4 (a, b, c, d, e, f, g) (a, b, c, d', e, f, g) d d' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_4 :: Lens (a, b, c, d, e, f, g) (a, b, c, d', e, f, g) d d' Source #

Field4 (a, b, c, d, e, f, g, h) (a, b, c, d', e, f, g, h) d d' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_4 :: Lens (a, b, c, d, e, f, g, h) (a, b, c, d', e, f, g, h) d d' Source #

Field4 (a, b, c, d, e, f, g, h, i) (a, b, c, d', e, f, g, h, i) d d' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_4 :: Lens (a, b, c, d, e, f, g, h, i) (a, b, c, d', e, f, g, h, i) d d' Source #

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

Provides access to the 5th field of a tuple.

Minimal complete definition

Nothing

Methods

_5 :: Lens s t a b Source #

Access the 5th field of a tuple.

default _5 :: GPosition 5 s t a b => Lens s t a b Source #

Instances

Instances details
Field5 (a, b, c, d, e) (a, b, c, d, e') e e' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_5 :: Lens (a, b, c, d, e) (a, b, c, d, e') e e' Source #

Field5 (a, b, c, d, e, f) (a, b, c, d, e', f) e e' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_5 :: Lens (a, b, c, d, e, f) (a, b, c, d, e', f) e e' Source #

Field5 (a, b, c, d, e, f, g) (a, b, c, d, e', f, g) e e' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_5 :: Lens (a, b, c, d, e, f, g) (a, b, c, d, e', f, g) e e' Source #

Field5 (a, b, c, d, e, f, g, h) (a, b, c, d, e', f, g, h) e e' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_5 :: Lens (a, b, c, d, e, f, g, h) (a, b, c, d, e', f, g, h) e e' Source #

Field5 (a, b, c, d, e, f, g, h, i) (a, b, c, d, e', f, g, h, i) e e' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_5 :: Lens (a, b, c, d, e, f, g, h, i) (a, b, c, d, e', f, g, h, i) e e' Source #

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

Provides access to the 6th element of a tuple.

Minimal complete definition

Nothing

Methods

_6 :: Lens s t a b Source #

Access the 6th field of a tuple.

default _6 :: GPosition 6 s t a b => Lens s t a b Source #

Instances

Instances details
Field6 (a, b, c, d, e, f) (a, b, c, d, e, f') f f' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_6 :: Lens (a, b, c, d, e, f) (a, b, c, d, e, f') f f' Source #

Field6 (a, b, c, d, e, f, g) (a, b, c, d, e, f', g) f f' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_6 :: Lens (a, b, c, d, e, f, g) (a, b, c, d, e, f', g) f f' Source #

Field6 (a, b, c, d, e, f, g, h) (a, b, c, d, e, f', g, h) f f' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_6 :: Lens (a, b, c, d, e, f, g, h) (a, b, c, d, e, f', g, h) f f' Source #

Field6 (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f', g, h, i) f f' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_6 :: Lens (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f', g, h, i) f f' Source #

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

Provide access to the 7th field of a tuple.

Minimal complete definition

Nothing

Methods

_7 :: Lens s t a b Source #

Access the 7th field of a tuple.

default _7 :: GPosition 7 s t a b => Lens s t a b Source #

Instances

Instances details
Field7 (a, b, c, d, e, f, g) (a, b, c, d, e, f, g') g g' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_7 :: Lens (a, b, c, d, e, f, g) (a, b, c, d, e, f, g') g g' Source #

Field7 (a, b, c, d, e, f, g, h) (a, b, c, d, e, f, g', h) g g' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_7 :: Lens (a, b, c, d, e, f, g, h) (a, b, c, d, e, f, g', h) g g' Source #

Field7 (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f, g', h, i) g g' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_7 :: Lens (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f, g', h, i) g g' Source #

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

Provide access to the 8th field of a tuple.

Minimal complete definition

Nothing

Methods

_8 :: Lens s t a b Source #

Access the 8th field of a tuple.

default _8 :: GPosition 8 s t a b => Lens s t a b Source #

Instances

Instances details
Field8 (a, b, c, d, e, f, g, h) (a, b, c, d, e, f, g, h') h h' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_8 :: Lens (a, b, c, d, e, f, g, h) (a, b, c, d, e, f, g, h') h h' Source #

Field8 (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f, g, h', i) h h' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_8 :: Lens (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f, g, h', i) h h' Source #

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

Provides access to the 9th field of a tuple.

Minimal complete definition

Nothing

Methods

_9 :: Lens s t a b Source #

Access the 9th field of a tuple.

default _9 :: GPosition 9 s t a b => Lens s t a b Source #

Instances

Instances details
Field9 (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f, g, h, i') i i' Source #
Instance details

Defined in Data.Tuple.Optics

Methods

_9 :: Lens (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f, g, h, i') i i' Source #

Strict variations

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

Strict version of _1

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

Strict version of _2

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

Strict version of _3

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

Strict version of _4

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

Strict version of _5

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

Strict version of _6

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

Strict version of _7

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

Strict version of _8

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

Strict version of _9