@@ -1397,7 +1397,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
1397
1397
}
1398
1398
}
1399
1399
1400
- /// Creates an iterator that visits all elements (key-value pairs) in
1400
+ /// Creates an iterator that visits elements (key-value pairs) in the specified range in
1401
1401
/// ascending key order and uses a closure to determine if an element
1402
1402
/// should be removed.
1403
1403
///
@@ -1423,10 +1423,16 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
1423
1423
/// use std::collections::BTreeMap;
1424
1424
///
1425
1425
/// let mut map: BTreeMap<i32, i32> = (0..8).map(|x| (x, x)).collect();
1426
- /// let evens: BTreeMap<_, _> = map.extract_if(|k, _v| k % 2 == 0).collect();
1426
+ /// let evens: BTreeMap<_, _> = map.extract_if(.., |k, _v| k % 2 == 0).collect();
1427
1427
/// let odds = map;
1428
1428
/// assert_eq!(evens.keys().copied().collect::<Vec<_>>(), [0, 2, 4, 6]);
1429
1429
/// assert_eq!(odds.keys().copied().collect::<Vec<_>>(), [1, 3, 5, 7]);
1430
+ ///
1431
+ /// let mut map: BTreeMap<i32, i32> = (0..8).map(|x| (x, x)).collect();
1432
+ /// let low: BTreeMap<_, _> = map.extract_if(0..4, |_k, _v| true).collect();
1433
+ /// let high = map;
1434
+ /// assert_eq!(low.keys().copied().collect::<Vec<_>>(), [0, 1, 2, 3]);
1435
+ /// assert_eq!(high.keys().copied().collect::<Vec<_>>(), [4, 5, 6, 7]);
1430
1436
/// ```
1431
1437
#[ unstable( feature = "btree_extract_if" , issue = "70530" ) ]
1432
1438
pub fn extract_if < F , R > ( & mut self , range : R , pred : F ) -> ExtractIf < ' _ , K , V , R , F , A >
0 commit comments