From f81d23c413869818fb783821358943b2ddb87164 Mon Sep 17 00:00:00 2001 From: Martin Ockajak Date: Sat, 13 Jul 2024 03:06:52 +0200 Subject: [PATCH] . --- src/extensions/sequence.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/extensions/sequence.rs b/src/extensions/sequence.rs index e6df45a..f775916 100644 --- a/src/extensions/sequence.rs +++ b/src/extensions/sequence.rs @@ -245,19 +245,17 @@ pub trait Sequence { let mut chunk_empty = true; unfold(iterator.next(), |previous| { let chunk: Self = unfold(false, |split| { - if *split { - return None; + if !*split { + if let Some(prev) = previous.take() { + if let Some(item) = iterator.next() { + *split = predicate(&prev, &item); + *previous = Some(item); + } + chunk_empty = false; + return Some(prev); + }; }; - if let Some(prev) = previous.take() { - if let Some(item) = iterator.next() { - *split = predicate(&prev, &item); - *previous = Some(item); - } - chunk_empty = false; - Some(prev) - } else { - None - } + None }) .collect(); if chunk_empty {