Copyright | (c) Aaron Allen 2020 |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | Aaron Allen <aaronallen8455@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Typson.Optics
Contents
Description
Synopsis
- fieldLens :: (KnownSymbol key, tree ~ 'Node 'Product edges, TypeAtPath obj tree key ~ ty) => proxy key -> Optic key ty tree obj -> Lens' obj ty
- fieldPrism :: (KnownSymbol key, tree ~ 'Node 'Sum edges, TypeAtPath obj tree key ~ Maybe ty) => proxy key -> Optic key ty tree obj -> Prism' obj ty
Optics
van Laarhoven style optics derived from schemas.
Arguments
:: (KnownSymbol key, tree ~ 'Node 'Product edges, TypeAtPath obj tree key ~ ty) | |
=> proxy key | The field's key |
-> Optic key ty tree obj | The object's schema |
-> Lens' obj ty |
Produce a Lens
given a key for an object field and a schema
>>>
edward ^. fieldLens (key @"name") personJ
"Edward"
Arguments
:: (KnownSymbol key, tree ~ 'Node 'Sum edges, TypeAtPath obj tree key ~ Maybe ty) | |
=> proxy key | The tag's key |
-> Optic key ty tree obj | The union's schema |
-> Prism' obj ty |
Produce a Prism
given a key for a union tag and a schema
>>>
dog ^? fieldLens (key @"classifier") lifeFormJ . fieldPrism (key @"fauna") classifierJ
Just (Animal {favoriteFoods = ["Chicken","Peanut Butter","Salmon"], isGoodPet = True})