Matching Complex Data Types

You cannot view this unit as you're not logged in yet. Go to Account to login.

9 Comments

  1. xrsia on May 8, 2020 at 4:32 am

    Excellent !!!

  2. Francisco Quintero on November 13, 2020 at 12:49 pm

    Awesome. I’m understanding more pattern matching.

  3. Maksym Kosenko on October 16, 2021 at 11:26 am

    Outstanding! 🎹 🎷 🎻 🎯

  4. Takudzwa Gwindingwi on October 26, 2021 at 11:08 am

    This is really helpful thanks.

  5. Juan Borrás on August 24, 2023 at 6:58 am

    When executing the following in `iex`:

    “`{iex}
    f = fn a -> case a do
    %{_a, _b, _c} -> “A tuple of size 3, so what?”
    _ -> “Uhh…. what’s that?”
    end
    end
    “`

    I get the following error: `** (CompileError) iex:24: expected key-value pairs in a map, got: _a`
    Am I running a too old Elixir-Erland/OTP combo? Elixir v1.12..2 on Erlang 24 erts 12.2.1

    • Mark Ericksen on August 24, 2023 at 7:12 am

      I think the issue is you put a “%” on the front, making the datastructure a Map, but it’s and invalid structure for a map. Remove the “%” for it to be a tuple.

      • Juan Borrás on August 24, 2023 at 8:20 am

        *insert-huge-facepalm-image-here*
        You were right on target. Working like a charm now.
        Thanks for the course and for your time.

  6. Marcus West on June 25, 2024 at 6:31 am

    Erm, I read that case do is not proper functional programming, and that we should use functional clauses.

    • Mark Ericksen on June 25, 2024 at 6:41 am

      Case statements are used a lot in Elixir. They are one of the easiest ways to go a pattern match whenever you need it. Multiple function heads that use pattern matching actually turn into case statements when compiled. There are mixed feelings in the community about piping directly into a |> case do. I think that’s what you may have been seeing.

Leave a Comment

You must be logged in to post a comment.