File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -2279,6 +2279,25 @@ pub trait ParallelIterator: Sized + Send {
2279
2279
/// assert!(result.len() <= 50);
2280
2280
/// assert!(result.windows(2).all(|w| w[0] < w[1]));
2281
2281
/// ```
2282
+ ///
2283
+ /// ```
2284
+ /// use rayon::prelude::*;
2285
+ /// use std::sync::atomic::AtomicUsize;
2286
+ /// use std::sync::atomic::Ordering::Relaxed;
2287
+ ///
2288
+ /// // Collect any group of items that sum <= 1000
2289
+ /// let quota = AtomicUsize::new(1000);
2290
+ /// let result: Vec<_> = (0_usize..100)
2291
+ /// .into_par_iter()
2292
+ /// .take_any_while(|&x| {
2293
+ /// quota.fetch_update(Relaxed, Relaxed, |q| q.checked_sub(x))
2294
+ /// .is_ok()
2295
+ /// })
2296
+ /// .collect();
2297
+ ///
2298
+ /// let sum = result.iter().sum::<usize>();
2299
+ /// assert!(matches!(sum, 902..=1000));
2300
+ /// ```
2282
2301
fn take_any_while < P > ( self , predicate : P ) -> TakeAnyWhile < Self , P >
2283
2302
where
2284
2303
P : Fn ( & Self :: Item ) -> bool + Sync + Send ,
You can’t perform that action at this time.
0 commit comments