tushar

tushar

Pattern matching in multi level nested maps

How do I pattern match in multi-level nested maps

Suppose this is my map , 
mymap = %{a: "xxx" , b: %{k1: "k1" , k2: "k2" , c: %{k3: "k3", k4: "k4"}}}

When I do this , I get an  error , 

** %{a: v1, b: %{k1: v2, k2: v3, c: %{k3: v4, k4: v4}}} = mymap **

** (MatchError) no match of right hand side value: %{a: "xxx", b: %{c: %{k3: "k3", k4: "k4"}, k1: "k1", k2: "k2"}}
    (stdlib) erl_eval.erl:453: :erl_eval.expr/5
    (iex) lib/iex/evaluator.ex:257: IEx.Evaluator.handle_eval/5
    (iex) lib/iex/evaluator.ex:237: IEx.Evaluator.do_eval/3
    (iex) lib/iex/evaluator.ex:215: IEx.Evaluator.eval/3
    (iex) lib/iex/evaluator.ex:103: IEx.Evaluator.loop/1
    (iex) lib/iex/evaluator.ex:27: IEx.Evaluator.init/4

Marked As Solved

NobbZ

NobbZ

You ask here that :k3 and :k4 have values that meatch.

Also Liked

mentero

mentero

you still didn’t fix the typo. You ask that k3: and k4: both have the same value v4 but then pass "k3" and "k4 as the values. Your pattern is OK, your data simply doesn’t match.

Last Post!

tushar

tushar

Apologies , it was indeed the typo causing the issue :weary:

Where Next?

Popular in Questions Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49134 226
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement