Module optic_path

April 27, 2019 ยท View on GitHub

Utility functions for constructing optics from lists of selectors.

Data Types

path()


path() = string() | binary() | non_neg_integer() | *

A single path component.

paths()


paths() = [path()]

A list of path components.

Function Index

new/1 Construct a list of optics from a path.

Function Details

new/1


new(Paths) -> optic:optics()

Paths: A list of path components to convert.

returns: A list of opaque optic records.

Construct a list of optics from a path. The type of the path component determines the optic used:

  • string: A key for a map-like structure.

  • binary: A key for a map-like structure.

  • integer: An index into a list-like structure.

  • '*': All elements of a list.

This heavily depends on the optic_generic module, see the optics there for the full list of containers supported.

Example:

  > optic:get(optic_path(["first"]), ${"first" => 1, "second" => 2}).
  {ok,[1]}