Functional Weave
Code in TypeScript

insurance.age-banding Unreviewed

Age at policy inception and the rating band it falls in, from a table of age bands.

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

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

Unreviewed. This capability’s implementations agree in every language and pass its published test vectors, which were worked out from the official sources cited. But no qualified actuary has yet checked those vectors, or confirmed that the capability covers the cases it claims. Treat it as a draft. Do not use it for real people, money or decisions without your own expert review. Once a qualified reviewer signs off, this notice is replaced with their name, qualification and the date. Each new version needs fresh sign-off.

Not professional advice. This capability calculates insurance figures from published rules. It is a software component for developers, not financial advice. Rules change and every rate here has an effective date. Check that the dates cover your case. Verify results against the official sources listed in its README, and have an actuary review how you use it, before anyone relies on the output. Provided “as is” under its licence, without warranty.

What it does

The policyholder's (or driver's) age on the inception date, and the band of a rating table it falls in: "17-20", "21-24", "70+".

## Age

For example

  • ageBand(2000-06-15, 2026-09-23, bands ×6) → age 26, label 25-29 26 at inception is in the 25-29 band
  • ageBand(2001-09-23, 2026-09-23, bands ×6) → age 25, label 25-29 a birthday on the inception date counts: 25 that day
  • ageBand(2001-09-23, 2026-09-22, bands ×6) → age 24, label 21-24 the day before the 25th birthday is still 24

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 ageBand(birthDate: string, inceptionDate: string, bands: readonly AgeBand[]): AgeBanding
birthDatedatedate of birth
inceptionDatedatethe date the age is taken on: inception or renewal, never today implicitly
bandsAgeBand[]the bands, youngest first, not overlapping
returnsAgeBanding

The types it declares, generated into your project

/** One band of ages, inclusive at both ends. */
export interface AgeBand {
  readonly label: string;
  readonly minAge: number;
  /** null for no upper limit, on the last band only */
  readonly maxAge: number | null;
}

/** The age and its band. */
export interface AgeBanding {
  /** completed years on the inception date */
  readonly age: number;
  readonly label: string;
}

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

import { ageBand } from "#fune/insurance.age-banding@^1";
impl/typescript.ts · 40 lines · open · raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

import { age } from "./dates_age.ts";  ← from dates.age ^1.0.0 · built alongside by fune
import { type AgeBand, type AgeBanding } from "./insurance_age_banding_types.ts";

/**
 * The policyholder's age on the inception date and the band it falls in.
 *
 * Age is completed years by dates.age, so a 29 February birthday ages on
 * 1 March in other years. The bands are checked before use: youngest first,
 * inclusive at both ends, no overlaps, and only the last may be open-ended.
 * An age no band covers is an error, not the nearest band.
 */
export function ageBand(birthDate: string, inceptionDate: string, bands: readonly AgeBand[]): AgeBanding {
  if (bands.length === 0) throw new RangeError("bands must not be empty");
  let previousMax = -1;
  for (let i = 0; i < bands.length; i++) {
    const band = bands[i];
    if (!Number.isInteger(band.minAge) || band.minAge < 0) {
      throw new RangeError(`minAge must be a whole number of 0 or more, received ${band.minAge}`);
    }
    const open = band.maxAge === null || band.maxAge === undefined;
    if (open && i !== bands.length - 1) {
      throw new RangeError(`only the last band may have no maxAge: "${band.label}" is not last`);
    }
    if (!open && (!Number.isInteger(band.maxAge) || (band.maxAge as number) < band.minAge)) {
      throw new RangeError(`maxAge must be a whole number no less than minAge in band "${band.label}"`);
    }
    if (band.minAge <= previousMax) {
      throw new RangeError(`bands must be youngest first and not overlap: "${band.label}" starts at ${band.minAge}`);
    }
    previousMax = open ? Number.MAX_SAFE_INTEGER : (band.maxAge as number);
  }
  const years = age(birthDate, inceptionDate);
  for (const band of bands) {
    const open = band.maxAge === null || band.maxAge === undefined;
    if (years >= band.minAge && (open || years <= (band.maxAge as number))) {
      return { age: years, label: band.label };
    }
  }
  throw new RangeError(`no band for age ${years}`);
}

Install

fune build

With that line in your source, in a TypeScript project (language typescript in fune.project), fune build resolves it and its 1 dependency, 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 insurance.age-banding
Download for TypeScript insurance.age-banding-1.0.1-typescript.fune · 16,578 bytes sha256 919c1f5cd77bdffae992d3caf04b98968c1371744446a79224efd0636ff6a559

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

The whole function, every language, is one file too: insurance.age-banding-1.0.1.fune, 21,490 bytes, sha256 4105698c1939caa7e55028e28b250af68328f96d6a2bf614fe066223725563b3. 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 insurance.age-banding

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

// fune: after insurance.age-banding

replace — inside this capability’s code only, calls to a dependency go to your function, with the same signature. Other capabilities that use it are unaffected; write in * to replace it everywhere.

// fune: replace dates.age in insurance.age-banding

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 insurance.age-banding --steps.

// fune: step insurance.age-banding 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
26 at inception is in the 25-29 band 2000-06-15, 2026-09-23, bands ×6 → age 26, label 25-29
a birthday on the inception date counts: 25 that day 2001-09-23, 2026-09-23, bands ×6 → age 25, label 25-29
the day before the 25th birthday is still 24 2001-09-23, 2026-09-22, bands ×6 → age 24, label 21-24
a 29 February birthday has not turned 21 on 28 February 2004-02-29, 2025-02-28, bands ×6 → age 20, label 17-20
and turns 21 on 1 March 2004-02-29, 2025-03-01, bands ×6 → age 21, label 21-24
in a leap year it turns on 29 February 2004-02-29, 2028-02-29, bands ×6 → age 24, label 21-24
the open top band 1950-01-01, 2026-09-23, bands ×6 → age 76, label 70+
exactly the youngest age 2009-09-23, 2026-09-23, bands ×6 → age 17, label 17-20
the upper edge of a band is inside it 1976-09-24, 2026-09-23, bands ×6 → age 49, label 30-49
a single open band covers everyone from its minimum 1990-01-01, 2026-01-01, bands ×1 → age 36, label all
Show the other 8 tests
CaseArgumentsExpected
too young for any band 2010-01-01, 2026-09-23, bands ×6 → error: no band for age 16
an age in a gap between bands is refused 2004-01-01, 2026-09-23, bands ×2 → error: no band for age 22
overlapping bands are refused 2000-01-01, 2026-09-23, bands ×2 → error: bands must be youngest first and not overlap
an open band that is not last is refused 2000-01-01, 2026-09-23, bands ×2 → error: only the last band may have no maxAge
a band whose maximum is below its minimum is refused 2000-01-01, 2026-09-23, bands ×1 → error: maxAge must be a whole number no less than minAge
no bands is refused 2000-01-01, 2026-09-23, → error: bands must not be empty
inception before birth is refused 2026-09-23, 2026-01-01, bands ×6 → error: is before birthDate
a fractional minimum age is refused 2000-01-01, 2026-09-23, bands ×1 → error: minAge must be a whole number

More from the author

Completed years on `inceptionDate`, by `dates.age`: a birthday on the inception date counts, and a 29 February birthday ages on 1 March in other years (UK law), so someone born on 29 February 2004 is still 20 on 28 February 2025. The date is always passed in: insurers rate on the age at inception or renewal, never on the day the code runs, and a mid-term change is usually rated on the age at the start of the term.

## Bands

The band table is the insurer's, so it is an argument. Each band is inclusive at both ends in whole years; the last may have no upper limit (`maxAge` null). The table is checked first: youngest first, no overlaps, and only the last band open-ended. Gaps are allowed, and an age that falls in a gap, or below the first band, is an error naming the age rather than being put in the nearest band, because a quote for someone the table does not cover should stop, not be priced.

Look the label up in a factor table with `insurance.rating-factors`.

## Before you rely on this

**Not professional advice.** This capability calculates insurance figures from published rules. It is a software component for developers, not financial advice. Rules change and every rate here has an effective date. Check that the dates cover your case. Verify results against the official sources listed above, and have an actuary review how you use it, before anyone relies on the output. Provided "as is" under its licence, without warranty.

**Unreviewed.** This capability's implementations agree in every language and pass its published test vectors, which were worked out from the official sources cited. But no qualified actuary has yet checked those vectors, or confirmed that the capability covers the cases it claims. Treat it as a draft. Do not use it for real people, money or decisions without your own expert review. Once a qualified reviewer signs off, this notice is replaced with their name, qualification and the date. Each new version needs fresh sign-off.

1.0.1 marks it unreviewed. The code and the tests are unchanged.

Files

PathBytes
README.md2,210
impl/python.py1,900
impl/rust.rs2,813
impl/typescript.ts1,932
vectors.json8,489