DynamicOptic

zio.blocks.schema.DynamicOptic
See theDynamicOptic companion object
case class DynamicOptic(nodes: IndexedSeq[Node])

An untyped path into a value: a sequence of DynamicOptic.Node steps, such as a field, a case, an index, a map key or every element. A typed Optic turns into one with Optic#toDynamic. The DynamicValue operations (get, modify, set, delete, insert) take one, Reflect#get navigates a schema with one, and SchemaError and OpticCheck use them to say where a problem is.

Build a path from DynamicOptic.root with the builder methods, or with the p"..." interpolator, which checks the syntax at compile time. toString renders the path in the interpolator syntax (.books[0].title), and toScalaString in the syntax of the optic macros (.books.at(0).title), which error messages use. The companion's schema makes paths serializable.

val path = DynamicOptic.root.field("books").at(0).field("title")

path.toString              // .books[0].title
path.toScalaString         // .books.at(0).title
path == p".books[0].title" // true

Attributes

See also
Companion
object
Source
DynamicOptic.scala
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

Returns this path followed by the steps of that.

Returns this path followed by the steps of that.

Attributes

Source
DynamicOptic.scala
def apply[F[_, _], A](reflect: Reflect[F, A]): Option[Reflect[F, _]]

Returns the schema node that this path leads to inside reflect, or None when a step does not fit, such as a field that the record does not have. An index step leads to the element schema and a key step to the value schema, whatever the index or key; a search step leads to the first matching node. The same as reflect.get(this).

Returns the schema node that this path leads to inside reflect, or None when a step does not fit, such as a field that the record does not have. An index step leads to the element schema and a key step to the value schema, whatever the index or key; a search step leads to the first matching node. The same as reflect.get(this).

Attributes

Source
DynamicOptic.scala
def at(index: Int): DynamicOptic

Appends a step to the sequence element at index.

Appends a step to the sequence element at index.

Attributes

Source
DynamicOptic.scala
def atIndices(indices: Int*): DynamicOptic

Appends a step to the sequence elements at indices, kept in the order given.

Appends a step to the sequence elements at indices, kept in the order given.

Attributes

Source
DynamicOptic.scala
def atKey[K](key: K)(implicit schema: Schema[K]): DynamicOptic

Appends a step to the map value at key. The key is stored as a DynamicValue, converted with schema.

Appends a step to the map value at key. The key is stored as a DynamicValue, converted with schema.

Attributes

Source
DynamicOptic.scala
def atKeys[K](keys: K*)(implicit schema: Schema[K]): DynamicOptic

Appends a step to the map values at keys, each stored as a DynamicValue converted with schema.

Appends a step to the map values at keys, each stored as a DynamicValue converted with schema.

Attributes

Source
DynamicOptic.scala
def caseOf(name: String): DynamicOptic

Appends a step to the variant case name.

Appends a step to the variant case name.

Attributes

Source
DynamicOptic.scala

Appends a step to every element of a sequence.

Appends a step to every element of a sequence.

Attributes

Source
DynamicOptic.scala
def field(name: String): DynamicOptic

Appends a step to the record field name.

Appends a step to the record field name.

Attributes

Source
DynamicOptic.scala

Appends a step to every key of a map.

Appends a step to every key of a map.

Attributes

Source
DynamicOptic.scala

Appends a step to every value of a map.

Appends a step to every value of a map.

Attributes

Source
DynamicOptic.scala
def search[A](implicit typeId: TypeId[A]): DynamicOptic

Appends a step that searches for every value of the nominal type A, identified by its TypeId.

Appends a step that searches for every value of the nominal type A, identified by its TypeId.

Attributes

Source
DynamicOptic.scala

Appends a step that searches for every value that matches the schema pattern schemaRepr. The # steps of p"..." build this kind of step.

Appends a step that searches for every value that matches the schema pattern schemaRepr. The # steps of p"..." build this kind of step.

Attributes

Source
DynamicOptic.scala

Appends a step to the value inside a wrapper.

Appends a step to the value inside a wrapper.

Attributes

Source
DynamicOptic.scala

Inherited methods

def productElementNames: Iterator[String]

An iterator over the names of all the elements of this product.

An iterator over the names of all the elements of this product.

Attributes

Inherited from:
Product
Source
Product.scala
def productIterator: Iterator[Any]

An iterator over all the elements of this product.

An iterator over all the elements of this product.

Attributes

Returns

in the default implementation, an Iterator[Any]

Inherited from:
Product
Source
Product.scala

Concrete fields

lazy val toScalaString: String

Renders this path in the syntax of the optic macros, as error messages do: .name, .when[Case], .at(0), .atIndices(0, 2), .atKey("key"), .atKeys("a", "b"), .each, .eachKey, .eachValue, .wrapped, .search[Type] and .searchSchema(pattern), and . for the empty path.

Renders this path in the syntax of the optic macros, as error messages do: .name, .when[Case], .at(0), .atIndices(0, 2), .atKey("key"), .atKeys("a", "b"), .each, .eachKey, .eachValue, .wrapped, .search[Type] and .searchSchema(pattern), and . for the empty path.

Attributes

Source
DynamicOptic.scala
lazy override val toString: String

Renders this path in the syntax of the p"..." interpolator: .name for a field, `` for a case, [0] and [0,2] for indices, [*] for every element, {"key"} and {"a", "b"} for map keys, {*} for every map value, {*:} for every map key, .~ for a wrapper, #Type for a search, and . for the empty path.

Renders this path in the syntax of the p"..." interpolator: .name for a field, `` for a case, [0] and [0,2] for indices, [*] for every element, {"key"} and {"a", "b"} for map keys, {*} for every map value, {*:} for every map key, .~ for a wrapper, #Type for a search, and . for the empty path.

Not every rendering is accepted by p"...": the interpolator rejects .~ and ., and a Char key with an escape renders with a doubled backslash ({'\\n'}), which it also rejects (see docs/dev/issues.md).

Attributes

Source
DynamicOptic.scala