generic-lens-0.3.0.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 #

Sums that have a constructor with a given name.

Methods

_Ctor :: Prism' s a #

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 # 

Methods

_Ctor :: Prism' s a #

Internals

class GAsConstructor ctor f a | ctor f -> a where #

As AsConstructor but over generic representations as defined by GHC.Generics.

Methods

_GCtor :: Prism' (f x) a #

Instances

GSumAsConstructor ctor l r a (HasCtorP ctor l) => GAsConstructor ctor ((:+:) l r) a # 

Methods

_GCtor :: (Choice p, Applicative f) => p a (f a) -> p ((l :+: r) x) (f ((l :+: r) x)) #

GAsConstructor ctor f a => GAsConstructor ctor (M1 S meta f) a # 

Methods

_GCtor :: (Choice p, Applicative f) => p a (f a) -> p (M1 S meta f x) (f (M1 S meta f x)) #

GAsConstructor ctor f a => GAsConstructor ctor (M1 D meta f) a # 

Methods

_GCtor :: (Choice p, Applicative f) => p a (f a) -> p (M1 D meta f x) (f (M1 D meta f x)) #

(GCollectible f as, ListTuple a as) => GAsConstructor ctor (M1 C (MetaCons ctor fixity fields) f) a # 

Methods

_GCtor :: (Choice p, Applicative f) => p a (f a) -> p (M1 C (MetaCons ctor fixity fields) f x) (f (M1 C (MetaCons ctor fixity fields) f x)) #