Function fmty::concat_map_once

source ·
pub fn concat_map_once<I, R, F>(iter: I, f: F) -> ConcatMapOnce<I::IntoIter, F>where
    I: IntoIterator,
    F: Fn(I::Item) -> R,
Expand description

Concatenates mapped Iterator results, at most once.

This is a non-Clone alternative to concat_map(). It uses interior mutability to take ownership of the iterator in the first call to Display::fmt(). As a result, ConcatMapOnce does not implement Sync.

Examples

let value = fmty::concat_map_once(["hola", "mundo"], fmty::to_ascii_uppercase);
assert_eq!(value.to_string(), "HOLAMUNDO");

assert_eq!(value.to_string(), "");