How can i access values of aaa, xxx, yyy & zzz from into separate variables, as it does seems mix of maps/tuple.
{{: xxx, %{yyy: 'something', zzz: 'test'}, {aaa: 'best'}}}
Sorry guys for troubling you, i got that working as
iex(1)> {a, b, c} = {: xxx, %{yyy: 'something', zzz: 'test'}, {aaa: 'best'}}
{: xxx, %{yyy: 'something', zzz: 'test'}, {aaa: 'test'}}
iex(2)> a
:xxx
iex(3)> b
%{yyy: 'something', zzz: 'test'}
iex(4)> b[:zzz]
'test'
thanks anyways to all.
You can even pattern-match on map keys:
iex(1)> {a, %{zzz: b}, %{aaa: c}} = {:xxx, %{yyy: "something", zzz: "test"}, %{aaa: "best"}}
{:xxx, %{yyy: "something", zzz: "test"}, %{aaa: "best"}}
iex(2)> a
:xxx
iex(3)> b
"test"
iex(4)> c
"best"
See http://elixir-lang.org/getting_started/7.html
Btw, in Elixir, single- and doublequotes have different meaning (charlist vs. binary). If you don't really need singlequotes (charlist), use doublequotes everywhere - binary is the default string format in Elixir (see String docs)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With