generic-lens-0.4.1.0: 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 #