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

Internals

class GHasField field f a | field f -> a where Source #

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

Minimal complete definition

gfield

Methods

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

Instances

GHasField field (S1 (MetaSel (Just Symbol field) upkd str infstr) (Rec0 a)) a Source # 

Methods

gfield :: Functor f => (a -> f a) -> S1 (MetaSel (Just Symbol field) upkd str infstr) (Rec0 a) x -> f (S1 (MetaSel (Just Symbol field) upkd str infstr) (Rec0 a) x) Source #

(GHasField field l a, GHasField field r a) => GHasField field ((:+:) l r) a Source # 

Methods

gfield :: Functor f => (a -> f a) -> (l :+: r) x -> f ((l :+: r) x) Source #

GProductHasField field l r a (HasTotalFieldP field l) => GHasField field ((:*:) l r) a Source # 

Methods

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

GHasField field f a => GHasField field (M1 C meta f) a Source # 

Methods

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

GHasField field f a => GHasField field (M1 D meta f) a Source # 

Methods

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