Getter

dev.constructive.eo.optics.Getter
See theGetter companion object
final class Getter[S, A](read: S => A) extends Optic[S, Unit, A, Unit, Direct], CanGet[S, A], CanFold[S, A]

Concrete Optic subclass for a read-only getter. A final class storing get directly — NOT an abstract class with an abstract get: the CI A/B showed composed-getter dispatch through the abstract-class form costs ~1.8x (eoGet_3 5.1ns final vs 11.5ns abstract) even with a fused andThen, while every fused path that stayed a concrete class (GetReplaceLens lens-reuse) was flat. The hot path skips the Accessor[Direct] dispatch the generic extension would perform — the same shape as BijectionIso / GetReplaceLens. Returned by Getter.apply so hand-written getters pick up the fused path automatically.

Attributes

Companion
object
Source
Getter.scala
Graph
Supertypes
trait CanFold[S, A]
trait CanGet[S, A]
trait Optic[S, Unit, A, Unit, Direct]
class Object
trait Matchable
class Any
Show all

Members list

Grouped members

Operations

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

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

Value members

Concrete methods

inline def andThen[B](inner: Getter[A, B]): Getter[S, B]

Fused Getter.andThen(Getter) — composes the read functions; the vestigial Unit write path needs no threading.

Fused Getter.andThen(Getter) — composes the read functions; the vestigial Unit write path needs no threading.

inline so each composition call site splices its own copy of the s => inner.get(get(s)) lambda, yielding a distinct synthetic method per level. A plain def compiles the lambda once (andThen$$anonfun$1), so a depth-N runtime chain reuses that one bytecode and C2 treats the .get cascade as recursion — capping inlining at MaxRecursiveInlineLevel and leaving the deep tail as virtual Function1.apply. Distinct per-level methods sidestep that cap with no JVM flag, the same way Monocle's per-compose anonymous classes do.

Attributes

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

Read-only outer ∘ ANY inner — a Getter only reads, so the inner's write side is irrelevant and the composite is the read-only join via compose.ReadCompose (Getter when the inner reads totally, PickFold when partially, ForgetFold when it has many foci). This member covers the writable inners (getter ∘ lens / prism / optional / traversal) that the trait's read-only-inner overload cannot reach; the fused andThen(Getter) / andThen(PickFold) members above stay as the more-specific fast paths.

Read-only outer ∘ ANY inner — a Getter only reads, so the inner's write side is irrelevant and the composite is the read-only join via compose.ReadCompose (Getter when the inner reads totally, PickFold when partially, ForgetFold when it has many foci). This member covers the writable inners (getter ∘ lens / prism / optional / traversal) that the trait's read-only-inner overload cannot reach; the fused andThen(Getter) / andThen(PickFold) members above stay as the more-specific fast paths.

Attributes

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

Override of the trait's read-only-inner overload, re-homed in this class so it shares an owner with andThenReadAny above — otherwise a read-only inner is ambiguous between the two (the trait one wins on signature specificity, the class one on owner derivation, and dotty calls the split a tie). Same ReadCompose route either way.

Override of the trait's read-only-inner overload, re-homed in this class so it shares an owner with andThenReadAny above — otherwise a read-only inner is ambiguous between the two (the trait one wins on signature specificity, the class one on owner derivation, and dotty calls the split a tie). Same ReadCompose route either way.

Attributes

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

Attributes

Source
Getter.scala
def from(d: Direct[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
Getter.scala
def get(s: S): A

Attributes

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

Inherited methods

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

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