Functional Weave
Code in Python

todo.list@1.1.0

impl/rust/toggle_all_mode.rs

554 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_item::Todo;  ← from todo.item ^1.0.0 · built alongside by fune
use super::todo_item_validate_todo::todos_from_value;

/// What toggle_all would do: "complete" while any todo is open, "reopen"
/// once none is, "none" for an empty list.
pub fn toggle_all_mode(todos: &[Todo]) -> String {
    if todos.is_empty() {
        return "none".to_string();
    }
    if todos.iter().any(|t| !t.done) { "complete".to_string() } else { "reopen".to_string() }
}

pub fn fune_vector(args: &[Value]) -> Value {
    Value::str(&toggle_all_mode(&todos_from_value(&args[0])))
}