Functional Weave
Code in TypeScript

charts.extent

The minimum and maximum of a series as [min, max], skipping gaps (null), or null when there is no value.

1.0.1 · published 2026-10-03 by charlie · Anterra

Pinned by 15 tests, run in TypeScript, Python and Rust.

What it does

`extent([null, 5, 7])` is `[5, 7]`: the smallest and largest values of a series, skipping gaps. It is the first step of nearly every chart (the data extent becomes a scale's domain), so it is its own capability.

A gap is `null`: a missing reading, a day with no sales recorded rather than zero sales. Gaps are skipped, never read as zero. The usual one-liner, JavaScript's `Math.min(...values)`, converts `null` to 0 and so draws a temperature series from zero; Python's `min()` fails on `None` instead.

For example

  • extent(3, 1, 2) → 1, 3 an unordered series
  • extent(—, 5, 7) → 5, 7 a gap is skipped, not read as zero (Math.min treats null as 0)
  • extent(4.5, —, -2.25, 9, —) → -2.25, 9 gaps in the middle and at the end

The function

The same function in TypeScript, Python and Rust, pinned by the same tests. Pick your language; the choice follows you around the registry.

export function extent(values: readonly (number | null)[]): readonly number[] | null
valuesfloat?[]the series; null marks a gap, such as a missing reading
returnsfloat[]?[min, max], or null when every value is a gap or the list is empty

Your code names it in one line, in the file that uses it

import { extent } from "#fune/charts.extent@^1";
impl/typescript.ts · 27 lines · open · raw
/**
 * [min, max] of a series, skipping gaps.
 *
 * `Math.min(...values)` is the usual one-liner and it is wrong here: it
 * treats null as 0, so a series of temperatures with a missing reading
 * suddenly starts at zero. It also throws a RangeError on a long enough list.
 */
export function extent(values: readonly (number | null)[]): readonly number[] | null {
  let min = 0;
  let max = 0;
  let seen = false;
  for (const v of values) {
    if (v === null) continue;
    if (typeof v !== "number" || !Number.isFinite(v)) {
      throw new TypeError(`values must be finite numbers or null, received ${v}`);
    }
    if (!seen) {
      min = v;
      max = v;
      seen = true;
    } else {
      if (v < min) min = v;
      if (v > max) max = v;
    }
  }
  return seen ? [min, max] : null;
}

Install

fune build

With that line in your source, in a TypeScript project (language typescript in fune.project), fune build resolves it and nothing else, pins them in fune.lock, downloads only the TypeScript package of each, and builds the code above into your project’s .fune/build, one readable file per capability with a header linking back here. Or pin a range in fune.project and build in one step:

fune add charts.extent
Download for TypeScript charts.extent-1.0.1-typescript.fune · 4,962 bytes sha256 418af12ad7d705b13efbd4a69975b4af3f460146acf15b7b6f0ee0e752cc08b2

The manifest, vectors and README with only the TypeScript implementation. Install it without the registry with fune add ./charts.extent-1.0.1-typescript.fune, or fetch it from a terminal with fune pull charts.extent@1.0.1:typescript.

The whole function, every language, is one file too: charts.extent-1.0.1.fune, 7,183 bytes, sha256 399353815202eee83b7de1869a785a3df6ca52d42d567693e8d053b41db659b9. It installs into a project of any language.

Customise it in your app

The seams this capability offers. Put a marker directly above a function of your own and fune build wires it into the built code; the package on the registry is not changed, the built file’s header lists it under CUSTOMISED, and fune hooks lists every hook in the project. How hooks work.

before — your function gets the arguments and returns them, changed or not, or throws to refuse the call.

// fune: before charts.extent

after — your function gets the result and the arguments, and returns the final result.

// fune: after charts.extent

replace — it requires no other capability, so there is no dependency to replace.

step — your function runs at a numbered point inside the function’s body, receives the in-scope values it names as parameters, and may return replacements. List the points with fune show charts.extent --steps.

// fune: step charts.extent after <n|label>

Tests

A version published now needs at least 8 tests for every function, and one that expects the error for each function that throws; the registry refuses it otherwise. fune verify --all runs each case in TypeScript, Python and Rust, and a project runs them again with fune verify. This page lists the cases; it does not run them. The exact JSON is vectors.json.

CaseArgumentsExpected
an unordered series 3, 1, 2 → 1, 3
a gap is skipped, not read as zero (Math.min treats null as 0) —, 5, 7 → 5, 7
gaps in the middle and at the end 4.5, —, -2.25, 9, — → -2.25, 9
negative values only -3, -8, -1 → -8, -1
one value is both ends 42 → 42, 42
all values equal 2, 2, 2 → 2, 2
every value a gap gives null —, — → —
an empty series gives null → —
fractions are returned exactly, not rounded 0.1, 0.3, 0.2 → 0.1, 0.3
very large and very small magnitudes 1,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,0… → -0, 1,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,0…
Show the other 5 tests
CaseArgumentsExpected
a single negative value is both ends -0.5 → -0.5, -0.5
zero is a value, not a gap 0, —, 0 → 0, 0
a leading gap then values that only fall —, 10, 8, 6 → 6, 10
a value that is not a number is an error, not a gap 1, 2, 3 → error: values must be finite numbers or null
true is not a number either 1, true → error: values must be finite numbers or null

More from the author

When the series is empty or every value is a gap, the answer is `null`, not a made-up `[0, 0]` or `[Infinity, -Infinity]`: a chart with no data should say so. A single value gives `[v, v]`; turning that into a usable domain (a scale needs two different ends) is the chart's decision, not this function's.

Values are returned exactly as given, with no rounding. A value that is not a finite number is an error.

1.0.1 adds tests; behaviour unchanged. The Rust vector adapter now refuses an argument that is not a number with the same message as TypeScript and Python, so the new error tests mean the same in all three.

Files

PathBytes
README.md1,142
impl/python.py808
impl/rust.rs1,316
impl/typescript.ts799
vectors.json1,516