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

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New

Other popular topics Top

hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 55125 245
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
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44778 311
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
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