|
12 | 12 | --- |
13 | 13 |
|
14 | 14 | ```rust |
15 | | -use split_every::{SplitEveryImpl, SplitEvery}; |
| 15 | +use split_every::prelude::*; |
| 16 | + |
| 17 | +// This prints: [(0, 0), (0, 1)] |
| 18 | +// [(0, 0)] |
| 19 | +// [(0, 1), (0, 0)] |
| 20 | +// [(0, 1)] |
| 21 | +let mut splitter: SplitEvery<&[(u8, u8)], &[(u8, u8)]> = [ |
| 22 | + (0, 0), (0, 1), (0, 0), |
| 23 | + (0, 0), (0, 0), (0, 1), |
| 24 | + (0, 0), (0, 0), (0, 1), |
| 25 | +].split_every_n_times(&[(0, 0)], 2); |
| 26 | +println!("{:?}", splitter.next().unwrap()); |
| 27 | +println!("{:?}", splitter.next().unwrap()); |
| 28 | +println!("{:?}", splitter.next().unwrap()); |
| 29 | +println!("{:?}", splitter.next().unwrap()); |
| 30 | + |
16 | 31 | // This prints: "Oh hi there" |
17 | 32 | // "I don't really" |
18 | 33 | // "know what to" |
19 | 34 | // "say". |
20 | | -let mut splitter: SplitEvery<&str> = |
| 35 | +let mut splitter: SplitEvery<&str, &str> = |
21 | 36 | "Oh hi there I don't really know what to say".split_every_n_times(" ", 3); |
22 | | -println!("{}", splitter.next().unwrap()); |
23 | | -println!("{}", splitter.next().unwrap()); |
24 | | -println!("{}", splitter.next().unwrap()); |
25 | | -println!("{}", splitter.next().unwrap()); |
| 37 | +println!("{:?}", splitter.next().unwrap()); |
| 38 | +println!("{:?}", splitter.next().unwrap()); |
| 39 | +println!("{:?}", splitter.next().unwrap()); |
| 40 | +println!("{:?}", splitter.next().unwrap()); |
| 41 | + |
| 42 | +// This prints: ["This", "is", "you", "This"] |
| 43 | +// ["me", "This", "is", "someone", "This"] |
| 44 | +// ["them"] |
| 45 | +let mut iter = [ |
| 46 | + ["This", "is", "you"], |
| 47 | + ["This", "is", "me"], |
| 48 | + ["This", "is", "someone"], |
| 49 | + ["This", "is", "them"], |
| 50 | +].iter().flatten().map(|val| *val); |
| 51 | +let mut splitter: SplitEvery<Box<dyn FnMut() -> Option<&'static str>>, &str> = |
| 52 | + SplitEvery::n_times_from_fn(Box::new(move || iter.next()), "is", 2); |
| 53 | +println!("{:?}", splitter.next().unwrap()); |
| 54 | +println!("{:?}", splitter.next().unwrap()); |
| 55 | +println!("{:?}", splitter.next().unwrap()); |
26 | 56 | ``` |
27 | 57 |
|
28 | 58 | --- |
29 | 59 |
|
30 | 60 | ## ✨ Split For Every N Occurrences Of A Pattern Iteratively |
31 | 61 |
|
32 | | -This crate **helps you** split a `string` for every `n` occurrences of a `pattern`. |
| 62 | +This crate **helps you** split data for every `n` occurrences of a `pattern`. |
33 | 63 | It contains an exclusive `iterator`. |
34 | 64 |
|
35 | 65 | --- |
|
0 commit comments