Skip to content

Latest commit

 

History

History
83 lines (51 loc) · 1.98 KB

optic_generic.md

File metadata and controls

83 lines (51 loc) · 1.98 KB

Module optic_generic

A set of generic optics that can be applied to multiple container types.

Description

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.

Function Index

index/1 Focus on an element of a list like container.
key/1 Focus on the value of many different key/value like mappings.

Function Details

index/1


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/1


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