View Source Surface.Catalogue.Data (surface v0.8.0)

Experimental module that provides conveniences for manipulating data in Examples and Playgrounds.

Provide wrappers around built-in functions like get_in/2 and update_in/3 using a shorter syntax for accessors.

accessor-mapping

Accessor Mapping

  • [_]: Access.all/0
  • [fun]: Access.filter(fun)
  • [index]: Access.at(index) (Shorthand for [index: i])
  • [index: i]: Access.at(i)
  • [key: k]: Access.key(k)
  • [first..last]: Surface.Catalogue.Data.slice(first..last)

example

Example

Data.get(props.lists[_].cards[& &1.id == "Card_1"].tags[-1].name)

The code above will be translated to:

get_in(props, [:lists, Access.all, :cards, Access.filter(& &1.id == "Card_1"), :tags, Access.at(-1), :name])

Link to this section Summary

Functions

Appends an item to a list in the given nested structure.

Deletes an item from the given nested structure.

Gets an existing value from the given nested structure.

Gets a value from the given nested structure.

Gets a value and updates a given nested structure.

Inserts an item into a list in the given nested structure.

Pops a item from the given nested structure.

Prepends an item to a list in the given nested structure.

Generates a short ramdom id.

Updates an item in the given nested structure.

Link to this section Functions

Link to this macro

append(path, value)

View Source (macro)

Appends an item to a list in the given nested structure.

Deletes an item from the given nested structure.

Gets an existing value from the given nested structure.

Raises an error if none or more than one value is found.

Gets a value from the given nested structure.

A wrapper around get_in/2

Link to this macro

get_and_update(path, fun)

View Source (macro)

Gets a value and updates a given nested structure.

A wrapper around get_and_update_in/3

Link to this macro

insert_at(path, pos, value)

View Source (macro)

Inserts an item into a list in the given nested structure.

Pops a item from the given nested structure.

A wrapper around pop_in/2

Link to this macro

prepend(path, value)

View Source (macro)

Prepends an item to a list in the given nested structure.

Generates a short ramdom id.

Link to this macro

update(path, fun)

View Source (macro)

Updates an item in the given nested structure.

A wrapper around update_in/2