Function maybe_rayon::iter::once

source ·
pub fn once<T>(item: T) -> Once<T>where
    T: Send,
Expand description

Creates a parallel iterator that produces an element exactly once.

This admits no parallelism on its own, but it could be chained to existing parallel iterators to extend their contents, or otherwise used for any code that deals with generic parallel iterators.

Examples

use rayon::prelude::*;
use rayon::iter::once;

let pi = (0..1234).into_par_iter()
    .chain(once(-1))
    .chain(1234..10_000);

assert_eq!(pi.clone().count(), 10_001);
assert_eq!(pi.clone().filter(|&x| x < 0).count(), 1);
assert_eq!(pi.position_any(|x| x < 0), Some(1234));