typson-core-0.1.0.1: Type-safe PostgreSQL JSON Querying
Copyright(c) Aaron Allen 2020
LicenseBSD-style (see the file LICENSE)
MaintainerAaron Allen <aaronallen8455@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Typson.Optics

Contents

Description

 
Synopsis

Optics

van Laarhoven style optics derived from schemas.

fieldLens Source #

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"

fieldPrism Source #

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})