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.Constructors

Contents

Description

Derive constructor-name-based prisms generically.

Synopsis

Prisms

class AsConstructor ctor a s | s ctor -> a where Source #

Sums that have a constructor with a given name.

Methods

_Ctor :: Prism' s a Source #

A prism that projects a named constructor from a sum. Compatible with the lens package's Prism type.

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

Instances

(Generic s, ErrorUnless ctor s (HasCtorP ctor (Rep s)), GAsConstructor ctor (Rep s) a) => AsConstructor ctor a s Source # 

Methods

_Ctor :: Prism' s a Source #