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