generic-lens-0.5.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.Typed

Contents

Description

Derive constructor-field-type-based prisms generically.

Synopsis

Prisms

class AsType a s where #

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

Minimal complete definition

_Typed, injectTyped, projectTyped

Methods

_Typed :: Prism' s a #

A prism that projects a constructor uniquely identifiable by the type of its field. Compatible with the lens package's Prism type.

>>> 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 #

Inject by type.

projectTyped :: s -> Maybe a #

Project by type.

Instances

(Generic s, ErrorUnlessOne a s (CollectPartialType a (Rep s)), GAsType (Rep s) a) => AsType a s # 

Methods

_Typed :: Prism' s a #

injectTyped :: a -> s #

projectTyped :: s -> Maybe a #