generic-lens-0.3.0.1: Generic data-structure operations exposed as lenses.

Copyright(C) 2017 Csongor Kiss
LicenseBSD3
MaintainerCsongor Kiss <kiss.csongor.kiss@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellSafe
LanguageHaskell2010

Data.Generics.Product.Positions

Contents

Description

Derive positional product type getters and setters generically.

Synopsis

Lenses

class HasPosition i a s | s i -> a where Source #

Records that have a field at a given position.

Minimal complete definition

position | setPosition, getPosition

Methods

position :: Lens' s a Source #

A lens that focuses on a field at a given position. Compatible with the lens package's Lens type.

>>> human ^. position @1
"Tunyasz"
>>> human & position @2 .~ "Berlin"
Human {name = "Tunyasz", age = 50, address = "Berlin"}

getPosition :: s -> a Source #

Get positional field

>>> getPosition @1 human
"Tunyasz"

setPosition :: a -> s -> s Source #

Set positional field

>>> setPosition @2 (setField @1 "Tamas" human) 30
Human "Tamas" 30 "London"

Instances

(Generic s, ErrorUnless i s ((&&) ((<?) 0 i) ((<=?) i (Size (Rep s)))), GHasPosition 1 i (Rep s) a) => HasPosition i a s Source # 

Methods

position :: Lens' s a Source #

getPosition :: s -> a Source #

setPosition :: a -> s -> s Source #

Internals

class GHasPosition offset i f a | offset i f -> a where Source #

As HasPosition but over generic representations as defined by GHC.Generics.

Minimal complete definition

gposition

Methods

gposition :: Lens' (f x) a Source #

Instances

((~) Bool goLeft ((<?) i ((+) offset (Size l))), (~) Nat offset' (If Nat goLeft offset ((+) offset (Size l))), GProductHasPosition offset' i l r a goLeft) => GHasPosition offset i ((:*:) l r) a Source # 

Methods

gposition :: Functor f => (a -> f a) -> (l :*: r) x -> f ((l :*: r) x) Source #

GHasPosition i i (S1 meta (Rec0 a)) a Source # 

Methods

gposition :: Functor f => (a -> f a) -> S1 meta (Rec0 a) x -> f (S1 meta (Rec0 a) x) Source #

GHasPosition offset i f a => GHasPosition offset i (M1 C meta f) a Source # 

Methods

gposition :: Functor f => (a -> f a) -> M1 C meta f x -> f (M1 C meta f x) Source #

GHasPosition offset i f a => GHasPosition offset i (M1 D meta f) a Source # 

Methods

gposition :: Functor f => (a -> f a) -> M1 D meta f x -> f (M1 D meta f x) Source #