Skip to main content

map

Function map 

Source
pub fn map<T, U, E, F>(items: Vec<T>, f: F) -> Result<Vec<U>, MapError>
where F: FnMut(T) -> Result<U, E>, E: Display,
Expand description

Applies f to items sequentially and returns results in their original order.

Each successful input is evaluated exactly once. Evaluation stops at the first callback error, and trailing unconsumed items are dropped naturally. Errors report a zero-based input index and a message truncated at a UTF-8 character boundary to at most 4096 bytes. This serial operation has no serde, Send, Sync, or 'static requirements.

ยงExample

use hataori::map;

let doubled = map(vec![1, 2, 3], |item| {
    Ok::<_, std::convert::Infallible>(item * 2)
})
.unwrap();
assert_eq!(doubled, vec![2, 4, 6]);