Skip to content

Latest commit

 

History

History
165 lines (101 loc) · 3.64 KB

optic_lists.md

File metadata and controls

165 lines (101 loc) · 3.64 KB

Module optic_lists

A set of optics specific to lists.

Function Index

all/0
all/1 Focus on all elements of a list.
head/0
head/1 Focus on the head of a list.
nth/1
nth/2 Focus on the nth element of a list.
tail/0
tail/1 Focus on the tail of a list.

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 elements of a list.

Example:

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

head/0


head() -> optic:optic()

See also: head/1.

head/1


head(Options) -> optic:optic()

Options: Common optic options.

returns: An opaque optic record.

Focus on the head of a list. The list must have at least one element to have a head.

Example:

  > optic:get([optic_lists:head()], [1,2,3]).
  {ok,[1]}

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 list element to focus on.
Options: Common optic options.

returns: An opaque optic record.

Focus on the nth element of a list. As with lists:nth/2, indexing begins at 1.

Example:

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

tail/0


tail() -> optic:optic()

See also: tail/1.

tail/1


tail(Options) -> optic:optic()

Options: Common optic options.

returns: An opaque optic record.

Focus on the tail of a list. A list must have at least one element to have a tail.

Example:

  > optic:get([optic_lists:tail()], [1,2,3]).
  {ok,[2,3]}