Skip to content

Latest commit

 

History

History
86 lines (45 loc) · 1.61 KB

optic_path.md

File metadata and controls

86 lines (45 loc) · 1.61 KB

Module optic_path

Utility functions for constructing optics from lists of selectors.

Data Types


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

A single path component.


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]}