#iterator #lazy-evaluation #or

or-iterator

Rust iterator which takes two iterators and returns non-empty one

2 releases

0.1.1 May 2, 2020
0.1.0 May 2, 2020

#1814 in Algorithms

MIT license

9KB
195 lines

or-iterator

Crates.io docs.rs License

Rust iterator which takes two iterators and return not empty one

use or_iterator::OrIterator;

let v1 = vec![1, 2, 3];
let v2 = vec![4, 5];
let or = v1.iter().or(v2.iter());
assert_eq!(3, or.count());

let v1 = vec![];
let v2 = vec![4, 5];
let or = v1.iter().or(v2.iter());
assert_eq!(2, or.count());

Thanks to

Frank Steffahn (https://internals.rust-lang.org/u/steffahn)


lib.rs:

Examples

use or_iterator::OrIterator;

let v1 = vec![1, 2, 3];
let v2 = vec![4, 5];
let or = v1.iter().or(v2.iter());
assert_eq!(3, or.count());

let v1 = vec![];
let v2 = vec![4, 5];
let or = v1.iter().or(v2.iter());
assert_eq!(2, or.count());

No runtime deps