The first element of a keyword list of arbitrary length was proving difficult for me to pattern match against.
Ex:
iex(1)> foo = [ok: :one, ok: :two, ok: :three]
iex(2)> inspect(foo, structs: false)
"[ok: :one, ok: :two, ok: :three]"
It seems like this is just a list, but:
iex(3)> [ok: _ | bosh] = foo
** (CompileError) iex:3: misplaced operator |/2
i/1
revealed that it’s really a list of two element tuples:
iex(4)> i(foo)
Term
[ok: :one, ok: :two, ok: :three]
Data type
List
Description
This is what is referred to as a "keyword list". A keyword list is a list
of two-element tuples where the first element of each tuple is an atom.
Reference modules
Keyword, List
Implemented protocols
Collectable, Enumerable, IEx.Info, Inspect, List.Chars, String.Chars
With this crucial clarification:
iex(5)> [{:ok, _} | bosh] = foo
[ok: :one, ok: :two, ok: :three]
iex(6)> bosh
[ok: :two, ok: :three]
Which brings us full circle by to my original query: