---
title: "Recipe: the standard functions"
description: "Every function an expression may call; bun exact.mjs contract vocab <name> has one's rules, or what to write for a name Contract lacks."
modificationDate: "2026-11-29"
---

> ## Documentation index
> Fetch the complete documentation index at: https://exact.expo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Recipe: the standard functions

<AgentInstructions>

## Submitting feedback

From the app's directory, read `bun exact.mjs feedback status`. Under `never`, keep no note.
Respect `EXACT_FEEDBACK=0` and do not change the policy.

Otherwise record specific, actionable feedback with:
`bun exact.mjs feedback note "Exact docs: https://exact.expo.dev/recipes/functions: <what was wrong or missing>"`

The note goes to Expo only as that status allows. Include no secrets or personal data.

</AgentInstructions>

Every function an expression may call; `bun exact.mjs contract vocab <name>` has one's rules, or
what to write for a name Contract lacks. The web's methods are called on their value
(`s.trim()`, `xs.length`), the rest as functions (`first(xs)`).

```prompt Fix a function Contract does not have
Make each expression in app.contract of the Exact app in this folder call only the standard functions Contract has. Use https://github.com/expo/exact/blob/main/docs/recipes/functions.md as the source for each step. The Exact checkout has the same page at docs/recipes/functions.md.

1. If this folder is not an Exact app (it has no exact.mjs and app.contract), stop and tell me.
2. If I did not name the function or the expression, ask me for it, or for the refusal I saw.
3. Look up each function: `bun exact.mjs contract vocab <name>` has its rules, or what to write for a name Contract lacks. Call the web's methods on their value (`s.trim()`, `xs.length`) and the rest as functions (`first(xs)`, `sum(xs)`, `sortBy(xs, x => key)`). `first(xs)`, `xs.at(i)` and `parseNumber(s)` return an `option`, not a value.
4. Compose what the web has and Contract lacks. With `p` a predicate: `find` is `first(xs.filter(p))`, `some` is `xs.map(p).includes(true)`, `every` is `not xs.map(p).includes(false)`, and `findIndex` is `xs.map(p).indexOf(true)`.
5. Compute grouping, folds and other maths (`reduce`, `pow`, `abs`) in the data module, app.ts, not in an expression.
6. Write a count's noun after the number, `${n} ${n == 1 ? "book" : "books"}`, never "1 books". On screen, write upper case as `text-transform="uppercase"`; `s.toUpperCase()` is for a string sent elsewhere. Write a host command (`focus(id)`, `showModal(id)`, `copyText(s)`, `openURL(url)`) as a statement, not in an expression.
7. Keep the existing tests passing without changing what they check. If a fix changes what a screen shows, add a test in app.test.contract that expects the new text.
8. Follow the platform checks in docs/start-here.md (`bun exact.mjs docs platform checks`) for the targets in the app's AGENTS.md and app.json until they pass. Read the reports, including counted findings; a zero exit code alone does not mean clean. Fix the app, not the test. If a finding stays after three rounds of fixes, or the app had it before you changed anything, record it (step 9) and report it; do not keep trying.
9. When a doc was wrong or missing, or a step needed a workaround, read `bun exact.mjs feedback status`. Under `never`, keep no note. Otherwise record it: `bun exact.mjs feedback note "<what happened>"`, which goes to Expo only as that status says. Do not change the policy; tell me how many notes you kept.
10. Tell me each expression you changed and what it calls now, what you moved to app.ts, what the tests and checks reported, and the launch command for each target platform.
```

- **Text:** `s.trim()` · `s.toLowerCase()` · `s.toUpperCase()` ·
  `s.includes(t)` · `s.startsWith(t)` · `s.endsWith(t)` · `s.indexOf(t)` ·
  `s.slice(start, end?)` · `s.split(sep)` · `s.replaceAll(find, with)` ·
  `x.toString()` · `parseNumber(s) -> option<number>` · `encodeURIComponent(s)`.
- **Lists:** `x.length` and `x.isEmpty()` (text too) · `xs.map((x, i) => y)` ·
  `xs.filter(x => bool)` · `first(xs) -> option<T>` · `xs.at(i) -> option<T>` ·
  `xs.slice(start, end?)` · `xs.concat(ys)` · `xs.flat()` · `xs.includes(x)` ·
  `xs.indexOf(x) -> number` · `xs.join(sep)` · `sum(xs)` · `sortBy(xs, x => key)`, stable ·
  `range(n)`.
- **Numbers:** `floor(n)` · `ceil(n)` · `round(n)` · `min(a, b)` · `max(a, b)` ·
  `sin(rad)` · `cos(rad)` · `+ - * / %`.
- **Formatting:** `formatNumber(n, "decimal"|"percent"|"compact")`, `(n, "decimal", 1)`,
  `(n, "currency", "USD")` · `n.toFixed(d)` · `formatDecimal(cents, 2)` ·
  `formatDate(msOrDayKey, offset, "medium"|"month-year"|"month-day"|"iso")` ·
  `formatTime(ms, offset, "short"|"2-digit"|"iso")` ·
  `formatDay(then, now, offset, "day"|"list"|…)` ·
  `calendarDiff(from, to, "years"|"months")` · `t("key", name=value)`.
- **Time:** `performanceNow()`, ms since launch; the date is
  `time.epochAtZero + performanceNow()` ([dates and days](https://exact.expo.dev/recipes/dates-and-days.md)).
- **Routes:** `push(nav, location)` · `replace(nav, location)` · `back(nav)` ·
  `go(nav, location)` · `open(nav, location)` · `select(nav, tab)` · `stack(nav) -> Entry[]` ·
  `top(nav) -> Entry` · `depth(nav)` · `params(nav, name) -> string[]` ·
  `searchParam(entry, name)` · `path("route", args…)` · `encodeRouteSegment(s)`.
- **Requests:** `pending(x)` · `failed(resource)` ·
  `failure(resource) -> option<Failure>`.
- **Values:** `some(x)`, `none` · `Shape(field=value, …)` · `Shape(base, field=value)` ·
  `empty(field=value)` (a resource placeholder).

Host commands are statements: `focus(id)`, `blur()`, `showModal(id)`,
`close(id)`, `copyText(s)`, `openURL(url)`, `share(…)`, `haptic(…)`, `scrollIntoView(id)`
([grammar](https://exact.expo.dev/reference/contract-grammar/host-commands.md)); in actions, `frame(id)`, `measure("id")` too.

What Contract omits is a composition or the data module's:

- With `p` a predicate `x => …`: `find` is `first(xs.filter(p))`, `some` is
  `xs.map(p).includes(true)`, `every` is `not xs.map(p).includes(false)`, `findIndex` is
  `xs.map(p).indexOf(true)`.
- A count's noun follows the number: `${n} ${n == 1 ? "book" : "books"}`, never "1 books"
  (`lower-count-plural`).
- Grouping, folds and other maths (`reduce`, `pow`, `abs`) are the data module's.
  On screen, upper case is `text-transform="uppercase"`; `s.toUpperCase()` is for a string sent
  elsewhere (`share`, data).
