Pathex v0.2.0 Pathex View Source

This module contains macroses to be used by user

Any macro here belongs to one of two categories: 1) Macro which creates path closure (sigil_P/2, path/2, ~>/2) 2) Macro which uses path closure as path (over/3, set/3, view/2)

Path closure is a closure which takes two arguments: 1) Atom.t() with operaion name 2) Tuple.t() of arguments of this operation

Link to this section Summary

Functions

Macro of three arguments which sets the given value in the given path of given structure

Macro of three arguments which applies given function for item in the given path of given structure

Creates path for given structure

Macro of three arguments which sets the given value in the given path of given structure

Sigil for paths. Has only two modes: naive (default) and json. Naive paths should look like ~P["string"/:atom/1] Json paths should look like ~P[string/this_one_is_too/1/0]

Macro gets the value in the given path of the given structure

Creates composition of two paths

Link to this section Types

Link to this type

el_structure()

View Source
el_structure() :: map() | list() | Keyword.t() | tuple()
Link to this type

key_type()

View Source
key_type() :: :integer | :atom | :binary
Link to this type

result()

View Source
result() :: {:ok, any()} | {:error, any()} | :error
Link to this type

struct_type()

View Source
struct_type() :: :map | :keyword | :list | :tuple
Link to this type

t()

View Source
t() ::
  (:get
   | :set
   | :update,
   {el_structure()}
   | {el_structure(), any()}
   | {el_structure(), (any() -> any())} ->
     result())

Link to this section Functions

Link to this macro

force_set(path, struct, value)

View Source (macro)

Macro of three arguments which sets the given value in the given path of given structure

If the path does not exist it creates the path favouring maps when structure is unknown

Link to this macro

over(path, struct, function)

View Source (macro)

Macro of three arguments which applies given function for item in the given path of given structure

Link to this macro

path(quoted, mod \\ 'naive')

View Source (macro)

Creates path for given structure

Example:

iex> x = 1
iex> mypath = path 1 / :atom / "string" / {"tuple?"} / x
Link to this macro

set(path, struct, value)

View Source (macro)

Macro of three arguments which sets the given value in the given path of given structure

Link to this macro

sigil_P(arg, mod)

View Source (macro)

Sigil for paths. Has only two modes: naive (default) and json. Naive paths should look like ~P["string"/:atom/1] Json paths should look like ~P[string/this_one_is_too/1/0]

Link to this macro

view(path, struct)

View Source (macro)

Macro gets the value in the given path of the given structure

Creates composition of two paths