Copyright | (C) 2017 Csongor Kiss |
---|---|
License | BSD3 |
Maintainer | Csongor Kiss <kiss.csongor.kiss@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | Safe |
Language | Haskell2010 |
Derive constructor-name-based prisms generically.
- class AsConstructor ctor a s | s ctor -> a where
- class GAsConstructor ctor f a | ctor f -> a where
Prisms
class AsConstructor ctor a s | s ctor -> a where #
Sums that have a constructor with a given name.
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)
(Generic s, ErrorUnless ctor s (HasCtorP ctor (Rep s)), GAsConstructor ctor (Rep s) a) => AsConstructor ctor a s # | |
Internals
class GAsConstructor ctor f a | ctor f -> a where #
As AsConstructor
but over generic representations as defined by
GHC.Generics.
GSumAsConstructor ctor l r a (HasCtorP ctor l) => GAsConstructor ctor ((:+:) l r) a # | |
GAsConstructor ctor f a => GAsConstructor ctor (M1 S meta f) a # | |
GAsConstructor ctor f a => GAsConstructor ctor (M1 D meta f) a # | |
(GCollectible f as, ListTuple a as) => GAsConstructor ctor (M1 C (MetaCons ctor fixity fields) f) a # | |