1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Distinctness: lazy dedup and short-circuiting checks.
//
// Spliced into the `FluentIter` trait by `build.rs`. Names resolve in
// the crate-root scope of `lib.rs`, exactly as before the split.
/// ⇔ `.distinct()` on hashable items: keeps the **first** occurrence of
/// every item. Lazy — buffers only the seen-set, and short-circuits
/// downstream (`take(k)` stops pulling once `k` uniques are out).
///
/// `Item` must be `Clone` (like `itertools::unique`): the set retains a
/// copy of each value to compare against while the occurrence itself is
/// yielded. Use [`FluentIter::distinct_by`] when cloning is not
/// available — it tracks borrowed keys instead.
///
/// ```
/// use fluent_iterable::FluentIter;
///
/// let out: Vec<i32> = [1, 2, 1, 3, 2].into_iter().distinct().collect();
/// assert_eq!(out, vec![1, 2, 3]);
/// ```
/// ⇔ `.distinct(keyFn)`: keep the **first** item seen for each key.
///
/// Purely lazy — buffers only the seen-key set, never the sequence, so
/// `take(k)` stops pulling the source once `k` distinct keys are out.
///
/// ```
/// use fluent_iterable::FluentIter;
///
/// let out: Vec<&str> = ["bb", "a1", "b1", "a2", "c"]
/// .into_iter()
/// .distinct_by(|s| s.chars().next().unwrap())
/// .collect();
/// assert_eq!(out, vec!["bb", "a1", "c"]);
/// ```
/// ⇔ `.isDistinct()`: are all items unique? Short-circuits on the first
/// duplicate (the source is not drained).
///
/// ```
/// use fluent_iterable::FluentIter;
///
/// assert!([1, 2, 3].into_iter().is_distinct());
/// assert!(![1, 2, 1].into_iter().is_distinct());
/// ```
// npm parity names (`isDistinct`/`isDistinctBy`): these consume the
// iterator instead of taking &mut self, because Iterator::all needs an
// owned chain through the extension trait.
/// ⇔ `.isDistinct(keyFn)`: is every key unique? Short-circuits on the
/// first repetition.
///
/// ```
/// use fluent_iterable::FluentIter;
///
/// assert!([("a", 1), ("b", 2)].into_iter().is_distinct_by(|(k, _)| *k));
/// assert!(![("a", 1), ("b", 2), ("a", 3)].into_iter().is_distinct_by(|(k, _)| *k));
/// ```