generic-optics-2.0.0.0: Generically derive traversals, lenses and prisms.

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

Data.Generics.Sum.Typed

Contents

Description

Derive constructor-field-type-based prisms generically.

Synopsis

Prisms

class AsType a s where Source #

Sums that have a constructor with a field of the given type.

Minimal complete definition

injectTyped, projectTyped | _Typed

Methods

_Typed :: Prism' s a Source #

A prism that projects a constructor uniquely identifiable by the type of its field.

>>> dog ^? _Typed @Dog
Just (MkDog {name = "Shep", age = Age 3})
>>> cat ^? _Typed @(Name, Age)
Just ("Mog",Age 5)
>>> dog ^? _Typed @Age
...
...
... The type Animal contains multiple constructors whose fields are of type Age.
... The choice of constructor is thus ambiguous, could be any of:
... Duck
... Turtle
...

injectTyped :: a -> s Source #

Inject by type.

projectTyped :: s -> Maybe a Source #

Project by type.

Instances
AsType a Void Source #

See Note [Uncluttering type signatures] >>> :t _Typed _Typed :: AsType a s => Prism' s a

Instance details

Defined in Data.Generics.Sum.Typed

Context a s => AsType a s Source # 
Instance details

Defined in Data.Generics.Sum.Typed

Methods

_Typed :: Prism' s a Source #

injectTyped :: a -> s Source #

projectTyped :: s -> Maybe a Source #

AsType Void a Source #

See Note [Uncluttering type signatures] >>> :t _Typed Int _Typed Int :: AsType Int s => Prism' s Int

Instance details

Defined in Data.Generics.Sum.Typed