Skip to content

Instantly share code, notes, and snippets.

@orez-
orez- / take_while_eq.rs
Last active August 2, 2024 01:29
Cautious variant of take_while.
use std::iter::{from_fn, Peekable};
fn take_while_eq<I>(it: &mut Peekable<I>, eq: I::Item) -> impl Iterator<Item = I::Item> + '_
where
I: Iterator,
I::Item: Eq,
{
from_fn(move || it.next_if_eq(&eq))
}