Functional Weave
Code in Rust

todo.group-by-due@1.1.0

impl/rust/group_by_due.rs

761 bytes · the Rust implementation · view 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())
}