mirror of
https://github.com/nushell/nushell.git
synced 2025-06-01 23:55:50 +02:00
Simplify retain
and retain_mut
This commit is contained in:
parent
0efeaee6b1
commit
c403581c0f
@ -139,7 +139,7 @@ impl Record {
|
|||||||
where
|
where
|
||||||
F: FnMut(&str, &Value) -> bool,
|
F: FnMut(&str, &Value) -> bool,
|
||||||
{
|
{
|
||||||
self.inner.retain(|(k, v)| keep(k, v))
|
self.retain_mut(|k, v| keep(k, v));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove elements in-place that do not satisfy `keep` while allowing mutation of the value.
|
/// Remove elements in-place that do not satisfy `keep` while allowing mutation of the value.
|
||||||
@ -183,10 +183,7 @@ impl Record {
|
|||||||
where
|
where
|
||||||
F: FnMut(&str, &mut Value) -> bool,
|
F: FnMut(&str, &mut Value) -> bool,
|
||||||
{
|
{
|
||||||
self.inner = std::mem::take(&mut self.inner)
|
self.inner.retain(|(k, v)| keep(k, v));
|
||||||
.into_iter()
|
|
||||||
.filter_map(|(col, mut val)| keep(&col, &mut val).then_some((col, val)))
|
|
||||||
.collect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Truncate record to the first `len` elements.
|
/// Truncate record to the first `len` elements.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user