data-as-0.0.0.1: Simple extensible sum
Copyright(c) incertia 2020
LicenseMIT
Maintainerincertia@incertia.net
Stabilityexperimental
Portabilityportable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.As

Description

This module provides the As class which is a multi parameter classy prism, much like how Has is a multi parameter classy lens.

We have the following primary use case for As.

 -- some library code
 throwE :: (As e err, MonadError err m) => e -> m ()
 throwE = throwError . review asPrism
Synopsis

Documentation

class As a t where Source #

A typeclass for extensible sums.

The provided instances were inspired from the lens library.

Making your own instances when you actually depend on lens should be as easy as instance As Foo Bar where asPrism = _Foo.

Minimal complete definition

previewer, reviewer | asPrism

Methods

previewer :: t -> Maybe a Source #

reviewer :: a -> t Source #

asPrism :: Prism t a Source #

modifier :: (a -> a) -> t -> t Source #

Instances

Instances details
(Read a, Show a) => As a String Source # 
Instance details

Defined in Data.As

Methods

previewer :: String -> Maybe a Source #

reviewer :: a -> String Source #

asPrism :: Prism String a Source #

modifier :: (a -> a) -> String -> String Source #

As a a Source # 
Instance details

Defined in Data.As

Methods

previewer :: a -> Maybe a Source #

reviewer :: a -> a Source #

asPrism :: Prism a a Source #

modifier :: (a -> a) -> a -> a Source #

As Void a Source # 
Instance details

Defined in Data.As

Methods

previewer :: a -> Maybe Void Source #

reviewer :: Void -> a Source #

asPrism :: Prism a Void Source #

modifier :: (Void -> Void) -> a -> a Source #

As () (Maybe a) Source # 
Instance details

Defined in Data.As

Methods

previewer :: Maybe a -> Maybe () Source #

reviewer :: () -> Maybe a Source #

asPrism :: Prism (Maybe a) () Source #

modifier :: (() -> ()) -> Maybe a -> Maybe a Source #

As a (Maybe a) Source # 
Instance details

Defined in Data.As

Methods

previewer :: Maybe a -> Maybe a Source #

reviewer :: a -> Maybe a Source #

asPrism :: Prism (Maybe a) a Source #

modifier :: (a -> a) -> Maybe a -> Maybe a Source #

As b (Either a b) Source # 
Instance details

Defined in Data.As

Methods

previewer :: Either a b -> Maybe b Source #

reviewer :: b -> Either a b Source #

asPrism :: Prism (Either a b) b Source #

modifier :: (b -> b) -> Either a b -> Either a b Source #

As a (Either a b) Source # 
Instance details

Defined in Data.As

Methods

previewer :: Either a b -> Maybe a Source #

reviewer :: a -> Either a b Source #

asPrism :: Prism (Either a b) a Source #

modifier :: (a -> a) -> Either a b -> Either a b Source #