SelectMany
SelectMany transforms each emissions from a
Schedule based on a provided bind function that returns a new
Schedule that then emits all its Duration
Warning
If the bind function returns an infinite Schedule for any
emission from the original Schedule no further emissions from
the original Schedule will occur
Schedule selectMany = Schedule
.Linear(TimeSpan.FromSeconds(1))
.Take(2)
.SelectMany(
bind: _ => Schedule.From(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(1)),
projection: (first, second) => first + second
);
| Duration |
|---|
| 3 seconds |
| 2 seconds |
| 4 seconds |
| 3 seconds |
Using LINQ expressions,
Schedule selectMany =
from linear in Schedule.Linear(TimeSpan.FromSeconds(1)).Take(2)
from twoThenOne in Schedule.From(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(1))
select linear + twoThenOne;
| Duration |
|---|
| 3 seconds |
| 2 seconds |
| 4 seconds |
| 3 seconds |
Ignoring the results from the first Schedule,
Schedule selectMany = Schedule
.Linear(TimeSpan.FromSeconds(1))
.SelectMany(_ => Schedule.From(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(1)));
| Duration |
|---|
| 2 seconds |
| 1 second |
| 2 seconds |
| 1 second |
| 2 seconds |