Functional Weave
Code in Python

charts.extent

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

1.0.0 (not the latest) · published 2026-10-03 by charlie · Anterra

Pinned by 10 tests, run in TypeScript, Python and Rust · fewer than the registry now requires. 1.0.1 adds them.

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.

def extent(values: Sequence[Optional[float]]) -> Optional[List[float]]
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

from fune.charts.extent import extent  # charts.extent@^1
impl/python.py · 26 lines · open · raw
import math
from typing import List, Optional, Sequence


def extent(values: Sequence[Optional[float]]) -> Optional[List[float]]:
    """[min, max] of a series, skipping gaps (None); None when nothing is left.

    min() over the raw list would fail on None rather than skip it.
    """
    lo = 0.0
    hi = 0.0
    seen = False
    for v in values:
        if v is None:
            continue
        if isinstance(v, bool) or not isinstance(v, (int, float)) or not math.isfinite(v):
            raise TypeError("values must be finite numbers or null, received %r" % (v,))
        if not seen:
            lo = hi = float(v)
            seen = True
        else:
            if v < lo:
                lo = float(v)
            if v > hi:
                hi = float(v)
    return [lo, hi] if seen else None

Install

fune build

With that line in your source, in a Python project (language python in fune.project), fune build resolves it and nothing else, pins them in fune.lock, downloads only the Python 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 Python charts.extent-1.0.0-python.fune · 4,148 bytes sha256 7efe937d84f56de95dbc96f8ce6e54b1ed5263691d51ab4a96ba5fabaaa0f385

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

The whole function, every language, is one file too: charts.extent-1.0.0.fune, 6,037 bytes, sha256 1b4a60b9f50bc1532a1136f2c266c61f9386fb5a55f1f62ffddb0a968a0bd8c8. 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.

This version has fewer tests than the registry now requires. It was published before every function had to have 8. 1.0.1 meets it, and a project on ^1.0.0 installs that or newer.

  • extent throws (throws yes) but none of its 10 tests expects an error; add an "expectError" vector for each error it documents, or declare `throws no` if it cannot throw
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…

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.

Files

PathBytes
README.md934
impl/python.py808
impl/rust.rs998
impl/typescript.ts799
vectors.json959