proarrow
Safe HaskellNone
LanguageGHC2024

Proarrow.Optic.AffineFold

Description

The affine fold: a fold that sees at most one focus, s ~> (a || TerminalObject) (AffineFoldRes / previewP). Every Getter and AffineTraversal is one, and it subtypes to Fold. Like all read-only flavors it has no builder of its own (convert a stronger optic); its canonical eliminator is preview / (^?), via the PreviewP carrier.

Synopsis

Documentation

class FoldRes p q => AffineFoldRes (p :: k +-> k) (q :: j +-> j) where Source Github #

An affine fold is a fold that can see at most one a -- 0-or-1, never 0-or-many. A getter is an affine fold that always succeeds; an affine traversal is one that additionally knows how to reconstruct a t when it fails to match.

Methods

previewP :: forall (s :: k) (a :: k). Bicartesian k => p s a -> s ~> (a || (TerminalObject :: k)) Source Github #

Instances

Instances details
(CategoryOf k, CategoryOf j) => AffineFoldRes (Id :: k -> k -> Type) (Id :: j -> j -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.AffineFold

Methods

previewP :: forall (s :: k) (a :: k). Bicartesian k => Id s a -> s ~> (a || (TerminalObject :: k)) Source Github #

(CategoryOf k, CategoryOf j) => AffineFoldRes (Id :: k -> k -> Type) (TerminalProfunctor :: j -> j -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.AffineFold

Methods

previewP :: forall (s :: k) (a :: k). Bicartesian k => Id s a -> s ~> (a || (TerminalObject :: k)) Source Github #

Comonoid m => AffineFoldRes (LensW m :: k -> k -> Type) (CoLensW m :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.MonoidalLens

Methods

previewP :: forall (s :: k) (a :: k). Bicartesian k => LensW m s a -> s ~> (a || (TerminalObject :: k)) Source Github #

(HasCoproducts k, Ob t) => AffineFoldRes (Corep (Coproduct t) :: k -> k -> Type) (Rep (Coproduct t) :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.AffineFold

Methods

previewP :: forall (s :: k) (a :: k). Bicartesian k => Corep (Coproduct t) s a -> s ~> (a || (TerminalObject :: k)) Source Github #

(CopyDiscard k, HasCoproducts k, Ob t) => AffineFoldRes (Rep (Coproduct t) :: k -> k -> Type) (Corep (Coproduct t) :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.AffineFold

Methods

previewP :: forall (s :: k) (a :: k). Bicartesian k => Rep (Coproduct t) s a -> s ~> (a || (TerminalObject :: k)) Source Github #

(HasBinaryProducts k, Ob s) => AffineFoldRes (Rep (Product s) :: k -> k -> Type) (Corep (Product s) :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.AffineFold

Methods

previewP :: forall (s0 :: k) (a :: k). Bicartesian k => Rep (Product s) s0 a -> s0 ~> (a || (TerminalObject :: k)) Source Github #

(AffineFoldRes f g, AffineFoldRes f' g') => AffineFoldRes (f :.: f' :: k -> k -> Type) (g' :.: g :: j -> j -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.AffineFold

Methods

previewP :: forall (s :: k) (a :: k). Bicartesian k => (f :.: f') s a -> s ~> (a || (TerminalObject :: k)) Source Github #

type AffineFold (s :: k) (t :: j) (a :: k) (b :: j) = Optic (Prostrong (AffineFoldRes :: (k +-> k) -> (j +-> j) -> Constraint)) s t a b Source Github #

data PreviewP (a :: k) (s :: k) (t :: j) where Source Github #

The carrier profunctor for preview: a generalized s -> Maybe a.

Constructors

PreviewP 

Fields

Instances

Instances details
(Bicartesian k, CategoryOf j, Ob a, SubFlavor w (AffineFoldRes :: (k +-> k) -> (j +-> j) -> Constraint)) => Prostrong (w :: FLAVOR j k) (PreviewP a :: k -> j -> Type) Source Github #

Any flavor whose optics can preview has strength for the PreviewP carrier.

Instance details

Defined in Proarrow.Optic.AffineFold

Methods

proact :: forall (f :: k +-> k) (g :: j +-> j). (w f g, Profunctor f, Profunctor g) => ((f :.: (PreviewP a :: k -> j -> Type)) :.: g) :~> (PreviewP a :: k -> j -> Type) Source Github #

(Bicartesian k, CategoryOf j, Ob a) => Profunctor (PreviewP a :: k -> j -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.AffineFold

Methods

dimap :: forall (c :: k) (a0 :: k) (b :: j) (d :: j). (c ~> a0) -> (b ~> d) -> PreviewP a a0 b -> PreviewP a c d Source Github #

lmap :: forall (c :: k) (a0 :: k) (b :: j). (c ~> a0) -> PreviewP a a0 b -> PreviewP a c b Source Github #

rmap :: forall (b :: j) (d :: j) (a0 :: k). (b ~> d) -> PreviewP a a0 b -> PreviewP a a0 d Source Github #

(\\) :: forall (a0 :: k) (b :: j) r. ((Ob a0, Ob b) => r) -> PreviewP a a0 b -> r Source Github #

preview :: forall {j} {k} (c :: (k -> j -> Type) -> Constraint) (s :: k) (t :: j) (a :: k) (b :: j). (Bicartesian k, CategoryOf j, c (PreviewP a :: k -> j -> Type)) => Optic c s t a b -> s ~> (a || (TerminalObject :: k)) Source Github #

Preview through any optic that can act as an affine fold, in either encoding.

(^?) :: forall s t a b (c :: (Type -> Type -> Type) -> Constraint). c (PreviewP a :: Type -> Type -> Type) => s -> Optic c s t a b -> Maybe a infixl 8 Source Github #

Preview the focus of a concrete, Type-level optic (a getter that might not match).