MendTearPrism

dev.constructive.eo.optics.MendTearPrism
final class MendTearPrism[S, T, A, B](val tear: S => Either[T, A], val mend: B => T) extends Optic[S, T, A, B, Either], CanGetOption[S, A], CanReverseGet[T, B], CanModifyP[S, T, A, B], CanFold[S, A]

Concrete Optic subclass storing tear (getOrModify) and mend (reverseGet) directly. The fused-andThen overloads pattern-match once and skip the generic AssociativeFunctor[Either] round-trip. All Prism.* constructors return this type.

Attributes

Source
Prism.scala
Graph
Supertypes
trait CanFold[S, A]
trait CanModifyP[S, T, A, B]
trait CanReverseGet[T, B]
trait CanGetOption[S, A]
trait Optic[S, T, A, B, Either]
class Object
trait Matchable
class Any
Show all

Members list

Grouped members

Operations

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

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 = T

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

Value members

Concrete methods

inline def andThen[C, D](inner: MendTearPrism[A, B, C, D]): MendTearPrism[S, T, C, D]

Fused Prism.andThen(Prism) — composed tear + mend = outer.mend ∘ inner.mend, no nested Either wrappers. Picked when both sides are statically MendTearPrism. inline so a deep prism chain splices distinct lambdas per level, under C2's recursive-inline cap (see Getter.andThen).

Fused Prism.andThen(Prism) — composed tear + mend = outer.mend ∘ inner.mend, no nested Either wrappers. Picked when both sides are statically MendTearPrism. inline so a deep prism chain splices distinct lambdas per level, under C2's recursive-inline cap (see Getter.andThen).

Attributes

Source
Prism.scala
def andThen[C, D](inner: BijectionIso[A, B, C, D]): MendTearPrism[S, T, C, D]

Fused Prism.andThen(Iso) — collapses the iso into the prism. Skips Composer[Direct, Either].

Fused Prism.andThen(Iso) — collapses the iso into the prism. Skips Composer[Direct, Either].

Attributes

Source
Prism.scala
def andThen[C, D](inner: PickMendPrism[A, C, D])(using ev: A =:= B): MendTearPrism[S, T, C, D]

Fused MendTearPrism.andThen(PickMendPrism) — outer mono in focus; produces the more general MendTearPrism shape (PickMendPrism's T = S invariant doesn't survive composition).

Fused MendTearPrism.andThen(PickMendPrism) — outer mono in focus; produces the more general MendTearPrism shape (PickMendPrism's T = S invariant doesn't survive composition).

Attributes

Source
Prism.scala
def andThen[C, D](inner: GetReplaceLens[A, B, C, D]): Optional[S, T, C, D]

Fused Prism.andThen(Lens) — prism may miss, lens focuses on hit. Result is Optional.

Fused Prism.andThen(Lens) — prism may miss, lens focuses on hit. Result is Optional.

Attributes

Source
Prism.scala
def andThen[C, D](inner: Optional[A, B, C, D]): Optional[S, T, C, D]

Fused Prism.andThen(Optional) — nested partial focuses.

Fused Prism.andThen(Optional) — nested partial focuses.

Attributes

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

Attributes

Source
Prism.scala
def from(e: Either[T, B]): T

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
Prism.scala
inline def getOption(s: S): Option[A]

Attributes

Source
Prism.scala
def mendFrom[B1](g: B1 => B): MendTearPrism[S, T, A, B1]

Pre-compose the mend's focus: write back a B1 that g turns into this prism's B. The other half of the input-side mapping pair — see tearFrom.

Pre-compose the mend's focus: write back a B1 that g turns into this prism's B. The other half of the input-side mapping pair — see tearFrom.

Attributes

Source
Prism.scala
inline def modify(f: A => B): S => T

Attributes

Source
Prism.scala
inline override def replace(b: B): S => T

Attributes

Definition Classes
Source
Prism.scala
inline def reverseGet(b: B): T

Attributes

Source
Prism.scala
def tearFrom[S1](f: S1 => S): MendTearPrism[S1, T, A, B]

Pre-compose the tear's source: read from an S1 that f turns into this prism's S. One half of the contravariant (input-side) mapping pair — T and A stay fixed (map those by composing an outer / inner iso instead). Returns the concrete MendTearPrism — unlike Optic.outerProfunctor / innerProfunctor, whose dimap erases to an anonymous Optic and drops the fused-compose / capability surface. Sibling: mendFrom.

Pre-compose the tear's source: read from an S1 that f turns into this prism's S. One half of the contravariant (input-side) mapping pair — T and A stay fixed (map those by composing an outer / inner iso instead). Returns the concrete MendTearPrism — unlike Optic.outerProfunctor / innerProfunctor, whose dimap erases to an anonymous Optic and drops the fused-compose / capability surface. Sibling: mendFrom.

Attributes

Source
Prism.scala
def to(s: S): Either[T, 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
Prism.scala

Inherited methods

def andThen[C, IB, G[_, _]](inner: Optic[A, Unit, C, IB, G])(using rc: ReadCompose[Either, 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, B, C, D, Either]): Optic[S, T, C, D, Either]

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 mend: B => T

Attributes

Source
Prism.scala
val tear: S => Either[T, A]

Attributes

Source
Prism.scala