I have to match on data (HTTP headers) that may arrive in any order. What would be the elegant and performant way to do such pattern match?
F.e. say we have to match on these 3 values: <<a>>, <<b>>, <<c>>. Each known beforehand, yet with an indeterminate ordering. Is there any better way than to just write/generate out all the function heads, 6 in this case?
If you want to match on an unordered list of values, you can order them before doing the match. Note though, that the kind of binary pattern matching that you gave as an example won’t work in Elixir.
The function you wrote doesn’t do what you described you wanted.
What you’ve done is match a variable a and a variable b, both a single byte width. What the text you wrote described was to match specific values in any order. So it’d be more like match("foo:" <> foo_value <> "bar:" <> bar_value) but where foo and bar happen in any order. This is not possible to construct in a single match head, but @LostKobrakai’s solution works.
Give it a whirl! Evolve your example from matching on just 2 bytes and do something more like an HTTP header string.
@chocolatedonut I meant similar thing to what @benwilson512 wrote - based on your example I thought that you wanted to do something different. Glad you’ve already got some help on your problem!