@pyrmont Now in Elixir:
Is also used for many cases, as head / tail (who needs recursion?) to a functions-acting-as-overloading, but powerful and with a lot of sense:
def zero?(0) do : true
def zero?(x) when is_integer(x): false
In the above code the invocation will be called with the code required, no `if` statements involved because we are using pattern matching.
>zero(0) # will call 1st def
>zero(10) # will call the 2nd
@pyrmont so, how this is good or bad? it depends. But most of the cases is a more clear design, and in some a way better way to solve problems involving flow of 'instant' dispatchers with a defined pattern.
A promised no-if-statments-needed coding style? maybe.
What do we have on #ruby? Since is not bundle on the language we have been developing modules and classes trying to implement this ideas.
Basic idea: Create a Result object, then match.
@esparta I generally like pattern matching, but don't most examples violate the Tell Don't Ask principle? The complex matching logic should be done within the object, instead of outside.
A Mastodon instance for Rubyists & friends