MCPcopy Create free account
hub / github.com/daniel-e/rustml / vec_to_csv

Function vec_to_csv

src/csv.rs:22–32  ·  view source on GitHub ↗

Converts a vector into a comma seperated list of values. As delimiter the string `sep` is used. # Example ``` use rustml::csv::vec_to_csv; let a = &[1, 2, 3]; assert_eq!(vec_to_csv(a, ","), "1,2,3"); ```

(v: &[T], sep: &str)

Source from the content-addressed store, hash-verified

20/// assert_eq!(vec_to_csv(a, ","), "1,2,3");
21/// ```
22pub fn vec_to_csv<T: fmt::Display>(v: &[T], sep: &str) -> String {
23
24 v.iter().enumerate()
25 .map(|(c, val)|
26 match c {
27 0 => format!("{}", val),
28 _ => format!("{}{}", sep, val)
29 }
30 )
31 .fold(String::new(), |s, val| s + &val)
32}
33
34/// Converts a matrix into a comma seperated list of values.
35///

Callers 1

matrix_to_csvFunction · 0.85

Calls 2

mapMethod · 0.80
iterMethod · 0.45

Tested by

no test coverage detected