proarrow
Safe HaskellNone
LanguageGHC2024

Proarrow.Optic.Fold

Description

The fold: the weakest read-side optic, reducing the foci to any Monoid object of the category (FoldFl / foldMapP). It sits at the read-only top of the subtyping lattice (everything that can view, preview or traverse is a fold), so it has no builder of its own (reach it by convert from a stronger optic). Its canonical eliminator is foldMapOf, via the generic ExOptic carrier, with unfold as the re-mirror that builds from a Comonoid seed.

Synopsis

Documentation

class (Profunctor p, Profunctor q) => FoldFl (p :: k +-> k) (q :: j +-> j) where Source Github #

A fold is a getter or traversal that forgets everything except the ability to reduce the a's it can see into any monoid object of k. It can never reconstruct a t.

Methods

foldMapP :: forall (m :: k) (s :: k) (a :: k). Monoid m => p s a -> (a ~> m) -> s ~> m Source Github #

Instances

Instances details
(Distributive k, CopyDiscard k, Traversable t, Representable t) => FoldFl (t :: k +-> k) (RepCostar t :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Fold

Methods

foldMapP :: forall (m :: k) (s :: k) (a :: k). Monoid m => t s a -> (a ~> m) -> s ~> m Source Github #

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

Defined in Proarrow.Optic.Fold

Methods

foldMapP :: forall (m :: k) (s :: k) (a :: k). Monoid m => Id s a -> (a ~> m) -> s ~> m Source Github #

Monoidal k => FoldFl (UnitW :: k -> k -> Type) (CoUnitW :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Traversal

Methods

foldMapP :: forall (m :: k) (s :: k) (a :: k). Monoid m => UnitW s a -> (a ~> m) -> s ~> m Source Github #

HasInitialObject k => FoldFl (ZeroW :: k -> k -> Type) (CoZeroW :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Traversal

Methods

foldMapP :: forall (m :: k) (s :: k) (a :: k). Monoid m => ZeroW s a -> (a ~> m) -> s ~> m Source Github #

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

Defined in Proarrow.Optic.Fold

Methods

foldMapP :: forall (m :: k) (s :: k) (a :: k). Monoid m => Id s a -> (a ~> m) -> s ~> m Source Github #

(Monoidal k, SNatI n) => FoldFl (Pow n :: k -> k -> Type) (CoPow n :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.PowerGrate

Methods

foldMapP :: forall (m :: k) (s :: k) (a :: k). Monoid m => Pow n s a -> (a ~> m) -> s ~> m Source Github #

(Distributive k, CopyDiscard k, Cotraversable t, Corepresentable t) => FoldFl (CorepStar t :: k -> k -> Type) (t :: k +-> k) Source Github #

The corepresentable-cotraversable witness folds by cotraversing at the fold profunctor Rep (Constant m) and discarding the residual shape.

Instance details

Defined in Proarrow.Optic.Fold

Methods

foldMapP :: forall (m :: k) (s :: k) (a :: k). Monoid m => CorepStar t s a -> (a ~> m) -> s ~> m Source Github #

(FoldFl p1 q1, FoldFl p2 q2, Monoidal k) => FoldFl (Beside p1 p2 :: k -> k -> Type) (CoBeside q1 q2 :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Traversal

Methods

foldMapP :: forall (m :: k) (s :: k) (a :: k). Monoid m => Beside p1 p2 s a -> (a ~> m) -> s ~> m Source Github #

(FoldFl p1 q1, FoldFl p2 q2, HasBinaryCoproducts k) => FoldFl (BesideSum p1 p2 :: k -> k -> Type) (CoBesideSum q1 q2 :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Traversal

Methods

foldMapP :: forall (m :: k) (s :: k) (a :: k). Monoid m => BesideSum p1 p2 s a -> (a ~> m) -> s ~> m Source Github #

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

Defined in Proarrow.Optic.Fold

Methods

foldMapP :: forall (m :: k) (s :: k) (a :: k). Monoid m => Corep (Coproduct t) s a -> (a ~> m) -> s ~> m Source Github #

Comonoid m => FoldFl (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) with a comonoid residual m (legs s ~> m ** a, m ** b ~> t) is a (monoidal) traversal witness. It folds by discarding the residual with the counit, and distributes a StrongDistributiveProfunctor by its own strength act @Tensor, so neither product strength nor tensor = product is needed. Only m must be a Comonoid, so this works in LINEAR for the duplicable objects. It is also the monoidal-lens witness (Proarrow.Optic.MonoidalLens).

Instance details

Defined in Proarrow.Optic.Traversal

Methods

foldMapP :: forall (m0 :: k) (s :: k) (a :: k). Monoid m0 => Rep (ActionAt (Tensor :: k -> (k, k) -> Type) m) s a -> (a ~> m0) -> s ~> m0 Source Github #

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

Defined in Proarrow.Optic.Fold

Methods

foldMapP :: forall (m :: k) (s :: k) (a :: k). Monoid m => Rep (Coproduct t) s a -> (a ~> m) -> s ~> m Source Github #

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

Defined in Proarrow.Optic.Fold

Methods

foldMapP :: forall (m :: k) (s0 :: k) (a :: k). Monoid m => Rep (Product s) s0 a -> (a ~> m) -> s0 ~> m Source Github #

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

Defined in Proarrow.Optic.Fold

Methods

foldMapP :: forall (m :: k) (s :: k) (a :: k). Monoid m => (f :.: f') s a -> (a ~> m) -> s ~> m Source Github #

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

foldMapOf :: forall {j} {k} (c :: (k -> j -> Type) -> Constraint) (m :: k) (s :: k) (t :: j) (a :: k) (b :: j). (CategoryOf j, CategoryOf k, Ob m, Monoid m, (Ob a, Ob b) => c (ExOptic (FoldFl :: (k +-> k) -> (j +-> j) -> Constraint) a b)) => Optic c s t a b -> (a ~> m) -> s ~> m Source Github #

Fold through any optic that can act as a fold, in either encoding: run it at its witness pair (ExOptic FoldFl, via withLegs) and apply foldMapP.

unfold :: forall {k} (c :: (OPPOSITE k -> OPPOSITE k -> Type) -> Constraint) (cm :: k) (s :: k) (t :: k) (a :: k) (b :: k). (Comonoid cm, Ob cm, forall (p :: OPPOSITE k +-> OPPOSITE k). c p => c (Op (UnOp p)), (Ob a, Ob b) => c (ExOptic (FoldFl :: (OPPOSITE k +-> OPPOSITE k) -> (OPPOSITE k +-> OPPOSITE k) -> Constraint) ('OP b) ('OP a))) => Optic (OpConstraint c) s t a b -> (cm ~> b) -> cm ~> t Source Github #

Unfold t from a Comonoid seed cm through the b-foci. It is foldMapOf run in OPPOSITE k, where Monoid becomes Comonoid and consumption becomes construction.