4 stable releases

3.1.0 Dec 21, 2024
3.0.0 Nov 1, 2024
2.0.0 Aug 9, 2024
1.0.0 Aug 7, 2024

#467 in Visualization

Download history 8/week @ 2024-09-17 23/week @ 2024-09-24 41/week @ 2024-10-01 2/week @ 2024-10-08 119/week @ 2024-10-29 3/week @ 2024-11-05 3/week @ 2024-11-19 1/week @ 2024-12-10 103/week @ 2024-12-17 6/week @ 2024-12-24

110 downloads per month

MIT license

16KB
246 lines

split-every

crates.io version github.com forks github.com stars crates.io downloads


use split_every::prelude::*;

// This prints: [(0, 0), (0, 1)]
//              [(0, 0)]
//              [(0, 1), (0, 0)]
//              [(0, 1)]
let mut splitter: SplitEvery<&[(u8, u8)], &[(u8, u8)]> = [
    (0, 0), (0, 1), (0, 0),
    (0, 0), (0, 0), (0, 1),
    (0, 0), (0, 0), (0, 1),
].split_every_n_times(&[(0, 0)], 2);
println!("{:?}", splitter.next().unwrap());
println!("{:?}", splitter.next().unwrap());
println!("{:?}", splitter.next().unwrap());
println!("{:?}", splitter.next().unwrap());

// This prints: "Oh hi there"
//              "I don't really"
//              "know what to"
//              "say".
let mut splitter: SplitEvery<&str, &str> =
    "Oh hi there I don't really know what to say".split_every_n_times(" ", 3);
println!("{:?}", splitter.next().unwrap());
println!("{:?}", splitter.next().unwrap());
println!("{:?}", splitter.next().unwrap());
println!("{:?}", splitter.next().unwrap());

// This prints: ["This", "is", "you", "This"]
//              ["me", "This", "is", "someone", "This"]
//              ["them"]
let mut splitter: SplitEvery<Box<dyn FnMut() -> Option<&'static str>>, &str> = [
    ["This", "is", "you"],
    ["This", "is", "me"],
    ["This", "is", "someone"],
    ["This", "is", "them"],
]
.iter()
.flatten()
.copied()
.split_every_n_times("is", 2);
println!("{:?}", splitter.next().unwrap());
println!("{:?}", splitter.next().unwrap());
println!("{:?}", splitter.next().unwrap());

// This prints: ["This", "is", "you", "This"]
//              ["me", "This", "is", "someone", "This"]
//              ["them"]
let mut iter = [
    ["This", "is", "you"],
    ["This", "is", "me"],
    ["This", "is", "someone"],
    ["This", "is", "them"],
].iter().flatten().map(|val| *val);
let mut splitter: SplitEvery<Box<dyn FnMut() -> Option<&'static str>>, &str> =
    SplitEvery::n_times_from_fn(Box::new(move || iter.next()), "is", 2);
println!("{:?}", splitter.next().unwrap());
println!("{:?}", splitter.next().unwrap());
println!("{:?}", splitter.next().unwrap());

✨ Split For Every N Occurrences Of A Pattern Iteratively

This crate helps you split data for every n occurrences of a pattern.
It contains an exclusive iterator.


📄 Licensing

split-every is licensed under the MIT LICENSE; This is the summarization.

No runtime deps