[erlang-questions] Deep data structures and lenses
Ulf Wiger
ulf@REDACTED
Mon Sep 21 14:22:12 CEST 2015
> On 12 Sep 2015, at 19:51, Guilherme Andrade <g@REDACTED> wrote:
>
> Partially inspired by jlouis' erl-lenses[1] and an old discussion on this mailing list[2], I've been sketching a library for easier manipulation (both data fetching and updating) of deep data structures
Another library that’s been inspired by erl-lenses (although this has perhaps not been well communicated) is exprecs in parse_trans.
Example:
-module(lens).
-include_lib("parse_trans/include/exprecs.hrl").
-export([t/0]).
-record(r, {a, b, c}).
-export_records([r]).
t() ->
R = '#new-r'([{a,1},{b,2},{c,3}]),
{GetA, SetA} = Lens = '#lens-r'(a),
GetA1 = GetA(R),
R1 = SetA(17, R),
GetA2 = GetA(R1),
[{lens, Lens},
{get_a, GetA1},
{set_a, 17, R1},
{get_a, GetA2}].
...
Eshell V5.10.4 (abort with ^G)
1> c(lens).
{ok,lens}
2> lens:t().
[{lens,{#Fun<lens.6.121208397>,#Fun<lens.7.121208397>}},
{get_a,1},
{set_a,17,{r,17,2,3}},
{get_a,17}]
BR,
Ulf W
Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.
http://feuerlabs.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150921/c14f8378/attachment.htm>
More information about the erlang-questions
mailing list