Functional Weave
Code in TypeScript

hr.absence-bradford-factor

Bradford factor for a set of absence spells: spells squared times total days, which weights frequent short absences.

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

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

What it does

The Bradford factor is B = S² × D, where S is the number of separate spells of absence and D is the total days absent, both over one rolling period (commonly 52 weeks). Squaring the spell count is the point: ten one-day absences (10² × 10 = 1000) score a hundred times one ten-day absence (1² × 10 = 10), because frequent short absences disrupt work more.

The caller decides what a spell is (consecutive days off for the same reason are one spell) and which period to look at, and passes the days lost in each spell. An empty list is a score of 0. A spell of zero or fewer days is an error rather than something silently counted as a spell.

For example

  • bradfordFactor() → spells 0, days 0, score 0 no absence scores zero
  • bradfordFactor(10) → spells 1, days 10, score 10 one ten-day spell scores 10
  • bradfordFactor(2, 2, 2, 2, 2) → spells 5, days 10, score 250 five two-day spells score 250

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 bradfordFactor(spellDays: readonly number[]): BradfordFactor
spellDaysint[]days lost in each separate spell of absence within the rolling period, one entry per spell
returnsBradfordFactor

The type it declares, generated into your project

/** The score and the two numbers it comes from. */
export interface BradfordFactor {
  /** S, the number of spells */
  readonly spells: number;
  /** D, the total days absent */
  readonly days: number;
  /** S x S x D */
  readonly score: number;
}

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

import { bradfordFactor } from "#fune/hr.absence-bradford-factor@^1";
impl/typescript.ts · 14 lines · open · raw
import { type BradfordFactor } from "./hr_absence_bradford_factor_types.ts";

/** B = S x S x D over the spells given. */
export function bradfordFactor(spellDays: readonly number[]): BradfordFactor {
  let days = 0;
  for (const d of spellDays) {
    if (!Number.isInteger(d) || d < 1) {
      throw new RangeError(`each spell must be at least one whole day, received ${d}`);
    }
    days += d;
  }
  const spells = spellDays.length;
  return { spells, days, score: spells * spells * days };
}

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 hr.absence-bradford-factor
Download for TypeScript hr.absence-bradford-factor-1.0.0-typescript.fune · 4,635 bytes sha256 068638a39cfd9c35f3c7d561ab9f72a67089a4e2435ecd9fb66207f7e85df387

The manifest, vectors and README with only the TypeScript implementation. Install it without the registry with fune add ./hr.absence-bradford-factor-1.0.0-typescript.fune, or fetch it from a terminal with fune pull hr.absence-bradford-factor@1.0.0:typescript.

The whole function, every language, is one file too: hr.absence-bradford-factor-1.0.0.fune, 6,247 bytes, sha256 2a1f3a106d2a361a144113adb6e481be6a0e58e4c254009219961a1e8d166876. 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 hr.absence-bradford-factor

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

// fune: after hr.absence-bradford-factor

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 hr.absence-bradford-factor --steps.

// fune: step hr.absence-bradford-factor 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
no absence scores zero → spells 0, days 0, score 0
one ten-day spell scores 10 10 → spells 1, days 10, score 10
five two-day spells score 250 2, 2, 2, 2, 2 → spells 5, days 10, score 250
ten one-day spells score 1000: same days, a hundred times the score 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 → spells 10, days 10, score 1,000
mixed spells 3, 2, 1 → spells 3, days 6, score 54
a single day off 1 → spells 1, days 1, score 1
a long-term absence plus a short one 60, 1 → spells 2, days 61, score 244
a zero-day spell is an error 2, 0 → error: at least one whole day
a negative spell is an error -1 → error: at least one whole day
a half-day spell is an error 1.5 → error: at least one whole day

More from the author

It is a management heuristic, not a legal test. Absences related to disability, pregnancy or other protected characteristics should not be scored against someone (Equality Act 2010); this function cannot know which those are, so filter them out before calling it.

Files

PathBytes
README.md943
impl/python.py533
impl/rust.rs991
impl/typescript.ts497
vectors.json1,168