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
//! This submodule provides utilities for selecting elements from collections based on logical predicates.
//!
//! Useful for applications such as enforcing uniquenes or extracting anomalies based on logical rules.
use ;
/// Selects elements that satisfy the predicate.
///
/// Equivalent to **_{x ∈ self | pred(x)}_**.
/// ## Arguments
/// - `iter` - The collection to filter.
/// - `pred` - The predicate to use for filtering.
/// ## Returns
/// - A `Vec<&T>` containing all matching elements.
/// ## Example
/// ```
/// use quantor::quantifiers::select_where;
///
/// let numbers = vec!(0, 1, 2, 3);
///
/// assert_eq!(select_where(&numbers, |x| x % 2 == 0), vec!(&0, &2));
/// ```
/// Selects elements that satisfy the predicate and returns only unique matches.
///
/// Equivalent to **_distinct({x ∈ self | pred(x)})_**.
/// ## Arguments
/// - `iter` - The collection to filter.
/// - `pred` - The predicate to use for filtering.
/// ## Returns
/// - A `Vec<&T>` of matching elements with duplicates removed.
/// ## Example
/// ```
/// use quantor::quantifiers::select_unique;
///
/// let numbers = vec!(0, 1, 2, 2, 3);
///
/// assert_eq!(select_unique(&numbers, |x| x % 2 == 0), vec!(&0, &2));
/// ```
/// Selects all duplicate elements in the collection.
///
/// Equivalent to **_{x ∈ self | count(x) > 1}_**.
/// ## Arguments
/// - `iter` - The collection to filter.
/// ## Returns
/// - A `Vec<&T>` containing all duplicates found.
/// ## Example
/// ```
/// use quantor::quantifiers::select_duplicates;
///
/// let numbers = vec!(0, 1, 2, 2, 3);
///
/// assert_eq!(select_duplicates(&numbers), vec!(&2));
/// ```