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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//! Determines whether an iterator is sorted.
//!
//! Code for this module is inspired by the crate [`is_sorted`](https://docs.rs/is_sorted/0.1.1/is_sorted/trait.IsSorted.html).
//! See below for the copyright and license. The OAT developers originally attempted to use the `is_sorted` crate as a dependency but encountered build issues.
//!
//!
//!
//! > Copyright (c) 2018 Gonzalo Brito Gadeschi Copyright (c) 2017 The Rust Project Developers
//! >
//! > Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//! >
//! > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//! >
//! > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
use Itertools;
use crateJudgePartialOrder;
/// Checks consecutive pairs of elements in an iterator with a provided closure.
///
/// The function iterates over consecutive pairs of elements in the given iterator
/// and applies the provided closure to each pair. If the closure returns `false`
/// for any pair, the function returns `Some((index, item1, item2))` where `index`
/// is the position of the first element of the pair, and `item1` and `item2` are
/// the elements that caused the closure to return `false`. If the closure returns
/// `true` for all pairs, the function returns `None`.
///
/// # Parameters
///
/// - `iter`: An iterator of type `I`.
/// - `f`: A closure of type `F` that takes two references to items from the iterator
/// and returns a `bool`.
///
/// # Returns
///
/// `Option<(usize, I::Item, I::Item)>`:
/// - `Some((index, item1, item2))` if the closure returns `false` for any pair,
/// where `index` is the position of the first element of the pair, and `item1`
/// and `item2` are the elements that did not satisfy the closure.
/// - `None` if the closure returns `true` for all pairs.
///
/// # Examples
///
/// ```
/// use itertools::Itertools;
/// use oat_rust::utilities::iterators::is_sorted::check_pairs;
///
/// let vec = vec![1, 2, 3, 5, 4];
/// let result = check_pairs(vec.iter(), |a, b| a < b);
///
/// match result {
/// Some((index, a, b)) => {
/// println!("Pair at index {}: ({:?}, {:?}) does not satisfy the condition", index, a, b);
/// }
/// None => println!("All pairs satisfy the condition"),
/// }
/// ```
///
/// This example checks if each element in the vector is less than the next element.
/// It will print that the pair `(5, 4)` at index 3 does not satisfy the condition.
// =========================================================================================================
// TESTS
// =========================================================================================================
// ---------------------------------------------------------------------
// Doc-test drafts
// ---------------------------------------------------------------------
// We use the following module to draft doc tests, which are easier to debug here than in doc strings.