Updated March 7, 2026 – now on Hex.pm with documentation on HexDocs.

Published Matcher – a simple expression matcher and evaluator for Erlang. Evaluate tuple-based expressions for comparisons, boolean logic, and substring matching – with optional case-insensitive variants and pluggable value providers.

Quick Start

%% Simple equality
true = matcher:eval({'=', <<"Albert">>, <<"Albert">>}).

%% Case-insensitive equality
true = matcher:eval({'=~', <<"Albert">>, <<"albert">>}).

%% Boolean logic
true = matcher:eval({'|', [
    {'=', <<"A">>, <<"B">>},
    {'=', <<"A">>, <<"A">>}
]}).

%% Substring matching
true = matcher:eval({'?', <<"bert">>, <<"Albert">>}).

Expressions are tuples that can be freely nested:

{Op, Arg}            %% Unary  (e.g. not)
{Op, Arg1, Arg2}     %% Binary (e.g. eq, lt, part_of)
{Op, [Arg, ...]}     %% N-ary  (e.g. and, or)

Providers

eval/2 accepts a provider – a fun/1 that resolves values that cannot be evaluated further. The most common use case is looking up keys in a map:

Map = #{name => <<"Albert">>, age => 42}.

true  = matcher:eval(Map, {'=', name, <<"Albert">>}).
true  = matcher:eval(Map, {'>', age, 18}).

You can use any fun/1 as a provider – and even implement custom operators by handling tuples in your function.

eval vs match

Function Returns On unknown operator
eval/1, eval/2 Any value Returns unevaluated expression as-is
match/1, match/2 true, false, or {error, ...} {error, {unevaluated_expression, Expr}}

Operators

Short Long Case-insensitive Description
! not   Logical negation
& and   Logical AND (short-circuit)
\| or   Logical OR (short-circuit)
=, == eq =~ Equal
< lt <~ Less than
> gt >~ Greater than
>=, => ge >=~, =>~ Greater than or equal
<=, =< le <=~, =<~ Less than or equal
? part_of ?~ Substring match

Installation

{deps, [{matcher, "1.0.0"}]}.

Licensed under MIT. I’d love to hear from you if you find this library useful. :-)