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.Fields

Contents

Description

Derive record field getters and setters generically.

Synopsis

Lenses

class HasField field a s | s field -> a where Source #

Records that have a field with a given name.

Minimal complete definition

field | setField, getField

Methods

field :: Lens' s a Source #

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

>>> human ^. field @"age"
50
>>> human & field @"name" .~ "Tamas"
Human {name = "Tamas", age = 50, address = "London"}

getField :: s -> a Source #

Get field

>>> getField @"name" human
"Tunyasz"

setField :: a -> s -> s Source #

Set field

>>> setField @"age" (setField @"name" "Tamas" human) 30
Human {name = "Tamas", age = 30, address = "London"}

Instances

(Generic s, ErrorUnless field s (HasTotalFieldP field (Rep s)), GHasField field (Rep s) a) => HasField field a s Source # 

Methods

field :: Lens' s a Source #

getField :: s -> a Source #

setField :: a -> s -> s Source #