Lens

dev.constructive.eo.optics.Lens
object Lens

Constructors for Lens — the always-present single-focus optic, backed by Tuple2. "A Lens[S, A]" is prose shorthand for Optic[S, S, A, A, Tuple2]: there is deliberately NO type Lens[S, A] alias to ascribe (Lens is only this constructor object). The reason is keeping code on the hot, fused paths: TWO concrete classes back this family — GetReplaceLens here, SimpleLens from first / second and the eo-generics macro — so an alias could only name the generic Optic[S, S, A, A, Tuple2], and ascribing that erases the concrete class, dropping its fused compose overloads and capability mixins in favour of generic typeclass dispatch. (Contrast Iso, whose single concrete class does get an alias.) So leave vals un-ascribed and let consuming signatures demand a capability (CanGet[S, A], CanModify[S, A], …) instead of a concrete optic type. A lens reads a field via get(s) and rewrites it via modify / replace. The eo-generics module's lens[S](_.field) macro derives both.

Attributes

Source
Lens.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Lens.type

Members list

Grouped members

Constructors

def apply[S, A](get: S => A, enplace: (S, A) => S): GetReplaceLens[S, S, A, A]

Monomorphic constructor (S = T, A = B).

Monomorphic constructor (S = T, A = B).

Attributes

Example
case class Person(name: String, age: Int)
val ageL = Lens[Person, Int](_.age, (p, a) => p.copy(age = a))
Source
Lens.scala
def curried[S, A](get: S => A, replace: A => S => S): GetReplaceLens[S, S, A, A]

Curried variant — accepts replace: A => S => S instead of (S, A) => S.

Curried variant — accepts replace: A => S => S instead of (S, A) => S.

Attributes

Source
Lens.scala
def first[A, B]: SimpleLens[(A, B), A, B]

Lens focusing the first element of a Tuple2. Returns a SimpleLens so place / transfer / transform land without extra evidence (S = T, A = B).

Lens focusing the first element of a Tuple2. Returns a SimpleLens so place / transfer / transform land without extra evidence (S = T, A = B).

Attributes

Source
Lens.scala
def pCurried[S, T, A, B](get: S => A, replace: B => S => T): GetReplaceLens[S & B, T, A, S]

Polymorphic counterpart to curried.

Polymorphic counterpart to curried.

Attributes

Source
Lens.scala
def pLens[S, T, A, B](get: S => A, enplace: (S, B) => T): GetReplaceLens[S, T, A, B]

Polymorphic constructor — allows S and T to differ.

Polymorphic constructor — allows S and T to differ.

Attributes

Source
Lens.scala
def representable[F[_], A](using R: Representable[F])(r: R.Representation): GetReplaceLens[F[A], F[A], A, A]

Representable[F] (F[A] ≅ Representation => A) as a lawful Lens into ONE position: get = index(fa)(r), and the write rebuilds via tabulate with every other position read back from the original — siblings survive, all three Lens laws hold. A Lens into a function's value at a point, or position r of any tabulated shape — the one optic no whole-container bridge (Traversal.each, Modify.functor, data.MultiFocus.representable) can produce.

Representable[F] (F[A] ≅ Representation => A) as a lawful Lens into ONE position: get = index(fa)(r), and the write rebuilds via tabulate with every other position read back from the original — siblings survive, all three Lens laws hold. A Lens into a function's value at a point, or position r of any tabulated shape — the one optic no whole-container bridge (Traversal.each, Modify.functor, data.MultiFocus.representable) can produce.

Lawful provided == is meaningful on Representation (it keys the rebuild).

Attributes

Source
Lens.scala
def second[A, B]: SimpleLens[(A, B), B, A]

Lens focusing the second element of a Tuple2.

Lens focusing the second element of a Tuple2.

Attributes

Source
Lens.scala