View Source Adoption Cheatsheet

Convert your project to Matcha quickly! For a more in-depth description of how to move your project over, see the adoption guide.

At a high level, you will want to:

choosing-a-matcha-context

Choosing a Matcha.Context

the-table-context

The :table context

Use the :table context if you intend to trace code execution with the Matcha.Table functions.

require Matcha
matcha_spec = Matcha.spec(:table) do
  { x, y } = z when x > 10 -> z
end

the-trace-context

The :trace context

Use the :trace context if you intend to query data with Matcha.Trace functions.

require Matcha
matcha_spec = Matcha.spec(:table) do
  { x, y } = z when x > 10 -> z
end

other-contexts

Other contexts

Use the :filter_map or :match contexts if you intend to play with specs and in-memory data using the Matcha.Spec.

require Matcha
matcha_spec = Matcha.spec(:table) do
  { x, y } = z when x > 10 -> z
end

creating-matcha-spec-structs

Creating Matcha.Spec structs

building-specs-with-elixir

Building Specs With Elixir

Matcha provides an Elixir-to-Matcha compiler with the Matcha.spec/2 macro.

require Matcha
matcha_spec = Matcha.spec(:table) do
  { x, y } = z when x > 10 -> z
end

wrapping-raw-specs

Wrapping Raw Specs

You can make existing raw match specs play nice with Matcha APIs using Matcha.Spec.from_source!/2

raw_spec = [{{:"$1", :"$2"}, [{:>, :"$1", 10}], [:"$_"]}]
matcha_spec = Matcha.Spec.from_source!(:table, raw_spec)

using-matcha-specs

Using Matcha Specs

outside-of-matcha

Outside of Matcha

You can always extract the raw source of any Matcha.Spec and pass it into other APIs that do not support Matcha with Matcha.Spec.source/1.

require Matcha
matcha_spec = Matcha.spec(:table) do
  { x, y } = z when x > 10 -> z
end

raw_spec = Matcha.Spec.source(matcha_spec)

call/2, run/2, and stream/2 functions.