[erlang-questions] Want to convert tuple format into map
Jesper Louis Andersen
jesper.louis.andersen@REDACTED
Sat Sep 2 18:18:19 CEST 2017
The tools you need are recursion and pattern matching.
Build a set of functions which match on your tuples, uses recursion to
compute subtuples into maps, and then builds a map out of the results at
this level. Suppose we have
T = {x, {data, 34, 35}, {data, 21, 22}},
We can then write a tool
conv({x, L, R}) -> #{ type => x, left => conv(L), right => conv(R) };
conv({data, V1, V2}) -> #{ type => data, value1 => V1, value2 => V2 }.
which can do the conversion by calling itself recursively. These ideas
should be applicable to your case as well.
On Sat, Sep 2, 2017 at 11:15 AM Palanikumar Gopalakrishnan <
palani@REDACTED> wrote:
>
>
> Hi Guys,
>
> I want to convert tuple format into map. This is format of
> tuple
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *{{metadata,2,0,
> {server_status,false,true,false,false,true,false,false,
> false,false,false,false,false}, [
> {
> field_metadata,"def","zurik","erlang","erlang","name",
> "name",33,135,253, <<0,0>>,
> 0, []
> }, {
> field_metadata,"def","zurik","erlang","erlang","id",
> "id",63,11,3, <<0,0>>,
> 0, []
> } ], []
> }, [ ["some",457],
> ["some",457], ["data2sosfasfme",42]
> ] }*
> I want to convert this format into map. Please help me to solve this
> challenge
>
>
>
> --
>
> *Warm Regards,*
>
> *Palanikumar Gopalakrishnan *[image: ✌]
> *Developer*
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170902/da78d369/attachment.htm>
More information about the erlang-questions
mailing list