Skip to content

Instantly share code, notes, and snippets.

@orez-
Created August 15, 2023 01:27
Show Gist options
  • Save orez-/c0a1ec2e0ac8da94b9742f2b453537d8 to your computer and use it in GitHub Desktop.
Save orez-/c0a1ec2e0ac8da94b9742f2b453537d8 to your computer and use it in GitHub Desktop.
fn into_iter(list: Option<Box<ListNode>>) -> LLIntoIter {
LLIntoIter(list)
}
struct LLIntoIter(Option<Box<ListNode>>);
impl Iterator for LLIntoIter {
type Item = Box<ListNode>;
fn next(&mut self) -> Option<Box<ListNode>> {
let mut node = self.0.take()?;
self.0 = node.next.take();
Some(node)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment