Add split and split_inclusive#1060
Conversation
Collect all iterator elements into one of two partitions. Unlike [`Iterator::partition`], when predicate returns true for the first time, it collects this element and all rest elements into B. ```rust use itertools::Itertools; let nums = vec![0, 1, 2, 3, 4, 5]; let (a, b): (Vec<_>, Vec<_>) = nums.into_iter().split(|n| *n == 3); assert_eq!(a, [0, 1, 2]); assert_eq!(b, [3, 4, 5]); ``` --- Collect all iterator elements into one of two partitions. Unlike [`Itertools::split`], when predicate returns true, the element is collected into A ```rust use itertools::Itertools; let nums = vec![0, 1, 2, 3, 4, 5]; let (a, b): (Vec<_>, Vec<_>) = nums.into_iter().split_inclusive(|n| *n == 3); assert_eq!(a, [0, 1, 2, 3]); assert_eq!(b, [4, 5]); ```
12843a5 to
02a78ac
Compare
|
Hi there. Honestly, I doubt this is really required from an API prospective, because afaik it can be expressed in terms of Thus, I suggest to close this. |
|
Closing this. It can straightforwardly be implemented in terms of |
|
The implementation of |
True, but at the cost that "swithing to the other container" is possible at most once. This begs the question "what does On top, it still does the |
|
Okay, although the Using external flags to mark split points is really cumbersome and semantically ambiguous ... |
If the judgment conditions are complex, it is necessary to replace |
Collect all iterator elements into one of two partitions.
Unlike [
Iterator::partition], when predicate returns true for the first time,it collects this element and all rest elements into B.
Collect all iterator elements into one of two partitions.
Unlike [
Itertools::split], when predicate returns true, the element is collected into A