Copyright | (C) 2018 Csongor Kiss |
---|---|
License | BSD3 |
Maintainer | Csongor Kiss <kiss.csongor.kiss@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Derive a variety of lenses generically.
Lenses
Running example:
>>>
:set -XTypeApplications
>>>
:set -XDataKinds
>>>
:set -XDeriveGeneric
>>>
import GHC.Generics
>>>
:m +Data.Generics.Internal.VL.Lens
>>>
:{
data Human = Human { name :: String , age :: Int , address :: String } deriving (Generic, Show) human :: Human human = Human "Tunyasz" 50 "London" :}
class HasAny (sel :: k) s t a b | s sel k -> a where Source #
A lens that focuses on a part of a product as identified by some
selector. Currently supported selectors are field names, positions and
unique types. Compatible with the lens package's Lens
type.
>>>
human ^. the @Int
50
>>>
human ^. the @"name"
"Tunyasz"
>>>
human ^. the @3
"London"
Instances
HasPosition i s t a b => HasAny (i :: Nat) s t a b Source # | |
Defined in Data.Generics.Product.Any | |
HasField field s t a b => HasAny (field :: Symbol) s t a b Source # | |
Defined in Data.Generics.Product.Any | |
(HasType a s, t ~ s, a ~ b) => HasAny (a :: Type) s t a b Source # | |
Defined in Data.Generics.Product.Any |