mingyar.furtado

mingyar.furtado

Patern Matching on Koans

Hi! Could someone help me on that?

I’m trying to solve that one, it seems to be right but is not passing:

The original code is:

koan "Lists must match exactly" do
    assert_raise ___, fn ->
      [a, b] = [1, 2, 3]
    end
  end  

And I’m trying that:

koan "Lists must match exactly" do
    assert_raise ___, fn ->
      [a, b, c] = [1, 2, 3]
    end
  end

Then the output is like “still the same”:

Lists must match exactly
Assertion failed in lib/koans/12_pattern_matching.ex:42
assert_raise(___, fn → [a, b, c] = [1, 2, 3] end)

Maybe I’m not understanding that structure calling an anonymous function.

I already had tested on my terminal doing just:

[a, b, c] = [1, 2, 3]

And it seems to be right :sweat_smile:

Marked As Solved

lud

lud

Take a look at the docs for assert_raise/2 and assert_raise/3 to have the correct syntax.

Also Liked

mingyar.furtado

mingyar.furtado

@lud Just solved:

koan "Lists must match exactly" do
    assert_raise MatchError, "no match of right hand side value: [1, 2, 3]", fn ->
      [a, b] = [1, 2, 3]
    end
end

Thanks for helping!

lud

lud

The test is using assert_raise, so I guess you do not have to make the match work but just to provide the correct exception name at ___.

Where Next?

Popular in Questions Top

New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

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
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
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