A set of generic optics that can be applied to multiple container types.
Intended both as a convenience and to support optic creation from parsed paths in optic_path.
Because of the ambiguous types they support, these optics do not support the standard optic options. Instead, they always skip unexpected types and never create missing values.
index/1 | Focus on an element of a list like container. |
key/1 | Focus on the value of many different key/value like mappings. |
index(Index) -> optic:optic()
Index = non_neg_integer()
Index
: The one based index of the element to focus on.
returns: An opaque optic record.
Focus on an element of a list like container. Indexing begins at 1. Understands how to focus on lists and tuples. Does not support the usual optic options.
Example:
> optic:get([optic_generic:index(3)], [1, 2, 3]).
{ok,[3]}
key(Key) -> optic:optic()
Key = term()
Key
: The key to focus on.
returns: An opaque optic record.
Focus on the value of many different key/value like mappings. Understands how to focus on maps, property lists, dicts, orddicts and gb_trees. Does not support the usual optic options.
Example:
> optic:get([optic_generic:key(first)], #{first => 1}).
{ok,[1]}