| Copyright | (C) 2019 Csongor Kiss | 
|---|---|
| License | BSD3 | 
| Maintainer | Csongor Kiss <kiss.csongor.kiss@gmail.com> | 
| Stability | experimental | 
| Portability | non-portable | 
| Safe Haskell | None | 
| Language | Haskell2010 | 
Data.Generics.Sum.Typed
Contents
Description
Derive constructor-field-type-based prisms generically.
Synopsis
- class AsType a s where- _Typed :: Prism' s a
- injectTyped :: a -> s
- projectTyped :: s -> Maybe a
 
Prisms
class AsType a s where Source #
Sums that have a constructor with a field of the given type.
Minimal complete definition
Methods
A prism that projects a constructor uniquely identifiable by the type of
  its field. Compatible with the lens package's Prism type.
>>>dog ^? _Typed @DogJust (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] | 
| Defined in Data.Generics.Sum.Typed | |
| (Generic s, ErrorUnlessOne a s (CollectPartialType as (Rep s)), as ~ TupleToList a, ListTuple a as, GAsType (Rep s) as, Defined (Rep s) (NoGeneric s ((Text "arising from a generic prism focusing on a constructor of type " :<>: QuoteType a) ': ([] :: [ErrorMessage]))) ()) => AsType a s Source # | |
| Defined in Data.Generics.Sum.Typed | |
| AsType Void a Source # | See Note [Uncluttering type signatures] | 
| Defined in Data.Generics.Sum.Typed | |