SimpleLens

dev.constructive.eo.optics.SimpleLens
See theSimpleLens companion object
final class SimpleLens[S, A, XA](get: S => A, split: S => (XA, A), combine: (XA, A) => S) extends SplitCombineLens[S, S, A, A, XA]

Monomorphic split-combine lens (S = T, A = B). The matched source / target lets the to splitter double as the T => (X, A) evidence the mutation extensions need, so place / transfer land on the class body directly. Used by Lens.first, Lens.second, and the eo-generics lens[S](_.field) macro.

Attributes

Companion
object
Source
Lens.scala
Graph
Supertypes
class SplitCombineLens[S, S, A, A, XA]
trait CanFold[S, A]
trait CanModifyP[S, S, A, A]
trait CanGet[S, A]
trait Optic[S, S, A, A, Tuple2]
class Object
trait Matchable
class Any
Show all

Members list

Grouped members

Operations

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

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

Inherited types

type X = XA

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

Inherited from:
SplitCombineLens
Source
Lens.scala

Value members

Concrete methods

inline def place(a: A): S => S

Overwrite the focus in an already-built S — the class-level twin of the generic Optic.place extension, with the T => (X, A) evidence supplied by split.

Overwrite the focus in an already-built S — the class-level twin of the generic Optic.place extension, with the T => (X, A) evidence supplied by split.

Attributes

Source
Lens.scala
inline def transfer[C](f: C => A): S => C => S

Lift a C => A into a focus overwrite — the class-level twin of the generic Optic.transfer extension.

Lift a C => A into a focus overwrite — the class-level twin of the generic Optic.transfer extension.

Attributes

Source
Lens.scala

Inherited methods

inline def andThen[C, D, XI](inner: SplitCombineLens[A, A, C, D, XI]): SplitCombineLens[S, S, C, D, (XA, XI)]

Fused SplitCombineLens.andThen(SplitCombineLens) — pairs the two leftovers directly instead of routing through the generic AssociativeFunctor[Tuple2], so macro-derived lens chains (lens[Person](_.address).andThen(lens[Address](_.street))) compose into another concrete class: the composite keeps the fused read / write paths AND the capability mixins (CanGet / CanModifyP / CanFold) that let it be passed as evidence directly. inline so each compose site splices distinct lambdas per level — the same C2 recursive-inline-cap dodge as GetReplaceLens.andThen.

Fused SplitCombineLens.andThen(SplitCombineLens) — pairs the two leftovers directly instead of routing through the generic AssociativeFunctor[Tuple2], so macro-derived lens chains (lens[Person](_.address).andThen(lens[Address](_.street))) compose into another concrete class: the composite keeps the fused read / write paths AND the capability mixins (CanGet / CanModifyP / CanFold) that let it be passed as evidence directly. inline so each compose site splices distinct lambdas per level — the same C2 recursive-inline-cap dodge as GetReplaceLens.andThen.

Attributes

Inherited from:
SplitCombineLens
Source
Lens.scala
def andThen[C, IB, G[_, _]](inner: Optic[A, Unit, C, IB, G])(using rc: ReadCompose[Tuple2, G]): rc.Out[S, C]

ANY outer ∘ read-only inner — the inner is honestly one-way (T = Unit: a Getter, AffineFold, or Fold), so only the two READ sides matter and the composite collapses to the read-only join of their strengths via compose.ReadCompose (Getter / PickFold / ForgetFold).

ANY outer ∘ read-only inner — the inner is honestly one-way (T = Unit: a Getter, AffineFold, or Fold), so only the two READ sides matter and the composite collapses to the read-only join of their strengths via compose.ReadCompose (Getter / PickFold / ForgetFold).

A trait member (not an extension in the companion) deliberately: once a receiver is statically one of the fused concrete classes, its andThen member overloads enter resolution and Scala 3 never falls back to extension methods when they all fail — the collapse must be in the member overload set to be reachable without an expected-type ascription.

Only the inner's T is pinned to Unit; its B stays free (IB) even though read-only inners always have B = Unit. That keeps this overload strictly LESS specific than the same-carrier andThen above (which accepts every argument this one does whenever B = Unit at the receiver), so a same-carrier read-only ∘ read-only call resolves unambiguously to the AssociativeFunctor path and this one fires exactly on the cross-seam cells the generic member cannot type.

Attributes

Inherited from:
Optic
Source
Optic.scala
inline def andThen[C, D](o: Optic[A, A, C, D, Tuple2]): Optic[S, S, C, D, Tuple2]

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 foldMap[M](f: A => M)(s: S)(using Monoid[M]): M

Attributes

Inherited from:
SplitCombineLens
Source
Lens.scala
def from(pair: (XA, A)): S

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

Inherited from:
SplitCombineLens
Source
Lens.scala
def get(s: S): A

Attributes

Inherited from:
SplitCombineLens
Source
Lens.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
inline def modify(f: A => A): S => S

Attributes

Inherited from:
SplitCombineLens
Source
Lens.scala
inline override def replace(b: A): S => S

Attributes

Definition Classes
Inherited from:
SplitCombineLens
Source
Lens.scala
def to(s: S): (XA, 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

Inherited from:
SplitCombineLens
Source
Lens.scala