Functional Weave
Code in TypeScript

todo.group-by-due

Split todos into Overdue, Today, Tomorrow, This week, Later, No date and Done sections, in that order.

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

Pinned by 26 tests, run in TypeScript, Python and Rust.groupByDue 14 · groupByDueWithOrder 12

What it does

Splits a todo list into the sections a planner shows, using todo.due-status for every todo so the sections agree with the labels and the summary.

| Function | Order inside a section | | --- | --- | | `groupByDue(todos, today)` | Overdue, This week and Later by due date; the rest as given (below). Unchanged since 1.0.0. | | `groupByDueWithOrder(todos, today, order)` | `order` `"due"`: the same as `groupByDue`. `"input"`: every section keeps the order the todos came in. |

The functions

A group: 2 functions that work together, each in its own file, each pinned by its own tests in TypeScript, Python and Rust. A project can install only the ones it calls.

  1. groupByDue (todos: Todo[], today: date) -> DueGroup[]
  2. groupByDueWithOrder (todos: Todo[], today: date, order: SectionOrder) -> DueGroup[]

The types it declares, generated into your project

/** One section of a todo list grouped by due date. */
export interface DueGroup {
  readonly status: DueStatus;
  /** Overdue, Today, Tomorrow, This week, Later, No date or Done */
  readonly title: string;
  readonly todos: readonly Todo[];
}

export type SectionOrder = "due" | "input";

Once installed, your code imports each one from the group's module.

groupByDue throws on bad input 14 tests

export function groupByDue(todos: readonly Todo[], today: string): readonly DueGroup[]
todosTodo[]in the order the caller wants within a section, e.g. already sorted by priority
todaydatethe user's local date, from the app; never the clock
returnsDueGroup[]only the sections that have todos, in the fixed order; Overdue, This week and Later sorted by date

For example

  • groupByDue(, 2026-09-28) → an empty list has no sections
  • groupByDue(todos ×7, 2026-09-28) → ×7 one todo of each kind, in reverse, comes out in section order
  • groupByDue(todos ×3, 2026-09-28) → ×1 overdue is sorted by due date, oldest first
import { groupByDue } from "#fune/todo.group-by-due@^1";
impl/typescript/group_by_due.ts · 14 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 { type DueGroup } from "./todo_group_by_due_types.ts";
import { groupByDueWithOrder } from "./todo_group_by_due_group_by_due_with_order.ts";  ← groupByDueWithOrder, another function of this group · built into the same file, even by a slim install
import { type Todo } from "./todo_item.ts";  ← from todo.item ^1.0.0 · built alongside by fune

/**
 * Todos in planner sections, fixed order, empty sections left out. Sections
 * spanning several dates are sorted by due date, stably; the rest keep the
 * caller's order, so a list pre-sorted by priority stays that way.
 * groupByDueWithOrder(todos, today, "input") keeps the caller's order in
 * every section.
 */
export function groupByDue(todos: readonly Todo[], today: string): readonly DueGroup[] {
  return groupByDueWithOrder(todos, today, "due");
}

groupByDueWithOrder throws on bad input 12 tests

export function groupByDueWithOrder(todos: readonly Todo[], today: string, order: SectionOrder): readonly DueGroup[]
todosTodo[]in the order the caller wants
todaydatethe user's local date, from the app; never the clock
orderSectionOrderdue sorts Overdue, This week and Later by date (groupByDue); input keeps the caller's order in every section
returnsDueGroup[]only the sections that have todos, in the fixed order

For example

  • groupByDueWithOrder(todos ×2, 2026-09-28, input) → ×1 input keeps overdue in the caller's order, not by date
  • groupByDueWithOrder(todos ×2, 2026-09-28, due) → ×1 due sorts the same overdue todos oldest first, as groupByDue does
  • groupByDueWithOrder(todos ×2, 2026-09-28, input) → ×1 input keeps this week in the caller's order
import { groupByDueWithOrder } from "#fune/todo.group-by-due@^1";
impl/typescript/group_by_due_with_order.ts · 38 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 { dayOfWeek } from "./dates_day_of_week.ts";  ← from dates.day-of-week ^1.0.0 · built alongside by fune
import { type DueStatus, dueStatus } from "./todo_due_status.ts";  ← from todo.due-status ^1.0.0 · built alongside by fune
import { type DueGroup, type SectionOrder } from "./todo_group_by_due_types.ts";
import { type Todo } from "./todo_item.ts";  ← from todo.item ^1.0.0 · built alongside by fune

const SECTIONS: readonly [DueStatus, string][] = [
  ["overdue", "Overdue"],
  ["today", "Today"],
  ["tomorrow", "Tomorrow"],
  ["this-week", "This week"],
  ["later", "Later"],
  ["none", "No date"],
  ["done", "Done"],
];

/**
 * Todos in planner sections, fixed order, empty sections left out. With
 * order "due", the sections spanning several dates (Overdue, This week,
 * Later) are sorted by due date, stably; with "input" every section keeps
 * the caller's order, so a list in manual order shows that order in each
 * section.
 */
export function groupByDueWithOrder(todos: readonly Todo[], today: string, order: SectionOrder): readonly DueGroup[] {
  if (order !== "due" && order !== "input") throw new Error(`order must be "due" or "input", found ${JSON.stringify(order)}`);
  dayOfWeek(today); // a bad today is an error even for an empty list
  const statuses = todos.map((todo) => dueStatus(todo, today));
  const groups: DueGroup[] = [];
  for (const [status, title] of SECTIONS) {
    const members = todos.filter((_, i) => statuses[i] === status);
    if (members.length === 0) continue;
    if (order === "due" && (status === "overdue" || status === "this-week" || status === "later")) {
      // Array.prototype.sort is stable, so equal dates keep input order.
      members.sort((a, b) => ((a.due as string) < (b.due as string) ? -1 : (a.due as string) > (b.due as string) ? 1 : 0));
    }
    groups.push({ status, title, todos: members });
  }
  return groups;
}

Install

fune build

With that line in your source, in a TypeScript project (language typescript in fune.project), fune build resolves it and its 3 dependencies, 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 todo.group-by-due

That builds the whole group. To build only what you call, and whatever it uses inside the group:

fune add todo.group-by-due --only groupByDue
Download for TypeScript todo.group-by-due-1.1.0-typescript.fune · 44,335 bytes sha256 af2108ad306863e43deb25de1f2883f1d3d7a77520c28b65dc55f3a57f83d0f7

The manifest, vectors and README with only the TypeScript implementation. Install it without the registry with fune add ./todo.group-by-due-1.1.0-typescript.fune, or fetch it from a terminal with fune pull todo.group-by-due@1.1.0:typescript.

The whole function, every language, is one file too: todo.group-by-due-1.1.0.fune, 49,637 bytes, sha256 d36f8e49fb579f388a1115d49410ca12ebca4b45e0d52da7f61191aa63236dd6. 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 todo.group-by-due.groupByDue
// fune: before todo.group-by-due.groupByDueWithOrder

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

// fune: after todo.group-by-due.groupByDue
// fune: after todo.group-by-due.groupByDueWithOrder

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.day-of-week in todo.group-by-due
// fune: replace todo.due-status in todo.group-by-due
// fune: replace todo.item in todo.group-by-due

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

// fune: step todo.group-by-due.<fn> 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.

groupByDue 14 tests

CaseArgumentsExpected
an empty list has no sections , 2026-09-28 →
one todo of each kind, in reverse, comes out in section order todos ×7, 2026-09-28 → ×7
overdue is sorted by due date, oldest first todos ×3, 2026-09-28 → ×1
equal due dates keep their input order (stable) todos ×4, 2026-09-28 → ×1
equal overdue dates keep their input order todos ×2, 2026-09-28 → ×1
this week is sorted by due date todos ×3, 2026-09-28 → ×1
today keeps the caller's order todos ×3, 2026-09-28 → ×1
done keeps the caller's order, whatever the dates todos ×3, 2026-09-28 → ×1
no date keeps the caller's order, and empty sections are left out todos ×3, 2026-09-28 → ×2
on Saturday there is no This week: Sunday is tomorrow, Monday is later todos ×3, 2026-10-03 → ×2
Show the other 4 tests
CaseArgumentsExpected
a list that is all done is one Done section todos ×2, 2026-09-28 → ×1
a malformed today is an error even for an empty list , 2026-9-28 → error: is not an ISO date
today with a trailing newline todos ×1, 2026-09-28 → error: is not an ISO date
a due date that never existed todos ×2, 2026-09-28 → error: is not a real calendar date

groupByDueWithOrder 12 tests

CaseArgumentsExpected
input keeps overdue in the caller's order, not by date todos ×2, 2026-09-28, input → ×1
due sorts the same overdue todos oldest first, as groupByDue does todos ×2, 2026-09-28, due → ×1
input keeps this week in the caller's order todos ×2, 2026-09-28, input → ×1
input keeps later in the caller's order todos ×3, 2026-09-28, input → ×1
due sorts later by date todos ×3, 2026-09-28, due → ×1
input still puts the sections in their fixed order todos ×6, 2026-09-28, input → ×6
an empty list has no sections , 2026-09-28, input →
a list sorted by priority stays in priority order inside overdue todos ×2, 2026-09-28, input → ×1
due keeps equal dates in input order (stable) todos ×3, 2026-09-28, due → ×1
manual order across several sections: each keeps its members' input order todos ×4, 2026-09-28, input → ×2
Show the other 2 tests
CaseArgumentsExpected
a malformed today is an error even for an empty list , 28/09/2026, input → error: is not an ISO date
an unknown order is an error , 2026-09-28, manual → error: order must be "due" or "input"

More from the author

Sections always come in this order, and only those with at least one todo are returned:

| status | title | | --- | --- | | overdue | Overdue | | today | Today | | tomorrow | Tomorrow | | this-week | This week | | later | Later | | none | No date | | done | Done |

- **Overdue, This week and Later are sorted by due date**, earliest first, because they span several dates. The sort is stable: todos with the same due date keep their input order. - **Today, Tomorrow, No date and Done keep the input order**, since every todo in them has the same date (or none). So sort first by whatever you prefer (priority, manual order, title) and the grouping keeps it inside each section and among equal dates. - The titles are English. A localised app maps `status` to its own strings. - "This week" is the rest of the ISO week after tomorrow (see todo.due-status): on Saturday and Sunday there is no This week section. - `today` is checked even for an empty list, and a malformed or impossible date anywhere is an error (dates.add-days's messages).

## New in 1.1.0: keeping the caller's order

`groupByDue` re-sorts the sections that span several dates, which is right for a planner sorted by date but wrong for a list in the person's own (manual, drag-and-drop) order: dragging a todo above another in Later would snap back. `groupByDueWithOrder(todos, today, "input")` keeps the order the todos came in, in every section, so sort first (todo.sort's manual order, priority, title...) and the sections show that order. Which section a todo goes in is the same either way.

`groupByDue` is now `groupByDueWithOrder(todos, today, "due")` and answers exactly as 1.0.0 did: every 1.0.0 vector is kept. An `order` other than `"due"` or `"input"` is an error (`order must be "due" or "input", found "manual"`), checked before `today`.

1.0.0 was one function in one file; 1.1.0 is a group of two (see `spec/AUTHORING.md`, Groups), so `import { groupByDue } from "#fune/todo.group-by-due@^1"` keeps working.

Files

PathBytes
README.md2,506
impl/python/group_by_due.py428
impl/python/group_by_due_with_order.py1,445
impl/rust/group_by_due.rs761
impl/rust/group_by_due_with_order.rs2,266
impl/typescript/group_by_due.ts656
impl/typescript/group_by_due_with_order.ts1,730
vectors.json30,662