We already have pattern matching and functions. Let's combine them and introduce a "partial procs" as first-class citizens.
What are partial procs? This is a function that works on a subset of arguments. The partial proc's main advantage is that a caller may decide in advance if this proc can accept an argument or not and do something different rather than calling it.
That's how it may look like:
partial_proc=procdo|arg|inxifx.odd?"#{x} is odd"end
One can check if a proc is defined on the argument
Isn't the topic starter talking about pattern arguments for function? This is something I'm personally looking froward to. It is similar to Elixir's functions pattern matching and increases the expressiveness of the language by order of magnitude.
For example, I have some complex entity and have a handler that does something with its attributes:
Now I have a loosely coupled handler that only specifies the requirements for the passed object with a pattern. You can even think of it as of a simple type system.
calculate_discount(product,discount)
Btw, while imagining this example I also thought maybe it is possible to use boolean-like pattern combinations, we have | user there already to alternate patterns, so why don't combine them with &?
This code would not do the trick by I hope you got the idea: we define multiple methods with the same name but different argument patterns using the DSL and then the first matching pattern and its corresponding block is used when the method is called. We might also need some pattern match result object like we have for regexp match. Later, this can be turned from a DSL to a first-class syntax like:
defpm foo({ bar: 0.. })
end
The bottom line is that in Elixir this pattern matching for function signature is very expressive and makes code writing and support a way more joyful process.