Skip to content

Commit 7645d98

Browse files
committed
filter
1 parent c4a1ee6 commit 7645d98

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/v1/value/value_utils.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl Value {
6262

6363
/// Remove all tokens whose quantity is zero.
6464
pub fn normalize(&self) -> Self {
65-
self.filter_map_amount(|_, _, a| a.is_zero().not().then(|| a.clone()))
65+
self.filter(|_, _, a| a.is_zero().not())
6666
}
6767

6868
/// Apply a function to each token of the value, and use its result as the new amount.
@@ -73,6 +73,14 @@ impl Value {
7373
self.filter_map_amount(|cs, tn, a| Some(f(cs, tn, a)))
7474
}
7575

76+
/// Apply a predicate to tokens.
77+
pub fn filter<F>(&self, mut f: F) -> Self
78+
where
79+
F: FnMut(&CurrencySymbol, &TokenName, &BigInt) -> bool,
80+
{
81+
self.filter_map_amount(|cs, tn, a| f(cs, tn, a).then(|| a.clone()))
82+
}
83+
7684
/// Apply a function to each token of the value. If the result is None, the token entry will be
7785
/// removed.
7886
///

0 commit comments

Comments
 (0)