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.
- class HasField field a s | s field -> a where
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"}