11

I'm starting to love pattern matching in #Elixir

Comments
  • 0
    What's the point of destructuring the list, only to return the same structure?
  • 0
    It's not destructuring but it's called pattern match really powerful although I see how you think it might be destructuring like in Es6... In short it's trying to extract first 3 item in the list and assign them to vars.
    It's a humongous topic to talk about and top of all I am still learning. But here a better screenshot of what's going on...
  • 1
    i don't know what's elixir but that looks like plain ruby to me
    EDIT : man that shit is wicked, why I've never heard about it before ?
    anyway i know how I'm wasting my weekend
  • 0
    Good luck, I'm loving it... :)
  • 0
    Pattern matching shines when you mix it with atoms.
    Its a fun and powerful language.
    and don't forget to checkout Awesome-Elixir!
  • 2
    @praneybehl I've written FP code for four years now I know how pattern matching works.

    Assigning variables based on the pattern is called deconstruction.

    The fact that you're writing
    [a, b, c] = foo
    [a, b, c]

    Means you're matching foo on a three element list, saving each element in a variable. On the very next line you're wrapping them back into a list that you then return.
Add Comment