Haskell has an as-pattern , which allows us to refer to the entire variable when matching with the pattern:
foo wholeList@(head:tail) = wholeList ++ head
The variable wholeListrepresents the original variable.
Assuming that headthere is ["Hello"], and tail- ["World"], then wholeListthere is ["Hello", "World"].
Using as-pattern, we can avoid constructing the variable again by combining headand tail.
Is there such a feature in Elixir?
source
share