Copyright | (C) 2017 Csongor Kiss |
---|---|
License | BSD3 |
Maintainer | Csongor Kiss <kiss.csongor.kiss@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | Safe |
Language | Haskell2010 |
Derive record field getters and setters generically.
Lenses
class HasField field a s | s field -> a where Source #
Records that have a field with a given name.
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"}
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"}
Internals
class GHasField field f a | field f -> a where Source #
As HasField
but over generic representations as defined by
GHC.Generics.
GHasField field (S1 (MetaSel (Just Symbol field) upkd str infstr) (Rec0 a)) a Source # | |
(GHasField field l a, GHasField field r a) => GHasField field ((:+:) l r) a Source # | |
GProductHasField field l r a (HasTotalFieldP field l) => GHasField field ((:*:) l r) a Source # | |
GHasField field f a => GHasField field (M1 C meta f) a Source # | |
GHasField field f a => GHasField field (M1 D meta f) a Source # | |