Pattern Matching a Function Body: Binaries

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

10 Comments

  1. Joep Stender on July 10, 2020 at 2:14 pm

    The link to https://hexdocs.pm/elixir/Kernel.SpecialForms.html in this article is displayed incorrectly.

    • Mark Ericksen on July 10, 2020 at 2:31 pm

      Thanks Joep! There is a problem linking directly to the function. I can’t do it or it corrupts the rendering. 🙁 The function I’m referring to is <<>>/1

      I’ve fixed the rendering problem but at the cost of a less precise link.

  2. romenigld on December 14, 2020 at 12:20 pm

    Wow this help me a lot, I always don’t understand well when I see something about binary using elixir.
    Now this opens my mind.
    Thank you so much, your explanations are awesome!
    i will now read on Documentation about this <> and be prepared.

    • Mark Ericksen on December 14, 2020 at 1:35 pm

      Awesome! I’m glad it is helpful!

  3. Mark Johnson on February 23, 2021 at 12:47 am

    These lessons are proving to be very helpful for me. I was surprised to find that the rest of the binary data does not match unless ::binary is appended.
    def image_type(<>), do: :png doesn’t work but
    def image_type(<>), do: :png does work

    Thank you, Mark, for making this available.

  4. Vitaly Vasiliev on June 5, 2021 at 9:31 pm

    1.13 elixir, little problem with 1 test, it is not accepting “SAY “, only “SAY” etc

    • Mark Ericksen on June 6, 2021 at 6:34 am

      Hello Vitaly! Can you be more specific? I just tested using Elixir 1.12.1 (current latest released version) and all the tests pass without a need to change.

  5. Vitaly Vasiliev on June 5, 2021 at 9:31 pm

    Fixed by removing space in the test. 🙂

  6. Jaison Vieira on October 4, 2021 at 8:31 pm

    My tests passed doing this:

    def image_type(@png_signature _image_body), do: :png
    def image_type(@jpg_signature _image_body), do: :jpg

    I see your solution is different. Is it the best way to do or just different? Why do both of them work?

  7. Maksym Kosenko on December 13, 2021 at 3:03 pm

    The links from “Recap” were very helpful for me! Thanks a lot, Mark

Leave a Comment

You must be logged in to post a comment.