Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
What's the point of destructuring the list, only to return the same structure?
-
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... -
Qchmqs5378yi 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 -
Pattern matching shines when you mix it with atoms.
Its a fun and powerful language.
and don't forget to checkout Awesome-Elixir! -
@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.
Related Rants
I'm starting to love pattern matching in #Elixir
undefined
cool
pattern matching
elixirlang
elixir