Skip to content

Commit 60793c3

Browse files
committed
✨ v3.0.0
1 parent 504f6df commit 60793c3

3 files changed

Lines changed: 256 additions & 139 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "split-every"
3-
version = "2.0.0"
3+
version = "3.0.0"
44
edition = "2021"
55
authors = ["JumperBot_"]
66
description = "Split for every n occurrences of a pattern iteratively!"

README.md

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,54 @@
1212
---
1313

1414
```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+
1631
// This prints: "Oh hi there"
1732
// "I don't really"
1833
// "know what to"
1934
// "say".
20-
let mut splitter: SplitEvery<&str> =
35+
let mut splitter: SplitEvery<&str, &str> =
2136
"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());
2656
```
2757

2858
---
2959

3060
## ✨ Split For Every N Occurrences Of A Pattern Iteratively
3161

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`.
3363
It contains an exclusive `iterator`.
3464

3565
---

0 commit comments

Comments
 (0)