generic-lens-0.3.0.1: 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 Source #

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

Methods

_Typed :: Prism' s a Source #

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 = 3})
>>> dog ^? _Typed @Cat
Nothing
>>> duck ^? _Typed @Age
Just 2

Instances

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

Methods

_Typed :: Prism' s a Source #

Internals

class GAsType f a where Source #

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

Minimal complete definition

ginjectTyped, gprojectTyped

Methods

_GTyped :: Prism' (f x) a Source #

ginjectTyped :: a -> f x Source #

gprojectTyped :: f x -> Either (f x) a Source #

Instances

GSumAsType (HasPartialTypeTupleP a l) l r a => GAsType ((:+:) l r) a Source # 

Methods

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

ginjectTyped :: a -> (l :+: r) x Source #

gprojectTyped :: (l :+: r) x -> Either ((l :+: r) x) a Source #

GAsType f a => GAsType (M1 D meta f) a Source # 

Methods

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

ginjectTyped :: a -> M1 D meta f x Source #

gprojectTyped :: M1 D meta f x -> Either (M1 D meta f x) a Source #

(GCollectible f as, ListTuple a as) => GAsType (M1 C meta f) a Source # 

Methods

_GTyped :: (Choice p, Applicative f) => p a (f a) -> p (M1 C meta f x) (f (M1 C meta f x)) Source #

ginjectTyped :: a -> M1 C meta f x Source #

gprojectTyped :: M1 C meta f x -> Either (M1 C meta f x) a Source #