Path
This page describes what a Pathex.t() is and how to create and use one
Note:
This is documentation about inner Pathex API and subject to change
You shouldn't read this unless you are interested inPathexinternals or want to hack intoPathex
Basic
Create: As described in README and
Pathexsimple paths can be created withPathex.path/2andPathex.sigil_P/2macrosUse: This paths then can be called using macro-helpers from
PathexlikePathex.view/2orPathex.force_set/3Prebuilt: some non-trivial prebuilt lenses are avaliable in
Pathex.Lensesmodule
Internal representation
Every path-closure is a closure of two arguments:
- Operation name (atom)
- Operation arguments, tuple which size depends on an operation
Currently every path-closure has 3 operations:
path_closure =
fn
# Operation which gets value from structure and retuns `function.(value)`
:view, {structure, function} -> ...
# Operation which returns new structure with updated value
:update, {structure, function} -> ...
# Operation which returns new structure with updated value, or default set
:force_update, {structure, function, default} -> ...
endPath-closure requirements
Path-closure must return
{:ok, any()} | :errorfor every valid operation call and raise if non-exsisting operation is calledPath-closures created by
Pathex.path/2orPathex.sigil_P/2are totally pure functions with no side effectsFunction passed as second element in tuple must return
{:ok, term()} | :erroror throw:path_not_found