proarrow
Safe HaskellNone
LanguageGHC2024

Proarrow.Optic.AffineFold

Description

The affine fold: a fold that sees at most one focus, s ~> (a || TerminalObject) (AffineFoldFl / 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 generic ExOptic carrier.

Synopsis

Documentation

class FoldFl p q => AffineFoldFl (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) => AffineFoldFl (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) => AffineFoldFl (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 #

(HasCoproducts k, Ob t) => AffineFoldFl (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 #

Comonoid m => AffineFoldFl (Rep (ActionAt (Tensor :: k -> (k, k) -> Type) m) :: k -> k -> Type) (Corep (ActionAt (Tensor :: k -> (k, k) -> Type) m) :: k -> k -> Type) Source Github #

The tensor-action witness pair Rep/Corep (ActionAt Tensor m) views (and previews) when the residual m is a Comonoid: discard it with the counit. (Its setter and traversal instances live in Proarrow.Optic.Setter and Proarrow.Optic.Traversal.)

Instance details

Defined in Proarrow.Optic.MonoidalLens

Methods

previewP :: forall (s :: k) (a :: k). Bicartesian k => Rep (ActionAt (Tensor :: k -> (k, k) -> Type) m) s a -> s ~> (a || (TerminalObject :: k)) Source Github #

(CopyDiscard k, HasCoproducts k, Ob t) => AffineFoldFl (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) => AffineFoldFl (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 #

(AffineFoldFl f g, AffineFoldFl f' g') => AffineFoldFl (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 (AffineFoldFl :: (k +-> k) -> (j +-> j) -> Constraint)) s t a b Source Github #

preview :: forall {j} {k} (c :: (k -> j -> Type) -> Constraint) (s :: k) (t :: j) (a :: k) (b :: j). (Bicartesian k, CategoryOf j, (Ob a, Ob b) => c (ExOptic (AffineFoldFl :: (k +-> k) -> (j +-> j) -> Constraint) a b)) => 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: run it at its witness pair (ExOptic AffineFoldFl, via withLegs) and apply previewP.

(^?) :: forall s t a b (c :: (Type -> Type -> Type) -> Constraint). c (ExOptic (AffineFoldFl :: (Type +-> Type) -> (Type +-> Type) -> Constraint) a b) => 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).