Module optic_array

April 29, 2019 ยท View on GitHub

A set of optics specific to arrays.

Function Index

all/0
all/1 Focus on all values of an array.
nth/1
nth/2 Focus on the nth value of an array.

Function Details

all/0


all() -> optic:optic()

See also: all/1.

all/1


all(Options) -> optic:optic()

Options: Common optic options.

returns: An opaque optic record.

Focus on all values of an array.

Example:

  > optic:get([optic_array:all()], array:from_list([1,2,3])).
  {ok,[1,2,3]}

nth/1


nth(N) -> optic:optic()
  • N = pos_integer()

See also: nth/2.

nth/2


nth(N, Options) -> optic:optic()

N: The index of the array value to focus on.
Options: Common optic options.

returns: An opaque optic record.

Focus on the nth value of an array. Like lists, but unlike the standard array operations, indexing begins at 1.

Example:

  > optic:get([optic_array:nth(1)], array:from_list([1,2,3])).
  {ok,[1]}