Patterns.Guards (patterns v0.0.1)

Copy Markdown View Source

Guard helpers for pattern modules.

Summary

Functions

Returns true when value is keyword-shaped.

Functions

is_keyword(value)

(macro)

Returns true when value is keyword-shaped.

This guard intentionally checks only what Elixir guard expressions can check: the value is a list and either empty or starts with a two-tuple whose key is an atom.

Guards cannot call arbitrary functions or recursively inspect every element in a list. See the Elixir documentation for the list of expressions allowed in guards: https://hexdocs.pm/elixir/patterns-and-guards.html#guards

For example, [{:name, "Rin"}, :bad] is keyword-shaped for this guard because the first element is a valid atom-key tuple, but it is not a valid keyword list.

Use Keyword.keyword?/1 outside guards when every element must be validated.