A set of optics specific to tuples.
all/0 | |
all/1 | Focus on all elements of a tuple. |
element/1 | |
element/2 | Focus on the nth element of a tuple. |
field/3 | |
field/4 | Focus on a record field. |
all() -> optic:optic()
See also: all/1.
all(Options) -> optic:optic()
Options = optic:variations()
Options
: Common optic options.
returns: An opaque optic record.
Focus on all elements of a tuple.
Example:
> optic:get([optic_tuples:all()], {1,2,3}).
{ok,[1,2,3]}
element(N) -> optic:optic()
N = pos_integer()
See also: element/2.
element(N, Options) -> optic:optic()
N = pos_integer()
Options = optic:variations()
N
: The index of the tuple element to focus on.Options
: Common optic options.
returns: An opaque optic record.
Focus on the nth element of a tuple. As with erlang:element/2
,
indexing begins at 1.
Example:
> optic:get([optic_tuples:element(1)], {1,2,3}).
{ok,[1]}
field(Tag, Size, N) -> optic:optic()
Tag = atom()
Size = pos_integer()
N = pos_integer()
See also: field/4.
field(Tag, Size, N, Options) -> optic:optic()
Tag = atom()
Size = pos_integer()
N = pos_integer()
Options = optic:variations()
Tag
: The expected record tag.Size
: The expected record size.N
: The index of the field in the record tuple.Options
: Common optic options.
returns: An opaque optic record.
Focus on a record field. As records are a compiler construct, this
depends on the ?OPTIC_FIELD
macro in include/optic_tuples.hrl
to construct the required arguments from the record definition.
Given the record definition:
-include_lib("optic/include/optic_tuples.hrl").
-record(example, {first}).
Example:
> optic:get([optic_tuples:field(?OPTIC_FIELD(example, first))],
#example{first=1}).
{ok,[1]}