Skip to content

Instantly share code, notes, and snippets.

@orez-
Last active August 2, 2024 01:29
Show Gist options
  • Save orez-/b70566549c30bc3d4ad573ba9e544eaf to your computer and use it in GitHub Desktop.
Save orez-/b70566549c30bc3d4ad573ba9e544eaf to your computer and use it in GitHub Desktop.
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))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment