distributors
Copyright(C) 2026 - Eitan Chatav
LicenseBSD-style (see the file LICENSE)
MaintainerEitan Chatav <eitan.chatav@gmail.com>
Stabilityprovisional
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Data.Profunctor.Filtrator

Contents

Description

 
Synopsis

Filtrator

class (Cochoice p, forall x. Filterable (p x)) => Filtrator (p :: Type -> Type -> Type) where Source #

The Filtrator class extends Cochoice, as well as Filterable, adding the filtrate method, which projects a profunctor of sums onto its summands.

For a CocartesianChoice, filtrate is a retraction of alternate, projecting a summand back out of its injection,

prop> fst (filtrate (alternate (Left p))) = p
prop> snd (filtrate (alternate (Right p))) = p

that is, since unleft is fst . filtrate & left' is alternate . Left,

prop> unleft . left' = id
prop> unright . right' = id

filtrate isn't a retraction of >+< in general, though, since it tries its summands in turn, & the second summand of a left-biased or predictive one, like the Parsor s Maybe or Parsector parsers of distributors-grammar, is lost where the first applies. Nor is >+< a retraction of filtrate, since a profunctor of sums may cross summands, as rmap (either Right Left) does.

Minimal complete definition

Nothing

Methods

filtrate :: p (Either a c) (Either b d) -> (p a b, p c d) Source #

prop> unleft = fst . filtrate
prop> unleft = lmap Left . mapMaybe (either Just (const Nothing))
prop> unright = snd . filtrate
prop> unright = lmap Right . mapMaybe (either (const Nothing) Just)

filtrate is a distant relative to partitionEithers. filtrate can be given a default value for Monadic Alternators via mfiltrate.

prop> filtrate = mfiltrate

filtrate has a default for Choice & Cochoice partial profunctors.

default filtrate :: Choice p => p (Either a c) (Either b d) -> (p a b, p c d) Source #

Instances

Instances details
Filtrator p => Filtrator (Coyoneda p) Source # 
Instance details

Defined in Data.Profunctor.Filtrator

Methods

filtrate :: Coyoneda p (Either a c) (Either b d) -> (Coyoneda p a b, Coyoneda p c d) Source #

Filtrator p => Filtrator (Yoneda p) Source # 
Instance details

Defined in Data.Profunctor.Filtrator

Methods

filtrate :: Yoneda p (Either a c) (Either b d) -> (Yoneda p a b, Yoneda p c d) Source #

Filtrator (Binocular a b) Source # 
Instance details

Defined in Control.Lens.Bifocal

Methods

filtrate :: Binocular a b (Either a0 c) (Either b0 d) -> (Binocular a b a0 b0, Binocular a b c d) Source #

Filtrator (Spectacle a b) Source # 
Instance details

Defined in Control.Lens.Bifocal

Methods

filtrate :: Spectacle a b (Either a0 c) (Either b0 d) -> (Spectacle a b a0 b0, Spectacle a b c d) Source #

Filtrator (PartialMarket a b) Source # 
Instance details

Defined in Data.Profunctor.Filtrator

Methods

filtrate :: PartialMarket a b (Either a0 c) (Either b0 d) -> (PartialMarket a b a0 b0, PartialMarket a b c d) Source #

(Profunctor p, forall x. Functor (p x), Filterable f) => Filtrator (WrappedPafb f p) Source # 
Instance details

Defined in Data.Profunctor.Filtrator

Methods

filtrate :: WrappedPafb f p (Either a c) (Either b d) -> (WrappedPafb f p a b, WrappedPafb f p c d) Source #

Filtrator (Forget r :: Type -> Type -> Type) Source # 
Instance details

Defined in Data.Profunctor.Filtrator

Methods

filtrate :: Forget r (Either a c) (Either b d) -> (Forget r a b, Forget r c d) Source #

Filterable f => Filtrator (Joker f :: Type -> Type -> Type) Source # 
Instance details

Defined in Data.Profunctor.Filtrator

Methods

filtrate :: Joker f (Either a c) (Either b d) -> (Joker f a b, Joker f c d) Source #

Monad m => Filtrator (Varifocus a b m) Source # 
Instance details

Defined in Control.Lens.Varifocal

Methods

filtrate :: Varifocus a b m (Either a0 c) (Either b0 d) -> (Varifocus a b m a0 b0, Varifocus a b m c d) Source #

mfiltrate Source #

Arguments

:: (Monadic p, Alternator p) 
=> p (Either a c) (Either b d)

partition Either

-> (p a b, p c d) 

A Monadic Alternator has an equivalent to filtrate, given by mfiltrate.

prop> filtrate = mfiltrate