PredicateSigil (Predicate Sigil v0.2.1)

PredicateSigil is sugar to condense pattern-matching predicate lambdas. E.g.:

fn %MyStruct{} -> true; _ -> false end

is equivalent to:

~p(%Mystruct{})

Link to this section Summary

Functions

Predicate Sigil. Expands to an arity-1 lambda that returns true only when pattern-matching the sigil string.

Link to this section Functions

Link to this macro

sigil_p(arg, modifiers)

(macro)

Predicate Sigil. Expands to an arity-1 lambda that returns true only when pattern-matching the sigil string.

Examples

iex> import PredicateSigil
...> [1,2,3,4] |> Enum.reject(~p(2))
[1, 3, 4]

iex> import PredicateSigil
...> [{1,2}, {1,2,3}, {3,4}] |> Enum.filter(~p({_, _})) # keep size-2 tuples
[{1, 2}, {3, 4}]

# supports inverting result
iex> import PredicateSigil
...> f = ~p(!"blah")
...> f.("blah")
false
...> f.("foo")
true