Safe Haskell | None |
---|---|
Language | Haskell2010 |
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 single-constructor datatype has a Generic
instance, the corresponding
FieldN
instances can be defined using their default methods:
>>>
:set -XDeriveGeneric
>>>
data T a = MkT Int a deriving (Generic, Show)
>>>
instance Field1 (T a) (T a) Int Int
>>>
instance Field2 (T a) (T b) a b
>>>
set _2 'x' (MkT 1 False)
MkT 1 'x'
Synopsis
- class Field1 s t a b | s -> a, t -> b, s b -> t, t a -> s where
- class Field2 s t a b | s -> a, t -> b, s b -> t, t a -> s where
- class Field3 s t a b | s -> a, t -> b, s b -> t, t a -> s where
- class Field4 s t a b | s -> a, t -> b, s b -> t, t a -> s where
- class Field5 s t a b | s -> a, t -> b, s b -> t, t a -> s where
- class Field6 s t a b | s -> a, t -> b, s b -> t, t a -> s where
- class Field7 s t a b | s -> a, t -> b, s b -> t, t a -> s where
- class Field8 s t a b | s -> a, t -> b, s b -> t, t a -> s where
- class Field9 s t a b | s -> a, t -> b, s b -> t, t a -> s where
- _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 Source #
Provides access to 1st field of a tuple.
Nothing
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)
_1 :: (Generic s, Generic t, GIxed N0 (Rep s) (Rep t) a b) => 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)
Instances
Field1 (Identity a) (Identity b) a b Source # | |
Field1 (a, b) (a', b) a a' Source # | |
Defined in Data.Tuple.Optics | |
Field1 (a, b, c) (a', b, c) a a' Source # | |
Defined in Data.Tuple.Optics | |
Field1 (a, b, c, d) (a', b, c, d) a a' Source # | |
Defined in Data.Tuple.Optics | |
Field1 ((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 # | |
Field1 (a, b, c, d, e) (a', b, c, d, e) a a' Source # | |
Defined in Data.Tuple.Optics | |
Field1 (a, b, c, d, e, f) (a', b, c, d, e, f) a a' Source # | |
Defined in Data.Tuple.Optics | |
Field1 (a, b, c, d, e, f, g) (a', b, c, d, e, f, g) a a' Source # | |
Defined in Data.Tuple.Optics | |
Field1 (a, b, c, d, e, f, g, h) (a', b, c, d, e, f, g, h) a a' Source # | |
Defined in Data.Tuple.Optics | |
Field1 (a, b, c, d, e, f, g, h, i) (a', b, c, d, e, f, g, h, i) a a' Source # | |
Defined in Data.Tuple.Optics |
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.
Nothing
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,())
_2 :: (Generic s, Generic t, GIxed N1 (Rep s) (Rep t) a b) => 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,())
Instances
Field2 (a, b) (a, b') b b' Source # | |
Defined in Data.Tuple.Optics | |
Field2 (a, b, c) (a, b', c) b b' Source # | |
Defined in Data.Tuple.Optics | |
Field2 (a, b, c, d) (a, b', c, d) b b' Source # | |
Defined in Data.Tuple.Optics | |
Field2 ((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 # | |
Field2 (a, b, c, d, e) (a, b', c, d, e) b b' Source # | |
Defined in Data.Tuple.Optics | |
Field2 (a, b, c, d, e, f) (a, b', c, d, e, f) b b' Source # | |
Defined in Data.Tuple.Optics | |
Field2 (a, b, c, d, e, f, g) (a, b', c, d, e, f, g) b b' Source # | |
Defined in Data.Tuple.Optics | |
Field2 (a, b, c, d, e, f, g, h) (a, b', c, d, e, f, g, h) b b' Source # | |
Defined in Data.Tuple.Optics | |
Field2 (a, b, c, d, e, f, g, h, i) (a, b', c, d, e, f, g, h, i) b b' Source # | |
Defined in Data.Tuple.Optics |
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.
Nothing
Access the 3rd field of a tuple.
_3 :: (Generic s, Generic t, GIxed N2 (Rep s) (Rep t) a b) => Lens s t a b Source #
Access the 3rd field of a tuple.
Instances
Field3 (a, b, c) (a, b, c') c c' Source # | |
Defined in Data.Tuple.Optics | |
Field3 (a, b, c, d) (a, b, c', d) c c' Source # | |
Defined in Data.Tuple.Optics | |
Field3 (a, b, c, d, e) (a, b, c', d, e) c c' Source # | |
Defined in Data.Tuple.Optics | |
Field3 (a, b, c, d, e, f) (a, b, c', d, e, f) c c' Source # | |
Defined in Data.Tuple.Optics | |
Field3 (a, b, c, d, e, f, g) (a, b, c', d, e, f, g) c c' Source # | |
Defined in Data.Tuple.Optics | |
Field3 (a, b, c, d, e, f, g, h) (a, b, c', d, e, f, g, h) c c' Source # | |
Defined in Data.Tuple.Optics | |
Field3 (a, b, c, d, e, f, g, h, i) (a, b, c', d, e, f, g, h, i) c c' Source # | |
Defined in Data.Tuple.Optics |
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.
Nothing
Access the 4th field of a tuple.
_4 :: (Generic s, Generic t, GIxed N3 (Rep s) (Rep t) a b) => Lens s t a b Source #
Access the 4th field of a tuple.
Instances
Field4 (a, b, c, d) (a, b, c, d') d d' Source # | |
Defined in Data.Tuple.Optics | |
Field4 (a, b, c, d, e) (a, b, c, d', e) d d' Source # | |
Defined in Data.Tuple.Optics | |
Field4 (a, b, c, d, e, f) (a, b, c, d', e, f) d d' Source # | |
Defined in Data.Tuple.Optics | |
Field4 (a, b, c, d, e, f, g) (a, b, c, d', e, f, g) d d' Source # | |
Defined in Data.Tuple.Optics | |
Field4 (a, b, c, d, e, f, g, h) (a, b, c, d', e, f, g, h) d d' Source # | |
Defined in Data.Tuple.Optics | |
Field4 (a, b, c, d, e, f, g, h, i) (a, b, c, d', e, f, g, h, i) d d' Source # | |
Defined in Data.Tuple.Optics |
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.
Nothing
Access the 5th field of a tuple.
_5 :: (Generic s, Generic t, GIxed N4 (Rep s) (Rep t) a b) => Lens s t a b Source #
Access the 5th field of a tuple.
Instances
Field5 (a, b, c, d, e) (a, b, c, d, e') e e' Source # | |
Defined in Data.Tuple.Optics | |
Field5 (a, b, c, d, e, f) (a, b, c, d, e', f) e e' Source # | |
Defined in Data.Tuple.Optics | |
Field5 (a, b, c, d, e, f, g) (a, b, c, d, e', f, g) e e' Source # | |
Defined in Data.Tuple.Optics | |
Field5 (a, b, c, d, e, f, g, h) (a, b, c, d, e', f, g, h) e e' Source # | |
Defined in Data.Tuple.Optics | |
Field5 (a, b, c, d, e, f, g, h, i) (a, b, c, d, e', f, g, h, i) e e' Source # | |
Defined in Data.Tuple.Optics |
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.
Nothing
Access the 6th field of a tuple.
_6 :: (Generic s, Generic t, GIxed N5 (Rep s) (Rep t) a b) => Lens s t a b Source #
Access the 6th field of a tuple.
Instances
Field6 (a, b, c, d, e, f) (a, b, c, d, e, f') f f' Source # | |
Defined in Data.Tuple.Optics | |
Field6 (a, b, c, d, e, f, g) (a, b, c, d, e, f', g) f f' Source # | |
Defined in Data.Tuple.Optics | |
Field6 (a, b, c, d, e, f, g, h) (a, b, c, d, e, f', g, h) f f' Source # | |
Defined in Data.Tuple.Optics | |
Field6 (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f', g, h, i) f f' Source # | |
Defined in Data.Tuple.Optics |
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.
Nothing
Access the 7th field of a tuple.
_7 :: (Generic s, Generic t, GIxed N6 (Rep s) (Rep t) a b) => Lens s t a b Source #
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' Source # | |
Defined in Data.Tuple.Optics | |
Field7 (a, b, c, d, e, f, g, h) (a, b, c, d, e, f, g', h) g g' Source # | |
Defined in Data.Tuple.Optics | |
Field7 (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f, g', h, i) g g' Source # | |
Defined in Data.Tuple.Optics |
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.
Nothing
Access the 8th field of a tuple.
_8 :: (Generic s, Generic t, GIxed N7 (Rep s) (Rep t) a b) => Lens s t a b Source #
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' Source # | |
Defined in Data.Tuple.Optics | |
Field8 (a, b, c, d, e, f, g, h, i) (a, b, c, d, e, f, g, h', i) h h' Source # | |
Defined in Data.Tuple.Optics |
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.
Nothing