generic-lens-0.4.1.0: Generic data-structure operations exposed as lenses.

Copyright(C) 2017 Csongor Kiss
LicenseBSD3
MaintainerCsongor Kiss <kiss.csongor.kiss@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellSafe
LanguageHaskell2010

Data.Generics.Sum.Any

Contents

Description

Derive a variety of prisms generically.

Synopsis

Prisms

class AsAny sel a s | s sel k -> a where Source #

Sums that have generic prisms.

Methods

_As :: Prism' s a Source #

A prism that projects a sum as identified by some selector. Currently supported selectors are constructor names and unique types. Compatible with the lens package's Prism type.

>>> dog ^? _As @"Dog"
Just (MkDog {name = "Shep", age = 3})
>>> dog ^? _As @Dog
Just (MkDog {name = "Shep", age = 3})
>>> dog ^? _As @"Cat"
Nothing
>>> cat ^? _As @(Name, Age)
Just ("Mog",5)
>>> cat ^? _As @"Cat"
Just ("Mog",5)
>>> _As @"Cat" # ("Garfield", 6) :: Animal
Cat ("Garfield",6)
>>> duck ^? _As @Age
Just 2

Instances

AsConstructor ctor a s => AsAny Symbol ctor a s Source # 

Methods

_As :: Prism' s s Source #

AsType a s => AsAny * a a s Source # 

Methods

_As :: Prism' s s Source #