1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use crateFixedPointCoro;
use cratefrom_control_flow;
use cratewith_state;
/// Creates a coroutine that yields its inputs while they satisfy the predicate,
/// and returns the first input that doesn't.
///
/// This can be useful as the argument of the `.compose()` operator to implement
/// a "do-until" algorithm, or used with `weave()` to filter a stream of values
/// yielded by another `Coro`.
///
/// # Example 1: truncate a coroutine
///
/// ```rust
/// use cocoro::Coro;
/// use cocoro::IntoCoro;
/// use cocoro::continue_while;
///
/// (1..)
/// .into_coro()
/// .compose(continue_while(|&n| n < 5).map_return(|_| ()))
/// .assert_yields(1, ())
/// .assert_yields(2, ())
/// .assert_yields(3, ())
/// .assert_yields(4, ())
/// .assert_returns((), ());
/// ```
///
/// # Example 2: take elements matching a pattern
///
/// ```rust
/// use cocoro::Coro;
/// use cocoro::IntoCoro;
/// use cocoro::continue_while;
///
/// // Extract consecutive alphabetic tokens
/// ["hello", "world", "123", "foo", "bar"]
/// .into_coro()
/// .compose(
/// continue_while(|s: &&str| s.chars().all(|c| c.is_alphabetic()))
/// .map_return(|_| ()),
/// )
/// .assert_yields("hello", ())
/// .assert_yields("world", ())
/// .assert_returns((), ());
/// ```