Right now if you want to do an "OR" match in a function head, you probably need to use guards and `in` (or duplicate bodies):
def foo(value) when value in [ :this, :that ],
do: a_thing
def foo(
value
),
do: another_thing
# or
d
ef foo(:this),
do: a_thing
d
ef foo(:that),
do: a_thing
def foo(
value
),
do: another_thing
It occurs to me that this is quite a lot of typing for something pretty simple, and so I was wondering what people thought about the following:
def foo(:this | :that),
do: a_thing
def foo(anything_else),
do: another_thing
It could unpack to create an extra foo/1 match. The benefit is less typing, less noise, and it flows better when working (it also matches the syntax of a type spec). Definitions would go from left to right, meaning that the pattern on the left would be declared first so that it's natural when following how things are matching. I took a look around code on GitHub, etc, and it seems the community in general would make good use of this (it'd be even better if we could make it work in a `case` by itself).
Not sure if this has been discussed or shot down before, but figured I might as well be the one to bring it up if it hasn't :)
Thanks all, appreciate thoughts!
IW