Last active
August 2, 2024 01:29
-
-
Save orez-/b70566549c30bc3d4ad573ba9e544eaf to your computer and use it in GitHub Desktop.
Cautious variant of take_while.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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