Recipes
- First query — Define a tiny dataset inline, run a relational query, see output.
- Values, records, and lists — A lookup page for how to make and pull apart the three shapes of data you'll use most.
- Reading the REPL and fixing your first error — Morel's error messages look intimidating. Here's how to read them without flinching.
- Load a CSV — Read CSV files straight off disk. Columns come through as strings; you parse from there.
- Filter rows — Narrow a list of records to the ones that match one or more predicates.
- Select and rename columns — Project the columns you want, rename them, and compute new ones, all in the yield step.
- Sort, take, skip — Ordering, limit, and pagination — including the multi-key sort that SQL makes you think twice about.
- Group and aggregate — The single most useful relational verb. Count, sum, min, max grouped by one or more keys.
- Join two tables — Inner joins two ways, plus the "unmatched orders" question without an outer join.
- Derive columns with pattern matching — Classify rows by rule using case expressions — the tidier answer to nested if/else chains.
- Handle missing values — option types, defaults, counting missing rows, and filtering them out.
- Clean and normalise strings — Lowercase, split on a delimiter, collapse whitespace, and build a slug — with the string functions Morel 0.8 ships.
- Pivot wide to long and back — Reshape between a long-format list (one row per observation) and a wide-format one (one row per entity, columns per category). Both directions.
- Define a metric once — Extract a calculation into a named function and reuse it across filter, sort, and aggregate.
- Higher-order functions on data — map, filter, fold — and how they map onto the from…where…yield pipeline when your data is already a list.
- Compose queries from small pieces — Wrap `from` expressions in named functions and chain them. The compiler won't let you wire them up wrong.
- Model a domain with ADTs and test it — Orders, payments, refunds as one algebraic data type. Query it, assert invariants on it, sleep better at night.