Want to convert tuple format into map

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Want to convert tuple format into map

Palanikumar Gopalakrishnan


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 ✌
Developer



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Want to convert tuple format into map

Jesper Louis Andersen-2
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 <[hidden email]> 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 ✌
Developer


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions