use anyhow::Result;
use itertools::Itertools;
fn main() -> Result<()> {
let ns = vec![2, 2, 3, 3, 4, 4, 5, 5];
let chunk = ns.iter().chunk_by(|n| *n % 2 == 0);
// let chunk = chunked(ns.iter());
let group = chunk.into_iter().take(2);
for (even, ns) in group {
println!("{} {:?}", even, ns.collect::<Vec<_>>());
}
Ok(())
}
// Don't know how to write the return type.
// Note that impl IntoIterator is not an option.
// the trait `IntoIterator` is implemented
// - for `&itertools::ChunkBy<K, I, F>`
// - not `itertools::ChunkBy<K, I, F>`
//
// fn chunked(ns: impl Iterator<Item = i32>) -> impl IntoIterator {
// ns.chunk_by(|n| *n % 2 == 0)
// }