Index

dev.constructive.eo.optics.Index
object Index

Monocle's Index as a plain constructor object — NOT a typeclass. Index(i) / Index(k) builds an ordinary Optional focusing one positional or keyed slot; there is no Index[S, I, A] typeclass to instance. Monocle index semantics hold: the focus is the slot's CURRENT value, so a write on an absent slot (index out of bounds, key missing) is a silent pass-through — Index never inserts. For insert-or-update-or-delete on a Map, use At, whose focus is the Option[V].

Bare Index(0) cannot pick between the sequence and map overloads on its own — supply the type arguments (Index[Vector, Int](0), Index[String, Long]("k")) or let .andThen composition pin the source type.

Attributes

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

Members list

Grouped members

Constructors

def apply[CC <: ([X] =>> SeqOps[X, CC, CC[X]]), A](i: Int): Optional[CC[A], CC[A], A, A]

Optional focusing the i-th element of an immutable sequence (List, Vector, …). Out of bounds (or negative i) is a miss: reads see nothing, writes pass through.

Optional focusing the i-th element of an immutable sequence (List, Vector, …). Out of bounds (or negative i) is a miss: reads see nothing, writes pass through.

Attributes

Example
val second = Index[Vector, Int](1)
second.getOption(Vector(1, 2, 3))    // Some(2)
second.replace(9)(Vector(1, 2, 3))   // Vector(1, 9, 3)
second.replace(9)(Vector.empty[Int]) // Vector() — no insert
Source
Index.scala
def apply[K, V](k: K): Optional[Map[K, V], Map[K, V], V, V]

Optional focusing the value at key k of a Map. A missing key is a miss: reads see nothing, writes pass through (no insert — that is At's job).

Optional focusing the value at key k of a Map. A missing key is a miss: reads see nothing, writes pass through (no insert — that is At's job).

Attributes

Example
val port = Index[String, Int]("port")
port.getOption(Map("port" -> 80))  // Some(80)
port.replace(8080)(Map.empty)      // Map() — no insert
Source
Index.scala