ForgetFold

dev.constructive.eo.optics.ForgetFold
final class ForgetFold[S, F[_], A](val read: S => F[A])(using FF: Foldable[F]) extends Optic[S, Unit, A, Unit, Forget[F]], CanFold[S, A]

Concrete Optic subclass for Fold, storing the source projection to and the underlying Foldable[F] directly. This lets the terminal foldMap fold the focus eagerly through the captured Foldable[F], skipping both the per-call ForgetfulFold[Forget[F]] summon and the intermediate S => M closure the generic Optic.foldMap extension builds — the same specialisation GetReplaceLens / Modify / MultiFocusSingleton apply to their hot paths.

Returned by every Fold.* constructor so hand-written folds pick up the fast path automatically. A composed Fold (the result of .andThen) surfaces as the erased Optic[…, Forget[F]] and keeps the generic extension — the same trade-off GetReplaceLens accepts.

Attributes

Source
Fold.scala
Graph
Supertypes
trait CanFold[S, A]
trait Optic[S, Unit, A, Unit, Forget[F]]
class Object
trait Matchable
class Any

Members list

Grouped members

Operations

inline def cross[C, D](o: Optic[Unit, S, C, D, Forget[F]])(using Accessor[Forget[F]], ReverseAccessor[Forget[F]]): Optic[Unit, A, C, D, Forget[F]]

Build-then-observe across the build-output ⇄ read-input seam, preserving structure, on a shared carrier F. Flip self (it must be reversible — Accessor[F] and ReverseAccessor[F], i.e. an Iso or Review over Direct) so it reads T from B, then andThen that under the same carrier. The result is the full Optic[B, A, C, D, F], not a collapsed getter: its read capability follows the carrier (.get for Direct), and self's read focus A survives as the composite's write-back focus.

Build-then-observe across the build-output ⇄ read-input seam, preserving structure, on a shared carrier F. Flip self (it must be reversible — Accessor[F] and ReverseAccessor[F], i.e. an Iso or Review over Direct) so it reads T from B, then andThen that under the same carrier. The result is the full Optic[B, A, C, D, F], not a collapsed getter: its read capability follows the carrier (.get for Direct), and self's read focus A survives as the composite's write-back focus.

This is exactly self.reverse.andThen(that). The motivating case is ana.cross(cata): a Review (the unfold) crossed with a getter on the built S (the fold) — a (materializing) hylomorphism whose .get reads the folded value. When that sits on a different carrier (a Prism, a Fold, …), the cross-carrier cross overload below is selected instead.

Seam: that's source is self's T and its back-type is self's S.

Attributes

Inherited from:
Optic
Source
Optic.scala

Type members

Types

type X = Nothing

Existential leftover carried alongside the focus — the type-level witness the carrier uses to rebuild T. Concrete at construction (Lens.apply sets X = S, Prism.apply sets X = S, …) and abstract when the optic is bound to Optic[…, F] without refinement.

Existential leftover carried alongside the focus — the type-level witness the carrier uses to rebuild T. Concrete at construction (Lens.apply sets X = S, Prism.apply sets X = S, …) and abstract when the optic is bound to Optic[…, F] without refinement.

Attributes

Source
Fold.scala

Value members

Concrete methods

def andThen[C](inner: ForgetFold[A, F, C])(using FM: FlatMap[F]): ForgetFold[S, F, C]

Fused Fold.andThen(Fold) — same-carrier flatMap (read(s).flatMap(inner.read)); the read-only-triple join cell for the many rung. Being the most specific overload, it resolves the otherwise-ambiguous fold ∘ fold (a read-only outer where the structure-preserving and read-collapse trait members both match a read-only inner). Requires FlatMap[F], exactly as the generic assocForgetMonad path did.

Fused Fold.andThen(Fold) — same-carrier flatMap (read(s).flatMap(inner.read)); the read-only-triple join cell for the many rung. Being the most specific overload, it resolves the otherwise-ambiguous fold ∘ fold (a read-only outer where the structure-preserving and read-collapse trait members both match a read-only inner). Requires FlatMap[F], exactly as the generic assocForgetMonad path did.

Attributes

Source
Fold.scala
def andThen[C, IT, IB, FI[_, _]](inner: Optic[A, IT, C, IB, FI])(using rc: ReadCompose[Forget[F], FI]): rc.Out[S, C]

Read-only outer ∘ ANY inner — a Fold only reads (many), so the inner's write side is irrelevant and the composite is always a ForgetFold (many ∘ anything = many) via compose.ReadCompose. Covers the writable inners (fold ∘ lens / prism / optional / traversal); the fused same-F andThen above stays as the more-specific fast path.

Read-only outer ∘ ANY inner — a Fold only reads (many), so the inner's write side is irrelevant and the composite is always a ForgetFold (many ∘ anything = many) via compose.ReadCompose. Covers the writable inners (fold ∘ lens / prism / optional / traversal); the fused same-F andThen above stays as the more-specific fast path.

Attributes

Source
Fold.scala
override def andThen[C, IB, G[_, _]](inner: Optic[A, Unit, C, IB, G])(using rc: ReadCompose[Forget[F], G]): rc.Out[S, C]

Override of the trait's read-only-inner overload, re-homed here so it shares an owner with andThenReadAny above — see Getter's twin override for the ambiguity rationale.

Override of the trait's read-only-inner overload, re-homed here so it shares an owner with andThenReadAny above — see Getter's twin override for the ambiguity rationale.

Attributes

Definition Classes
Source
Fold.scala
def foldMap[M](f: A => M)(s: S)(using Monoid[M]): M

Eager foldMap — folds s straight through the captured Foldable[F], returning M with no intermediate S => M closure and no ForgetfulFold summon. Wins over the Optic.foldMap extension by member precedence whenever the receiver is statically a ForgetFold; the call shape (fold.foldMap(f)(s)) is identical, so this is a transparent drop-in.

Eager foldMap — folds s straight through the captured Foldable[F], returning M with no intermediate S => M closure and no ForgetfulFold summon. Wins over the Optic.foldMap extension by member precedence whenever the receiver is statically a ForgetFold; the call shape (fold.foldMap(f)(s)) is identical, so this is a transparent drop-in.

Attributes

Source
Fold.scala
def from(u: Forget[F][X, Unit]): Unit

Close the carrier: given a modified focus B (and the leftover X already inside the F), reassemble the result T.

Close the carrier: given a modified focus B (and the leftover X already inside the F), reassemble the result T.

Attributes

Source
Fold.scala
def to(s: S): Forget[F][X, A]

Push the source S into the carrier, extracting the focus A and packing the leftover X. Paired with from to reconstruct T.

Push the source S into the carrier, extracting the focus A and packing the leftover X. Paired with from to reconstruct T.

Attributes

Source
Fold.scala

Inherited methods

inline def andThen[C, D](o: Optic[A, Unit, C, D, Forget[F]]): Optic[S, Unit, C, D, Forget[F]]

Compose with another optic under the shared carrier F. Requires AssociativeFunctor[F]. Cross-carrier composition (Lens → Optional, Lens → Traversal, …) goes through the Morph-summoning overload of this same method.

Compose with another optic under the shared carrier F. Requires AssociativeFunctor[F]. Cross-carrier composition (Lens → Optional, Lens → Traversal, …) goes through the Morph-summoning overload of this same method.

Attributes

Example
case class Address(street: String)
case class Person(address: Address)
val streetLens = lens[Person](_.address).andThen(lens[Address](_.street))
Inherited from:
Optic
Source
Optic.scala
def exists(p: A => Boolean)(s: S): Boolean

Attributes

Inherited from:
CanFold
Source
CanFold.scala
def foci(s: S): List[A]

Attributes

Inherited from:
CanFold
Source
CanFold.scala
def headOption(s: S): Option[A]

Attributes

Inherited from:
CanFold
Source
CanFold.scala
def length(s: S): Int

Attributes

Inherited from:
CanFold
Source
CanFold.scala

Concrete fields

val read: S => F[A]

Attributes

Source
Fold.scala