Functional Weave
Code in Rust

todo.list@1.1.0

impl/rust/remove_todo.rs

609 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, todos_to_value};
use super::todo_list_update_todo::index_of_todo;  ← updateTodo, another function of this group · built into the same file, even by a slim install

/// Delete one todo; the others keep their order values (gaps are harmless).
///
/// # Panics
/// On an unknown id.
pub fn remove_todo(todos: &[Todo], id: &str) -> Vec<Todo> {
    let at = index_of_todo(todos, id);
    let mut out = todos.to_vec();
    out.remove(at);
    out
}

pub fn fune_vector(args: &[Value]) -> Value {
    let todos = todos_from_value(&args[0]);
    todos_to_value(&remove_todo(&todos, args[1].as_str()))
}