Pattern matching against arbitrary sized tuple

ollran
Fri, 12 Oct 2018 20:03:13 +0000
Questions / Help

How can I pattern match against an arbitrary sized tuple? This works:

{status, _, _} = {:ok, 1, 2}

But what if I don’t know the structure of the tuple on the right side and I only care about the first element? This doesn’t work:

{status, _} = {:ok, 1, 2, 3, 4, 5, 6}
{status, _} = {:ok, {:random, :things}, [1, 2, 3]}

Is it possible to get the first value from the tuple with pattern matching?

7 posts - 6 participants