|
|
|
@ -282,11 +282,10 @@ extension_trait! {
|
|
|
|
|
```
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let s: VecDeque<usize> = vec![1, 2, 3, 4].into_iter().collect();
|
|
|
|
|
let s = stream::from_iter(vec![1, 2, 3, 4]);
|
|
|
|
|
let mut s = s.take_while(|x| x < &3 );
|
|
|
|
|
|
|
|
|
|
assert_eq!(s.next().await, Some(1));
|
|
|
|
@ -319,9 +318,9 @@ extension_trait! {
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let s: VecDeque<_> = vec![0u8, 1, 2, 3, 4].into_iter().collect();
|
|
|
|
|
let s = stream::from_iter(vec![0u8, 1, 2, 3, 4]);
|
|
|
|
|
let mut stepped = s.step_by(2);
|
|
|
|
|
|
|
|
|
|
assert_eq!(stepped.next().await, Some(0));
|
|
|
|
@ -351,10 +350,10 @@ extension_trait! {
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let first: VecDeque<_> = vec![0u8, 1].into_iter().collect();
|
|
|
|
|
let second: VecDeque<_> = vec![2, 3].into_iter().collect();
|
|
|
|
|
let first = stream::from_iter(vec![0u8, 1]);
|
|
|
|
|
let second = stream::from_iter(vec![2, 3]);
|
|
|
|
|
let mut c = first.chain(second);
|
|
|
|
|
|
|
|
|
|
assert_eq!(c.next().await, Some(0));
|
|
|
|
@ -421,17 +420,15 @@ extension_trait! {
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
|
|
|
|
|
let v: VecDeque<_> = vec![&1, &2, &3].into_iter().collect();
|
|
|
|
|
|
|
|
|
|
let mut v_copied = v.copied();
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
assert_eq!(v_copied.next().await, Some(1));
|
|
|
|
|
assert_eq!(v_copied.next().await, Some(2));
|
|
|
|
|
assert_eq!(v_copied.next().await, Some(3));
|
|
|
|
|
assert_eq!(v_copied.next().await, None);
|
|
|
|
|
let s = stream::from_iter(vec![&1, &2, &3]);
|
|
|
|
|
let mut s_copied = s.copied();
|
|
|
|
|
|
|
|
|
|
assert_eq!(s_copied.next().await, Some(1));
|
|
|
|
|
assert_eq!(s_copied.next().await, Some(2));
|
|
|
|
|
assert_eq!(s_copied.next().await, Some(3));
|
|
|
|
|
assert_eq!(s_copied.next().await, None);
|
|
|
|
|
#
|
|
|
|
|
# }) }
|
|
|
|
|
```
|
|
|
|
@ -457,9 +454,9 @@ extension_trait! {
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let s: VecDeque<_> = vec!['a', 'b', 'c'].into_iter().collect();
|
|
|
|
|
let s = stream::from_iter(vec!['a', 'b', 'c']);
|
|
|
|
|
let mut s = s.enumerate();
|
|
|
|
|
|
|
|
|
|
assert_eq!(s.next().await, Some((0, 'a')));
|
|
|
|
@ -487,9 +484,9 @@ extension_trait! {
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let s: VecDeque<_> = vec![1, 2, 3].into_iter().collect();
|
|
|
|
|
let s = stream::from_iter(vec![1, 2, 3]);
|
|
|
|
|
let mut s = s.map(|x| 2 * x);
|
|
|
|
|
|
|
|
|
|
assert_eq!(s.next().await, Some(2));
|
|
|
|
@ -521,10 +518,11 @@ extension_trait! {
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let s = stream::from_iter(vec![1, 2, 3, 4, 5]);
|
|
|
|
|
|
|
|
|
|
let a: VecDeque<_> = vec![1u8, 2, 3, 4, 5].into_iter().collect();
|
|
|
|
|
let sum = a
|
|
|
|
|
let sum = s
|
|
|
|
|
.inspect(|x| println!("about to filter {}", x))
|
|
|
|
|
.filter(|x| x % 2 == 0)
|
|
|
|
|
.inspect(|x| println!("made it through filter: {}", x))
|
|
|
|
@ -553,11 +551,10 @@ extension_trait! {
|
|
|
|
|
```
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let s: VecDeque<usize> = vec![1, 2, 3].into_iter().collect();
|
|
|
|
|
let s = stream::from_iter(vec![1, 2, 3]);
|
|
|
|
|
|
|
|
|
|
let last = s.last().await;
|
|
|
|
|
assert_eq!(last, Some(3));
|
|
|
|
@ -569,11 +566,10 @@ extension_trait! {
|
|
|
|
|
```
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
use crate::async_std::prelude::*;
|
|
|
|
|
|
|
|
|
|
let s: VecDeque<usize> = vec![].into_iter().collect();
|
|
|
|
|
let s = stream::empty::<()>();
|
|
|
|
|
|
|
|
|
|
let last = s.last().await;
|
|
|
|
|
assert_eq!(last, None);
|
|
|
|
@ -634,11 +630,10 @@ extension_trait! {
|
|
|
|
|
```
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let s: VecDeque<usize> = vec![1, 2, 3, 4].into_iter().collect();
|
|
|
|
|
let s = stream::from_iter(vec![1, 2, 3, 4]);
|
|
|
|
|
let mut s = s.filter(|i| i % 2 == 0);
|
|
|
|
|
|
|
|
|
|
assert_eq!(s.next().await, Some(2));
|
|
|
|
@ -666,14 +661,14 @@ extension_trait! {
|
|
|
|
|
```
|
|
|
|
|
# async_std::task::block_on(async {
|
|
|
|
|
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use async_std::stream::IntoStream;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let inner1: VecDeque<u8> = vec![1,2,3].into_iter().collect();
|
|
|
|
|
let inner2: VecDeque<u8> = vec![4,5,6].into_iter().collect();
|
|
|
|
|
let inner1 = stream::from_iter(vec![1,2,3]);
|
|
|
|
|
let inner2 = stream::from_iter(vec![4,5,6]);
|
|
|
|
|
|
|
|
|
|
let s: VecDeque<_> = vec![inner1, inner2].into_iter().collect();
|
|
|
|
|
let s = stream::from_iter(vec![inner1, inner2]);
|
|
|
|
|
|
|
|
|
|
let v :Vec<_> = s.flat_map(|s| s.into_stream()).collect().await;
|
|
|
|
|
|
|
|
|
@ -703,12 +698,12 @@ extension_trait! {
|
|
|
|
|
```
|
|
|
|
|
# async_std::task::block_on(async {
|
|
|
|
|
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let inner1: VecDeque<u8> = vec![1,2,3].into_iter().collect();
|
|
|
|
|
let inner2: VecDeque<u8> = vec![4,5,6].into_iter().collect();
|
|
|
|
|
let s: VecDeque<_> = vec![inner1, inner2].into_iter().collect();
|
|
|
|
|
let inner1 = stream::from_iter(vec![1u8,2,3]);
|
|
|
|
|
let inner2 = stream::from_iter(vec![4u8,5,6]);
|
|
|
|
|
let s = stream::from_iter(vec![inner1, inner2]);
|
|
|
|
|
|
|
|
|
|
let v: Vec<_> = s.flatten().collect().await;
|
|
|
|
|
|
|
|
|
@ -736,11 +731,11 @@ extension_trait! {
|
|
|
|
|
```
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let s: VecDeque<&str> = vec!["1", "lol", "3", "NaN", "5"].into_iter().collect();
|
|
|
|
|
let s = stream::from_iter(vec!["1", "lol", "3", "NaN", "5"]);
|
|
|
|
|
|
|
|
|
|
let mut parsed = s.filter_map(|a| a.parse::<u32>().ok());
|
|
|
|
|
|
|
|
|
@ -777,16 +772,15 @@ extension_trait! {
|
|
|
|
|
```
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let s: VecDeque<i32> = vec![1, 2, -3].into_iter().collect();
|
|
|
|
|
let s = stream::from_iter(vec![1isize, 2, -3]);
|
|
|
|
|
|
|
|
|
|
let min = s.clone().min_by_key(|x| x.abs()).await;
|
|
|
|
|
assert_eq!(min, Some(1));
|
|
|
|
|
|
|
|
|
|
let min = VecDeque::<isize>::new().min_by_key(|x| x.abs()).await;
|
|
|
|
|
let min = stream::empty::<isize>().min_by_key(|x| x.abs()).await;
|
|
|
|
|
assert_eq!(min, None);
|
|
|
|
|
#
|
|
|
|
|
# }) }
|
|
|
|
@ -814,16 +808,15 @@ extension_trait! {
|
|
|
|
|
```
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let s: VecDeque<i32> = vec![-1, -2, -3].into_iter().collect();
|
|
|
|
|
let s = stream::from_iter(vec![-1isize, -2, -3]);
|
|
|
|
|
|
|
|
|
|
let max = s.clone().max_by_key(|x| x.abs()).await;
|
|
|
|
|
assert_eq!(max, Some(3));
|
|
|
|
|
|
|
|
|
|
let max = VecDeque::<isize>::new().max_by_key(|x| x.abs()).await;
|
|
|
|
|
let max = stream::empty::<isize>().min_by_key(|x| x.abs()).await;
|
|
|
|
|
assert_eq!(max, None);
|
|
|
|
|
#
|
|
|
|
|
# }) }
|
|
|
|
@ -851,11 +844,10 @@ extension_trait! {
|
|
|
|
|
```
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let s: VecDeque<usize> = vec![1, 2, 3].into_iter().collect();
|
|
|
|
|
let s = stream::from_iter(vec![1u8, 2, 3]);
|
|
|
|
|
|
|
|
|
|
let min = s.clone().min_by(|x, y| x.cmp(y)).await;
|
|
|
|
|
assert_eq!(min, Some(1));
|
|
|
|
@ -863,7 +855,7 @@ extension_trait! {
|
|
|
|
|
let min = s.min_by(|x, y| y.cmp(x)).await;
|
|
|
|
|
assert_eq!(min, Some(3));
|
|
|
|
|
|
|
|
|
|
let min = VecDeque::<usize>::new().min_by(|x, y| x.cmp(y)).await;
|
|
|
|
|
let min = stream::empty::<u8>().min_by(|x, y| x.cmp(y)).await;
|
|
|
|
|
assert_eq!(min, None);
|
|
|
|
|
#
|
|
|
|
|
# }) }
|
|
|
|
@ -889,15 +881,15 @@ extension_trait! {
|
|
|
|
|
```ignore
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let s: VecDeque<usize> = vec![1, 2, 3].into_iter().collect();
|
|
|
|
|
let s = stream::from_iter(vec![1usize, 2, 3]);
|
|
|
|
|
|
|
|
|
|
let min = s.clone().min().await;
|
|
|
|
|
assert_eq!(min, Some(1));
|
|
|
|
|
|
|
|
|
|
let min = VecDeque::<usize>::new().min().await;
|
|
|
|
|
let min = stream::empty::<usize>().min().await;
|
|
|
|
|
assert_eq!(min, None);
|
|
|
|
|
#
|
|
|
|
|
# }) }
|
|
|
|
@ -923,11 +915,10 @@ extension_trait! {
|
|
|
|
|
```
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let s: VecDeque<usize> = vec![1, 2, 3].into_iter().collect();
|
|
|
|
|
let s = stream::from_iter(vec![1u8, 2, 3]);
|
|
|
|
|
|
|
|
|
|
let max = s.clone().max_by(|x, y| x.cmp(y)).await;
|
|
|
|
|
assert_eq!(max, Some(3));
|
|
|
|
@ -935,7 +926,7 @@ extension_trait! {
|
|
|
|
|
let max = s.max_by(|x, y| y.cmp(x)).await;
|
|
|
|
|
assert_eq!(max, Some(1));
|
|
|
|
|
|
|
|
|
|
let max = VecDeque::<usize>::new().max_by(|x, y| x.cmp(y)).await;
|
|
|
|
|
let max = stream::empty::<usize>().max_by(|x, y| x.cmp(y)).await;
|
|
|
|
|
assert_eq!(max, None);
|
|
|
|
|
#
|
|
|
|
|
# }) }
|
|
|
|
@ -962,11 +953,10 @@ extension_trait! {
|
|
|
|
|
```
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let mut s: VecDeque<usize> = vec![1, 2, 3].into_iter().collect();
|
|
|
|
|
let mut s = stream::from_iter(vec![1u8, 2, 3]);
|
|
|
|
|
|
|
|
|
|
let second = s.nth(1).await;
|
|
|
|
|
assert_eq!(second, Some(2));
|
|
|
|
@ -978,11 +968,10 @@ extension_trait! {
|
|
|
|
|
```
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
|
|
|
|
|
let mut s: VecDeque<usize> = vec![1, 2, 3].into_iter().collect();
|
|
|
|
|
let mut s = stream::from_iter(vec![1u8, 2, 3]);
|
|
|
|
|
|
|
|
|
|
let second = s.nth(0).await;
|
|
|
|
|
assert_eq!(second, Some(1));
|
|
|
|
@ -996,11 +985,10 @@ extension_trait! {
|
|
|
|
|
```
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let mut s: VecDeque<usize> = vec![1, 2, 3].into_iter().collect();
|
|
|
|
|
let mut s = stream::from_iter(vec![1u8, 2, 3]);
|
|
|
|
|
|
|
|
|
|
let fourth = s.nth(4).await;
|
|
|
|
|
assert_eq!(fourth, None);
|
|
|
|
@ -1091,9 +1079,9 @@ extension_trait! {
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let mut s: VecDeque<usize> = vec![1, 2, 3].into_iter().collect();
|
|
|
|
|
let mut s = stream::from_iter(vec![1u8, 2, 3]);
|
|
|
|
|
let res = s.find(|x| *x == 2).await;
|
|
|
|
|
assert_eq!(res, Some(2));
|
|
|
|
|
#
|
|
|
|
@ -1106,9 +1094,9 @@ extension_trait! {
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let mut s: VecDeque<usize> = vec![1, 2, 3].into_iter().collect();
|
|
|
|
|
let mut s= stream::from_iter(vec![1, 2, 3]);
|
|
|
|
|
let res = s.find(|x| *x == 2).await;
|
|
|
|
|
assert_eq!(res, Some(2));
|
|
|
|
|
|
|
|
|
@ -1136,9 +1124,9 @@ extension_trait! {
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let mut s: VecDeque<&str> = vec!["lol", "NaN", "2", "5"].into_iter().collect();
|
|
|
|
|
let mut s = stream::from_iter(vec!["lol", "NaN", "2", "5"]);
|
|
|
|
|
let first_number = s.find_map(|s| s.parse().ok()).await;
|
|
|
|
|
|
|
|
|
|
assert_eq!(first_number, Some(2));
|
|
|
|
@ -1169,9 +1157,9 @@ extension_trait! {
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let s: VecDeque<usize> = vec![1, 2, 3].into_iter().collect();
|
|
|
|
|
let s = stream::from_iter(vec![1u8, 2, 3]);
|
|
|
|
|
let sum = s.fold(0, |acc, x| acc + x).await;
|
|
|
|
|
|
|
|
|
|
assert_eq!(sum, 6);
|
|
|
|
@ -1200,12 +1188,12 @@ extension_trait! {
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
use std::sync::mpsc::channel;
|
|
|
|
|
|
|
|
|
|
let (tx, rx) = channel();
|
|
|
|
|
|
|
|
|
|
let s: VecDeque<usize> = vec![1, 2, 3].into_iter().collect();
|
|
|
|
|
let s = stream::from_iter(vec![1usize, 2, 3]);
|
|
|
|
|
let sum = s.for_each(move |x| tx.clone().send(x).unwrap()).await;
|
|
|
|
|
|
|
|
|
|
let v: Vec<_> = rx.iter().collect();
|
|
|
|
@ -1306,11 +1294,10 @@ extension_trait! {
|
|
|
|
|
```
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let s: VecDeque<isize> = vec![1, 2, 3].into_iter().collect();
|
|
|
|
|
let s = stream::from_iter(vec![1isize, 2, 3]);
|
|
|
|
|
let mut s = s.scan(1, |state, x| {
|
|
|
|
|
*state = *state * x;
|
|
|
|
|
Some(-*state)
|
|
|
|
@ -1347,11 +1334,10 @@ extension_trait! {
|
|
|
|
|
```
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let a: VecDeque<_> = vec![-1i32, 0, 1].into_iter().collect();
|
|
|
|
|
let a = stream::from_iter(vec![-1i32, 0, 1]);
|
|
|
|
|
let mut s = a.skip_while(|x| x.is_negative());
|
|
|
|
|
|
|
|
|
|
assert_eq!(s.next().await, Some(0));
|
|
|
|
@ -1377,11 +1363,10 @@ extension_trait! {
|
|
|
|
|
```
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let s: VecDeque<usize> = vec![1, 2, 3].into_iter().collect();
|
|
|
|
|
let s = stream::from_iter(vec![1u8, 2, 3]);
|
|
|
|
|
let mut skipped = s.skip(2);
|
|
|
|
|
|
|
|
|
|
assert_eq!(skipped.next().await, Some(3));
|
|
|
|
@ -1443,9 +1428,9 @@ extension_trait! {
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let s: VecDeque<usize> = vec![1, 2, 3].into_iter().collect();
|
|
|
|
|
let s = stream::from_iter(vec![1usize, 2, 3]);
|
|
|
|
|
let sum = s.try_fold(0, |acc, v| {
|
|
|
|
|
if (acc+v) % 2 == 1 {
|
|
|
|
|
Ok(v+3)
|
|
|
|
@ -1479,13 +1464,13 @@ extension_trait! {
|
|
|
|
|
```
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
use std::sync::mpsc::channel;
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let (tx, rx) = channel();
|
|
|
|
|
|
|
|
|
|
let s: VecDeque<usize> = vec![1, 2, 3].into_iter().collect();
|
|
|
|
|
let s = stream::from_iter(vec![1u8, 2, 3]);
|
|
|
|
|
let s = s.try_for_each(|v| {
|
|
|
|
|
if v % 2 == 1 {
|
|
|
|
|
tx.clone().send(v).unwrap();
|
|
|
|
@ -1537,12 +1522,11 @@ extension_trait! {
|
|
|
|
|
```
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let l: VecDeque<isize> = vec![1, 2, 3].into_iter().collect();
|
|
|
|
|
let r: VecDeque<isize> = vec![4, 5, 6, 7].into_iter().collect();
|
|
|
|
|
let l = stream::from_iter(vec![1u8, 2, 3]);
|
|
|
|
|
let r = stream::from_iter(vec![4u8, 5, 6, 7]);
|
|
|
|
|
let mut s = l.zip(r);
|
|
|
|
|
|
|
|
|
|
assert_eq!(s.next().await, Some((1, 4)));
|
|
|
|
@ -1672,14 +1656,14 @@ extension_trait! {
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
use std::cmp::Ordering;
|
|
|
|
|
|
|
|
|
|
let s1 = VecDeque::from(vec![1]);
|
|
|
|
|
let s2 = VecDeque::from(vec![1, 2]);
|
|
|
|
|
let s3 = VecDeque::from(vec![1, 2, 3]);
|
|
|
|
|
let s4 = VecDeque::from(vec![1, 2, 4]);
|
|
|
|
|
let s1 = stream::from_iter(vec![1]);
|
|
|
|
|
let s2 = stream::from_iter(vec![1, 2]);
|
|
|
|
|
let s3 = stream::from_iter(vec![1, 2, 3]);
|
|
|
|
|
let s4 = stream::from_iter(vec![1, 2, 4]);
|
|
|
|
|
assert_eq!(s1.clone().partial_cmp(s1.clone()).await, Some(Ordering::Equal));
|
|
|
|
|
assert_eq!(s1.clone().partial_cmp(s2.clone()).await, Some(Ordering::Less));
|
|
|
|
|
assert_eq!(s2.clone().partial_cmp(s1.clone()).await, Some(Ordering::Greater));
|
|
|
|
@ -1711,9 +1695,9 @@ extension_trait! {
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let s: VecDeque<usize> = vec![1, 2, 3].into_iter().collect();
|
|
|
|
|
let s = stream::from_iter(vec![1usize, 2, 3]);
|
|
|
|
|
let res = s.clone().position(|x| *x == 1).await;
|
|
|
|
|
assert_eq!(res, Some(0));
|
|
|
|
|
|
|
|
|
@ -1750,13 +1734,14 @@ extension_trait! {
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
use std::cmp::Ordering;
|
|
|
|
|
let s1 = VecDeque::from(vec![1]);
|
|
|
|
|
let s2 = VecDeque::from(vec![1, 2]);
|
|
|
|
|
let s3 = VecDeque::from(vec![1, 2, 3]);
|
|
|
|
|
let s4 = VecDeque::from(vec![1, 2, 4]);
|
|
|
|
|
|
|
|
|
|
let s1 = stream::from_iter(vec![1]);
|
|
|
|
|
let s2 = stream::from_iter(vec![1, 2]);
|
|
|
|
|
let s3 = stream::from_iter(vec![1, 2, 3]);
|
|
|
|
|
let s4 = stream::from_iter(vec![1, 2, 4]);
|
|
|
|
|
|
|
|
|
|
assert_eq!(s1.clone().cmp(s1.clone()).await, Ordering::Equal);
|
|
|
|
|
assert_eq!(s1.clone().cmp(s2.clone()).await, Ordering::Less);
|
|
|
|
|
assert_eq!(s2.clone().cmp(s1.clone()).await, Ordering::Greater);
|
|
|
|
@ -1786,11 +1771,13 @@ extension_trait! {
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
let single: VecDeque<isize> = vec![1].into_iter().collect();
|
|
|
|
|
let single_ne: VecDeque<isize> = vec![10].into_iter().collect();
|
|
|
|
|
let multi: VecDeque<isize> = vec![1,2].into_iter().collect();
|
|
|
|
|
let multi_ne: VecDeque<isize> = vec![1,5].into_iter().collect();
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let single = stream::from_iter(vec![1usize]);
|
|
|
|
|
let single_ne = stream::from_iter(vec![10usize]);
|
|
|
|
|
let multi = stream::from_iter(vec![1usize,2]);
|
|
|
|
|
let multi_ne = stream::from_iter(vec![1usize,5]);
|
|
|
|
|
|
|
|
|
|
assert_eq!(single.clone().ne(single.clone()).await, false);
|
|
|
|
|
assert_eq!(single_ne.clone().ne(single.clone()).await, true);
|
|
|
|
|
assert_eq!(multi.clone().ne(single_ne.clone()).await, true);
|
|
|
|
@ -1821,12 +1808,13 @@ extension_trait! {
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let single = stream::from_iter(vec![1]);
|
|
|
|
|
let single_gt = stream::from_iter(vec![10]);
|
|
|
|
|
let multi = stream::from_iter(vec![1,2]);
|
|
|
|
|
let multi_gt = stream::from_iter(vec![1,5]);
|
|
|
|
|
|
|
|
|
|
let single: VecDeque<isize> = vec![1].into_iter().collect();
|
|
|
|
|
let single_gt: VecDeque<isize> = vec![10].into_iter().collect();
|
|
|
|
|
let multi: VecDeque<isize> = vec![1,2].into_iter().collect();
|
|
|
|
|
let multi_gt: VecDeque<isize> = vec![1,5].into_iter().collect();
|
|
|
|
|
assert_eq!(single.clone().ge(single.clone()).await, true);
|
|
|
|
|
assert_eq!(single_gt.clone().ge(single.clone()).await, true);
|
|
|
|
|
assert_eq!(multi.clone().ge(single_gt.clone()).await, false);
|
|
|
|
@ -1857,12 +1845,13 @@ extension_trait! {
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let single = stream::from_iter(vec![1]);
|
|
|
|
|
let single_eq = stream::from_iter(vec![10]);
|
|
|
|
|
let multi = stream::from_iter(vec![1,2]);
|
|
|
|
|
let multi_eq = stream::from_iter(vec![1,5]);
|
|
|
|
|
|
|
|
|
|
let single: VecDeque<isize> = vec![1].into_iter().collect();
|
|
|
|
|
let single_eq: VecDeque<isize> = vec![10].into_iter().collect();
|
|
|
|
|
let multi: VecDeque<isize> = vec![1,2].into_iter().collect();
|
|
|
|
|
let multi_eq: VecDeque<isize> = vec![1,5].into_iter().collect();
|
|
|
|
|
assert_eq!(single.clone().eq(single.clone()).await, true);
|
|
|
|
|
assert_eq!(single_eq.clone().eq(single.clone()).await, false);
|
|
|
|
|
assert_eq!(multi.clone().eq(single_eq.clone()).await, false);
|
|
|
|
@ -1893,12 +1882,13 @@ extension_trait! {
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let single = stream::from_iter(vec![1]);
|
|
|
|
|
let single_gt = stream::from_iter(vec![10]);
|
|
|
|
|
let multi = stream::from_iter(vec![1,2]);
|
|
|
|
|
let multi_gt = stream::from_iter(vec![1,5]);
|
|
|
|
|
|
|
|
|
|
let single = VecDeque::from(vec![1]);
|
|
|
|
|
let single_gt = VecDeque::from(vec![10]);
|
|
|
|
|
let multi = VecDeque::from(vec![1,2]);
|
|
|
|
|
let multi_gt = VecDeque::from(vec![1,5]);
|
|
|
|
|
assert_eq!(single.clone().gt(single.clone()).await, false);
|
|
|
|
|
assert_eq!(single_gt.clone().gt(single.clone()).await, true);
|
|
|
|
|
assert_eq!(multi.clone().gt(single_gt.clone()).await, false);
|
|
|
|
@ -1929,12 +1919,13 @@ extension_trait! {
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let single = stream::from_iter(vec![1]);
|
|
|
|
|
let single_gt = stream::from_iter(vec![10]);
|
|
|
|
|
let multi = stream::from_iter(vec![1,2]);
|
|
|
|
|
let multi_gt = stream::from_iter(vec![1,5]);
|
|
|
|
|
|
|
|
|
|
let single = VecDeque::from(vec![1]);
|
|
|
|
|
let single_gt = VecDeque::from(vec![10]);
|
|
|
|
|
let multi = VecDeque::from(vec![1,2]);
|
|
|
|
|
let multi_gt = VecDeque::from(vec![1,5]);
|
|
|
|
|
assert_eq!(single.clone().le(single.clone()).await, true);
|
|
|
|
|
assert_eq!(single.clone().le(single_gt.clone()).await, true);
|
|
|
|
|
assert_eq!(multi.clone().le(single_gt.clone()).await, true);
|
|
|
|
@ -1965,12 +1956,12 @@ extension_trait! {
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let single = VecDeque::from(vec![1]);
|
|
|
|
|
let single_gt = VecDeque::from(vec![10]);
|
|
|
|
|
let multi = VecDeque::from(vec![1,2]);
|
|
|
|
|
let multi_gt = VecDeque::from(vec![1,5]);
|
|
|
|
|
let single = stream::from_iter(vec![1]);
|
|
|
|
|
let single_gt = stream::from_iter(vec![10]);
|
|
|
|
|
let multi = stream::from_iter(vec![1,2]);
|
|
|
|
|
let multi_gt = stream::from_iter(vec![1,5]);
|
|
|
|
|
|
|
|
|
|
assert_eq!(single.clone().lt(single.clone()).await, false);
|
|
|
|
|
assert_eq!(single.clone().lt(single_gt.clone()).await, true);
|
|
|
|
@ -2012,10 +2003,10 @@ extension_trait! {
|
|
|
|
|
```
|
|
|
|
|
# fn main() { async_std::task::block_on(async {
|
|
|
|
|
#
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
use async_std::prelude::*;
|
|
|
|
|
use async_std::stream;
|
|
|
|
|
|
|
|
|
|
let s: VecDeque<_> = vec![0u8, 1, 2, 3, 4].into_iter().collect();
|
|
|
|
|
let s = stream::from_iter(vec![0u8, 1, 2, 3, 4]);
|
|
|
|
|
let sum: u8 = s.sum().await;
|
|
|
|
|
|
|
|
|
|
assert_eq!(sum, 10);
|
|
|
|
|