Hello everybody,
As it’s possible to partially pattern match with maps like so:
iex> %{b: 2} = %{a: 1, b: 2, c: 3}
%{a: 1, b: 2, c: 3}
Is it possible to do the same with Lists, e.g. like that:
iex> [2] = [1, 2, 3]
# MatchError
I guess that the inherent nature of linked lists (which make it easy to pattern-match heads/tails) might complicate things. Also I got the fact that in this case it might not make sense to pattern-match for variable binding . But it might be useful to pattern-match in this case for conditions/tests.
One can simply use Enum.member?
but I don’t see an easy way to avoid conditions like we do when using pattern-matching in general or in functions argument.
Thank you very much for any details…