Traversal

dev.constructive.eo.optics.Traversal
object Traversal

Constructors for Traversal. Every constructor here — each / pEach / selfChildren and the two / three / four fixed-arity variants — rides the MultiFocus[PSVec] carrier, so they all compose through the standard .andThen in both directions (past a Lens, a Prism, another traversal, …).

Attributes

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

Members list

Grouped members

Constructors

def each[T[_] : Traverse, A]: Optic[T[A], T[A], A, A, MultiFocus[PSVec]]

Monomorphic Traversal over Traverse[T]S = T = T[A], focus preserved.

Monomorphic Traversal over Traverse[T]S = T = T[A], focus preserved.

Attributes

Source
Traversal.scala
def pEach[T[_] : Traverse, A, B]: Optic[T[A], T[B], A, B, MultiFocus[PSVec]]

Polymorphic counterpart to each — allows focus type change.

Polymorphic counterpart to each — allows focus type change.

Reassembly walks the original container with Functor.map plus a captured positional var — equivalent to Traverse.mapAccumulate but without the State thunk chain (the dominant CPU cost on profiled nested traversals). For ArraySeq the .from body bypasses Traverse[ArraySeq].map entirely (which threads through StrictOptimizedSeqOps → non-devirtualised SeqOps.size$, observed as 18% CPU), instead wrapping the focus vector directly via ArraySeq.unsafeWrapArray.

Attributes

Source
Traversal.scala
def selfChildren[S](children: S => PSVec[S], rebuild: (S, PSVec[S]) => S): Optic[S, S, S, S, MultiFocus[PSVec]]

Monomorphic self-traversal from an explicit immediate-children view — focuses the values of S that are themselves S (the immediate sub-terms), with S itself as the leftover skeleton. children(s) is the immediate children as a focus vector; rebuild(s, vec) reassembles s with that same number of children swapped in (same order). The two must agree on arity and order: rebuild(s, children(s)) == s.

Monomorphic self-traversal from an explicit immediate-children view — focuses the values of S that are themselves S (the immediate sub-terms), with S itself as the leftover skeleton. children(s) is the immediate children as a focus vector; rebuild(s, vec) reassembles s with that same number of children swapped in (same order). The two must agree on arity and order: rebuild(s, children(s)) == s.

PSVec-native: to / from pass the PSVec straight through, so both the read path (Plated.children / universe, which read to(s)._2) and the write path (Plated.transform / rewrite, which traverse and rebuild through the carrier) avoid any ListPSVec conversion. This is the carrier behind Plated — a recursive ADT's plate. Unlike each / pEach there is no container T[_]; the children of a node are gathered case-by-case, and the variable arity across cases (a binary node has two children, a leaf none) is exactly the PSVec shape.

Attributes

Source
Traversal.scala
def two[S, T, A, B](a: S => A, b: S => A, reverse: (B, B) => T): Optic[S, T, A, B, MultiFocus[PSVec]]

Traversal over two per-element getters with a reverse reassembly. The arity is known at construction time, so the foci tabulate straight into the MultiFocus[PSVec] carrier and the result composes like any other traversal — past each, a Lens, a Prism, or another fixed-arity hop. reverse sees only the (modified) foci: the constructor is full-cover, so any leftover context of S must be rebuilt by reverse itself (drill with a Lens first when there are sibling fields). For the Grate-shaped Int => A encoding, see MultiFocus.tuple.

Traversal over two per-element getters with a reverse reassembly. The arity is known at construction time, so the foci tabulate straight into the MultiFocus[PSVec] carrier and the result composes like any other traversal — past each, a Lens, a Prism, or another fixed-arity hop. reverse sees only the (modified) foci: the constructor is full-cover, so any leftover context of S must be rebuilt by reverse itself (drill with a Lens first when there are sibling fields). For the Grate-shaped Int => A encoding, see MultiFocus.tuple.

Attributes

Source
Traversal.scala

Value members

Concrete methods

def four[S, T, A, B](a: S => A, b: S => A, c: S => A, d: S => A, reverse: (B, B, B, B) => T): Optic[S, T, A, B, MultiFocus[PSVec]]

Fixed-arity-4 — see two. @group Constructors

Fixed-arity-4 — see two. @group Constructors

Attributes

Source
Traversal.scala
def three[S, T, A, B](a: S => A, b: S => A, c: S => A, reverse: (B, B, B) => T): Optic[S, T, A, B, MultiFocus[PSVec]]

Fixed-arity-3 — see two. @group Constructors

Fixed-arity-3 — see two. @group Constructors

Attributes

Source
Traversal.scala