The conditionally-present single-focus optic over the Affine carrier. Every operation tears the source ONCE: getOrModify / getOption / foldMap read without building anything a write would need, modify / replace tear once and rebuild from what they tore, and the carrier pair to / from keeps what the read computed — the existential intermediate M — so a generic write through to / from never tears S a second time either.
Two implementations, both private: Optional.apply (hand-written getOrModify + reverseGet; M = S, the source is all the user's reverseGet needs) and the fused compositions (prism.andThen(lens), optional.andThen(optional), …), whose M is whatever the outer step already produced — a prism ∘ lens keeps the decoded domain value, so writing back re-uses it instead of decoding again, and a nested chain keeps a tuple of its levels' intermediates.
Fused .andThen overloads skip the generic AssociativeFunctor[Affine] round-trip whenever the other side is a known concrete class.
Attributes
- Companion
- object
- Source
- Optional.scala
- Graph
-
- Supertypes
-
trait Serializableclass Objecttrait Matchableclass AnyShow all
Members list
Grouped members
Operations
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
What a hit keeps for the write: the part of the read the rebuild needs.
What a hit keeps for the write: the part of the read the rebuild needs.
Attributes
- Source
- Optional.scala
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
- Optional.scala
Value members
Abstract methods
The read: Right(a) on a hit, Left(t) (the pass-through T) on a miss.
The read: Right(a) on a hit, Left(t) (the pass-through T) on a miss.
Attributes
- Source
- Optional.scala
Write b back from what a hit kept — never re-reads S.
Concrete methods
Fused Optional.andThen(Optional) — two partial focuses compose into another. An inner miss lifts the inner's leftover back through the outer's rebuild (the outer's own intermediate, not a re-read). inline so a deep optional.andThen(optional)… chain splices distinct lambdas per level, under C2's recursive-inline cap (see Getter.andThen).
Fused Optional.andThen(Optional) — two partial focuses compose into another. An inner miss lifts the inner's leftover back through the outer's rebuild (the outer's own intermediate, not a re-read). inline so a deep optional.andThen(optional)… chain splices distinct lambdas per level, under C2's recursive-inline cap (see Getter.andThen).
Attributes
- Source
- Optional.scala
Fused Optional.andThen(Lens) — always-present inner inside a partial outer. Stays partial; the write keeps the outer's intermediate and the outer focus the lens writes into.
Fused Optional.andThen(Lens) — always-present inner inside a partial outer. Stays partial; the write keeps the outer's intermediate and the outer focus the lens writes into.
Attributes
- Source
- Optional.scala
Fused Optional.andThen(Prism) — outer Optional's hit fed into a Prism; an inner miss lifts the prism's leftover through the outer's rebuild.
Fused Optional.andThen(Prism) — outer Optional's hit fed into a Prism; an inner miss lifts the prism's leftover through the outer's rebuild.
Attributes
- Source
- Optional.scala
Fused Optional.andThen(Iso) — iso is transparent; threads through the Optional's shape.
Fused Optional.andThen(Iso) — iso is transparent; threads through the Optional's shape.
Attributes
- Source
- Optional.scala
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
- Optional.scala
Attributes
- Source
- Optional.scala
inline, like GetReplaceLens.modify: optional.modify(f)(s) reduces to modifyAt(s, f).
inline, like GetReplaceLens.modify: optional.modify(f)(s) reduces to modifyAt(s, f).
Attributes
- Source
- Optional.scala
One tear, then rebuild: the write behind modify / replace, taking the source directly so a modify(f)(s) call site allocates no S => T closure (modify is inline). Fused compositions override it with a kernel that builds no carrier at all.
One tear, then rebuild: the write behind modify / replace, taking the source directly so a modify(f)(s) call site allocates no S => T closure (modify is inline). Fused compositions override it with a kernel that builds no carrier at all.
Attributes
- Source
- Optional.scala
Attributes
- Definition Classes
- Source
- Optional.scala
Write b back into s: one tear, then rebuild; a miss passes s's T through. Optional.apply's optics call the user's reverseGet directly instead.
Write b back into s: one tear, then rebuild; a miss passes s's T through. Optional.apply's optics call the user's reverseGet directly instead.
Attributes
- Source
- Optional.scala
Inherited methods
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
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
Attributes
- Inherited from:
- CanFold
- Source
- CanFold.scala
Attributes
- Inherited from:
- CanFold
- Source
- CanFold.scala
Attributes
- Inherited from:
- CanFold
- Source
- CanFold.scala
Attributes
- Inherited from:
- CanFold
- Source
- CanFold.scala