MCPcopy Create free account
hub / github.com/docknetwork/crypto / seq_pairs_satisfy

Function seq_pairs_satisfy

utils/src/misc.rs:18–36  ·  view source on GitHub ↗

Ensures that each sequence pair satisfy provided predicate.

(mut validate: F)

Source from the content-addressed store, hash-verified

16
17/// Ensures that each sequence pair satisfy provided predicate.
18pub fn seq_pairs_satisfy<I, F>(mut validate: F) -> impl FnMut(&I) -> Option<InvalidPair<I>>
19where
20 I: Clone,
21 F: FnMut(&I, &I) -> bool,
22{
23 let mut last = None;
24
25 move |item: &I| -> Option<InvalidPair<I>> {
26 if let Some((prev, _)) = last
27 .replace(item.clone())
28 .zip(last.as_ref())
29 .filter(|(prev, cur)| !validate(prev, cur))
30 {
31 Some(InvalidPair(prev, item.clone()))
32 } else {
33 None
34 }
35 }
36}
37
38/// Produces a function which will check for each item to be equal previous plus `n` starting from the supplied value.
39pub fn seq_inc_by_n_from<N>(

Callers 10

verify_comMethod · 0.85
response_for_messageMethod · 0.85
verify_responseMethod · 0.85
newMethod · 0.85
unblindMethod · 0.85
commit_to_messagesMethod · 0.85
commit_to_messagesMethod · 0.85

Calls 4

InvalidPairClass · 0.85
cloneMethod · 0.80
validateFunction · 0.70
as_refMethod · 0.45

Tested by 2