Functional Weave
Code in Python

todo.import-csv@1.1.0

impl/rust/import_csv.rs

768 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_import_csv_validate_todo_csv::read_todo_csv;  ← validateTodoCsv, another function of this group · built into the same file, even by a slim install
use super::todo_item::{todos_to_value, Todo};  ← from todo.item ^1.0.0 · built alongside by fune

/// Todos from CSV: the 13 columns in any order, CRLF or LF, an optional
/// byte order mark. Every row is checked with validate_todo.
///
/// # Panics
/// With "row N: ..." (the header is row 1) on the first malformed or invalid
/// row, or on a header without exactly the 13 columns. validate_todo_csv
/// lists every problem instead.
pub fn import_csv(csv: &str) -> Vec<Todo> {
    let reading = read_todo_csv(csv);
    if let Some(first) = reading.problems.first() {
        panic!("{}", first.thrown);
    }
    reading.todos
}

pub fn fune_vector(args: &[Value]) -> Value {
    todos_to_value(&import_csv(args[0].as_str()))
}