PickFold

dev.constructive.eo.optics.PickFold
final class PickFold[S, A](val pick: S => Option[A]) extends Optic[S, Unit, A, Unit, Affine], CanGetOption[S, A], CanFold[S, A]

Concrete Optic subclass for AffineFold — a final class storing pick directly, NOT a shared anonymous wrapper: a single anon class would host one pick.apply bytecode site for every AffineFold instance, the megamorphic-dispatch trap PrintInlining exposed on the abstract-class Getter (the JIT profiles that one site over all instances' lambdas and gives up inlining). Same storage shape as PickMendPrism (pick) and ForgetFold (read). Returned by AffineFold.apply / AffineFold.select so hand-written affine folds pick up the fused members automatically.

Attributes

Source
AffineFold.scala
Graph
Supertypes
trait CanFold[S, A]
trait CanGetOption[S, A]
trait Optic[S, Unit, A, Unit, Affine]
class Object
trait Matchable
class Any
Show all

Members list

Grouped members

Operations

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

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 = (Unit, Unit)

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
AffineFold.scala

Value members

Concrete methods

inline def andThen[C](inner: PickFold[A, C]): PickFold[S, C]

Fused AffineFold.andThen(AffineFold)flatMaps the picks; no Affine wrappers, no Morph. inline so each compose site splices its own lambda (per-site monomorphic dispatch — see Getter.andThen).

Fused AffineFold.andThen(AffineFold)flatMaps the picks; no Affine wrappers, no Morph. inline so each compose site splices its own lambda (per-site monomorphic dispatch — see Getter.andThen).

Attributes

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

Read-only outer ∘ ANY inner — a PickFold only reads (partially), so the inner's write side is irrelevant and the composite is the read-only join via compose.ReadCompose (PickFold unless the inner has many foci, then ForgetFold). Covers the writable inners (affineFold ∘ lens / prism / optional / traversal); the fused andThen(Getter) / andThen(PickFold) members above stay as the more-specific fast paths.

Read-only outer ∘ ANY inner — a PickFold only reads (partially), so the inner's write side is irrelevant and the composite is the read-only join via compose.ReadCompose (PickFold unless the inner has many foci, then ForgetFold). Covers the writable inners (affineFold ∘ lens / prism / optional / traversal); the fused andThen(Getter) / andThen(PickFold) members above stay as the more-specific fast paths.

Attributes

Source
AffineFold.scala
override def andThen[C, IB, G[_, _]](inner: Optic[A, Unit, C, IB, G])(using rc: ReadCompose[Affine, 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
AffineFold.scala
def foldMap[M](f: A => M)(s: S)(using M: Monoid[M]): M

Attributes

Source
AffineFold.scala
def from(a: Affine[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
AffineFold.scala
inline def getOption(s: S): Option[A]

Fused getOption — reads pick directly, skipping the Affine carrier round-trip the generic extension performs. Wins over the extension by member precedence at static type.

Fused getOption — reads pick directly, skipping the Affine carrier round-trip the generic extension performs. Wins over the extension by member precedence at static type.

Attributes

Source
AffineFold.scala
def to(s: S): Affine[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
AffineFold.scala

Inherited methods

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

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 pick: S => Option[A]

Attributes

Source
AffineFold.scala