Functional Weave
Code in Rust

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. group_by_due (todos: Todo[], today: date) -> DueGroup[]
  2. group_by_due_with_order (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.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DueGroup {
    pub status: String,
    /// Overdue, Today, Tomorrow, This week, Later, No date or Done
    pub title: String,
    pub todos: Vec<Todo>,
}

// SectionOrder is a string in Rust, one of: "due", "input".
// Parameters take it as &str and results hold it as String.

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

group_by_due throws on bad input 14 tests

pub fn group_by_due(todos: &[Todo], today: &str) -> Vec<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

  • group_by_due(, 2026-09-28) → an empty list has no sections
  • group_by_due(todos ×7, 2026-09-28) → ×7 one todo of each kind, in reverse, comes out in section order
  • group_by_due(todos ×3, 2026-09-28) → ×1 overdue is sorted by due date, oldest first
fune!(todo.group-by-due@^1);  // then call group_by_due(…)
impl/rust/group_by_due.rs · 19 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.

use super::funejson::Value;  ← the fune runtime: the JSON value the test vectors use; fune build keeps it only where a signature takes one
use super::todo_group_by_due_group_by_due_with_order::{due_group_to_value, group_by_due_with_order};  ← groupByDueWithOrder, another function of this group · built into the same file, even by a slim install
use super::todo_item::Todo;  ← from todo.item ^1.0.0 · built alongside by fune
use super::todo_item_validate_todo::todos_from_value;

/// 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.
///
/// # Panics
/// Panics on an impossible or malformed date.
pub fn group_by_due(todos: &[Todo], today: &str) -> Vec<DueGroup> {
    group_by_due_with_order(todos, today, "due")
}

pub fn fune_vector(args: &[Value]) -> Value {
    let groups = group_by_due(&todos_from_value(&args[0]), args[1].as_str());
    Value::Arr(groups.iter().map(due_group_to_value).collect())
}

group_by_due_with_order throws on bad input 12 tests

pub fn group_by_due_with_order(todos: &[Todo], today: &str, order: &str) -> Vec<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

  • group_by_due_with_order(todos ×2, 2026-09-28, input) → ×1 input keeps overdue in the caller's order, not by date
  • group_by_due_with_order(todos ×2, 2026-09-28, due) → ×1 due sorts the same overdue todos oldest first, as groupByDue does
  • group_by_due_with_order(todos ×2, 2026-09-28, input) → ×1 input keeps this week in the caller's order
fune!(todo.group-by-due@^1);  // then call group_by_due_with_order(…)
impl/rust/group_by_due_with_order.rs · 60 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.

use super::funejson::Value;  ← the fune runtime: the JSON value the test vectors use; fune build keeps it only where a signature takes one
use super::dates_day_of_week::day_of_week;  ← from dates.day-of-week ^1.0.0 · built alongside by fune
use super::todo_due_status::due_status;  ← from todo.due-status ^1.0.0 · built alongside by fune
use super::todo_item::Todo;  ← from todo.item ^1.0.0 · built alongside by fune
use super::todo_item_validate_todo::{todos_from_value, todos_to_value};

const SECTIONS: [(&str, &str); 7] = [
    ("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 are sorted by due date,
/// stably; with "input" every section keeps the caller's order.
///
/// # Panics
/// Panics on an unknown order, or an impossible or malformed date.
pub fn group_by_due_with_order(todos: &[Todo], today: &str, order: &str) -> Vec<DueGroup> {
    if order != "due" && order != "input" {
        panic!("order must be \"due\" or \"input\", found \"{}\"", order);
    }
    day_of_week(today); // a bad today is an error even for an empty list
    let statuses: Vec<String> = todos.iter().map(|todo| due_status(todo, today)).collect();
    let mut groups = Vec::new();
    for (status, title) in SECTIONS.iter() {
        let mut members: Vec<Todo> = todos
            .iter()
            .zip(statuses.iter())
            .filter(|(_, s)| s.as_str() == *status)
            .map(|(todo, _)| todo.clone())
            .collect();
        if members.is_empty() {
            continue;
        }
        if order == "due" && matches!(*status, "overdue" | "this-week" | "later") {
            // sort_by is stable, so equal dates keep input order.
            members.sort_by(|a, b| a.due.cmp(&b.due));
        }
        groups.push(DueGroup { status: status.to_string(), title: title.to_string(), todos: members });
    }
    groups
}

pub fn due_group_to_value(group: &DueGroup) -> Value {
    Value::obj(vec![
        ("status", Value::str(&group.status)),
        ("title", Value::str(&group.title)),
        ("todos", todos_to_value(&group.todos)),
    ])
}

pub fn fune_vector(args: &[Value]) -> Value {
    let groups = group_by_due_with_order(&todos_from_value(&args[0]), args[1].as_str(), args[2].as_str());
    Value::Arr(groups.iter().map(due_group_to_value).collect())
}

Install

fune build

With that line in your source, in a Rust project (language rust in fune.project), fune build resolves it and its 3 dependencies, pins them in fune.lock, downloads only the Rust 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. A crate’s build.rs runs it before every compile. 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 Rust todo.group-by-due-1.1.0-rust.fune · 44,985 bytes sha256 6c947cf027f63c306fa65935a74bb1326d605dc2336f39a17d21d9a58116a09d

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

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