Skip to content

Commit 956820a

Browse files
committed
fix(iter): Improve readability of names
The goal is to make the inention of the functions ore obvious especially as we add inverses of these. Fixes #24 BREAKING CHANGE: Renamed functions and structs - `contains` -> `in_iter` - `contains_hashable` -> `in_hash` - `ContainsPredicate::ord` -> `ContainsPredicate::sort`
1 parent 3905e10 commit 956820a

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

src/iter.rs

+26-26
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,26 @@ use Predicate;
2020
/// Note that this implementation places the fewest restrictions on the
2121
/// underlying `Item` type at the expense of having the least performant
2222
/// implementation (linear search). If the type to be searched is `Hash + Eq`,
23-
/// it is much more efficient to use `HashableContainsPredicate` and
24-
/// `contains_hashable`. The implementation-specific predicates will be
23+
/// it is much more efficient to use `HashableInPredicate` and
24+
/// `in_hash`. The implementation-specific predicates will be
2525
/// deprecated when Rust supports trait specialization.
2626
#[derive(Debug)]
27-
pub struct ContainsPredicate<T>
27+
pub struct InPredicate<T>
2828
where
2929
T: PartialEq,
3030
{
3131
inner: Vec<T>,
3232
}
3333

34-
impl<T> ContainsPredicate<T>
34+
impl<T> InPredicate<T>
3535
where
3636
T: Ord,
3737
{
3838
/// Creates a new predicate that will return `true` when the given `variable` is
3939
/// contained with the set of items provided.
4040
///
4141
/// Note that this implementation requires `Item` to be `Ord`. The
42-
/// `ContainsPredicate` uses a less efficient search algorithm but only
42+
/// `InPredicate` uses a less efficient search algorithm but only
4343
/// requires `Item` implement `PartialEq`. The implementation-specific
4444
/// predicates will be deprecated when Rust supports trait specialization.
4545
///
@@ -48,21 +48,21 @@ where
4848
/// ```
4949
/// use predicates::prelude::*;
5050
///
51-
/// let predicate_fn = predicate::contains(vec![1, 3, 5]).ord();
51+
/// let predicate_fn = predicate::in_iter(vec![1, 3, 5]).sort();
5252
/// assert_eq!(true, predicate_fn.eval(&1));
5353
/// assert_eq!(false, predicate_fn.eval(&2));
5454
/// assert_eq!(true, predicate_fn.eval(&3));
5555
/// assert_eq!(false, predicate_fn.eval(&4));
5656
/// assert_eq!(true, predicate_fn.eval(&5));
5757
/// ```
58-
pub fn ord(self) -> OrdContainsPredicate<T> {
58+
pub fn sort(self) -> OrdInPredicate<T> {
5959
let mut items = self.inner;
6060
items.sort();
61-
OrdContainsPredicate { inner: items }
61+
OrdInPredicate { inner: items }
6262
}
6363
}
6464

65-
impl<T> Predicate<T> for ContainsPredicate<T>
65+
impl<T> Predicate<T> for InPredicate<T>
6666
where
6767
T: PartialEq,
6868
{
@@ -77,28 +77,28 @@ where
7777
/// Note that this implementation places the fewest restrictions on the
7878
/// underlying `Item` type at the expense of having the least performant
7979
/// implementation (linear search). If the type to be searched is `Hash + Eq`,
80-
/// it is much more efficient to use `HashableContainsPredicate` and
81-
/// `contains_hashable`. The implementation-specific predicates will be
80+
/// it is much more efficient to use `HashableInPredicate` and
81+
/// `in_hash`. The implementation-specific predicates will be
8282
/// deprecated when Rust supports trait specialization.
8383
///
8484
/// # Examples
8585
///
8686
/// ```
8787
/// use predicates::prelude::*;
8888
///
89-
/// let predicate_fn = predicate::contains(vec![1, 3, 5]);
89+
/// let predicate_fn = predicate::in_iter(vec![1, 3, 5]);
9090
/// assert_eq!(true, predicate_fn.eval(&1));
9191
/// assert_eq!(false, predicate_fn.eval(&2));
9292
/// assert_eq!(true, predicate_fn.eval(&3));
9393
/// assert_eq!(false, predicate_fn.eval(&4));
9494
/// assert_eq!(true, predicate_fn.eval(&5));
9595
/// ```
96-
pub fn contains<I, T>(iter: I) -> ContainsPredicate<T>
96+
pub fn in_iter<I, T>(iter: I) -> InPredicate<T>
9797
where
9898
T: PartialEq,
9999
I: IntoIterator<Item = T>,
100100
{
101-
ContainsPredicate {
101+
InPredicate {
102102
inner: Vec::from_iter(iter),
103103
}
104104
}
@@ -107,20 +107,20 @@ where
107107
/// set, otherwise returns `false`.
108108
///
109109
/// Note that this implementation requires `Item` to be `Ord`. The
110-
/// `ContainsPredicate` uses a less efficient search algorithm but only
110+
/// `InPredicate` uses a less efficient search algorithm but only
111111
/// requires `Item` implement `PartialEq`. The implementation-specific
112112
/// predicates will be deprecated when Rust supports trait specialization.
113113
///
114-
/// This is created by the `predicate::contains(...).ord` function.
114+
/// This is created by the `predicate::in_iter(...).sort` function.
115115
#[derive(Debug)]
116-
pub struct OrdContainsPredicate<T>
116+
pub struct OrdInPredicate<T>
117117
where
118118
T: Ord,
119119
{
120120
inner: Vec<T>,
121121
}
122122

123-
impl<T> Predicate<T> for OrdContainsPredicate<T>
123+
impl<T> Predicate<T> for OrdInPredicate<T>
124124
where
125125
T: Ord,
126126
{
@@ -133,20 +133,20 @@ where
133133
/// `HashSet`, otherwise returns `false`.
134134
///
135135
/// Note that this implementation requires `Item` to be `Hash + Eq`. The
136-
/// `ContainsPredicate` uses a less efficient search algorithm but only
136+
/// `InPredicate` uses a less efficient search algorithm but only
137137
/// requires `Item` implement `PartialEq`. The implementation-specific
138138
/// predicates will be deprecated when Rust supports trait specialization.
139139
///
140-
/// This is created by the `predicate::contains_hashable` function.
140+
/// This is created by the `predicate::in_hash` function.
141141
#[derive(Debug)]
142-
pub struct HashableContainsPredicate<T>
142+
pub struct HashableInPredicate<T>
143143
where
144144
T: Hash + Eq,
145145
{
146146
inner: HashSet<T>,
147147
}
148148

149-
impl<T> Predicate<T> for HashableContainsPredicate<T>
149+
impl<T> Predicate<T> for HashableInPredicate<T>
150150
where
151151
T: Hash + Eq,
152152
{
@@ -159,7 +159,7 @@ where
159159
/// contained with the set of items provided.
160160
///
161161
/// Note that this implementation requires `Item` to be `Hash + Eq`. The
162-
/// `ContainsPredicate` uses a less efficient search algorithm but only
162+
/// `InPredicate` uses a less efficient search algorithm but only
163163
/// requires `Item` implement `PartialEq`. The implementation-specific
164164
/// predicates will be deprecated when Rust supports trait specialization.
165165
///
@@ -168,19 +168,19 @@ where
168168
/// ```
169169
/// use predicates::prelude::*;
170170
///
171-
/// let predicate_fn = predicate::contains_hashable(vec![1, 3, 5]);
171+
/// let predicate_fn = predicate::in_hash(vec![1, 3, 5]);
172172
/// assert_eq!(true, predicate_fn.eval(&1));
173173
/// assert_eq!(false, predicate_fn.eval(&2));
174174
/// assert_eq!(true, predicate_fn.eval(&3));
175175
/// assert_eq!(false, predicate_fn.eval(&4));
176176
/// assert_eq!(true, predicate_fn.eval(&5));
177177
/// ```
178-
pub fn contains_hashable<I, T>(iter: I) -> HashableContainsPredicate<T>
178+
pub fn in_hash<I, T>(iter: I) -> HashableInPredicate<T>
179179
where
180180
T: Hash + Eq,
181181
I: IntoIterator<Item = T>,
182182
{
183-
HashableContainsPredicate {
183+
HashableInPredicate {
184184
inner: HashSet::from_iter(iter),
185185
}
186186
}

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
//! }
7070
//!
7171
//! assert_eq!(true, IsTheAnswer.eval(&42));
72-
//! let almost_the_answer = IsTheAnswer.or(predicate::contains(vec![41, 43]));
72+
//! let almost_the_answer = IsTheAnswer.or(predicate::in_iter(vec![41, 43]));
7373
//! assert_eq!(true, almost_the_answer.eval(&41));
7474
//!
7575
//! // Any function over a reference to the desired `Item` that returns `bool`

src/prelude.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub mod predicate {
1616
pub use constant::{always, never};
1717
pub use function::function;
1818
pub use ord::{eq, ge, gt, le, lt, ne};
19-
pub use iter::{contains, contains_hashable};
19+
pub use iter::{in_hash, in_iter};
2020

2121
/// `str` Predicate factories
2222
///

0 commit comments

Comments
 (0)