Difference between the behaviours of FoldWhile and FoldWhileIO
#1527
-
|
Hi. Maybe I'm fundamentally misunderstanding how var sum1 = Source
.forever(1)
.FoldWhile(
(s, x) => s + x,
(s, _) => s <= 10,
0
)
.Take(1)
.Last()
.Run();
Console.WriteLine(sum1);
var sum2 = SourceT
.forever<IO, int>(1)
.FoldWhileIO(
0,
(s, x) => s + x,
x => x.State <= 10
)
.As()
.Take(1)
.Last()
.Run();
Console.WriteLine(sum2);When I run this example, it prints out the value of Is this an expected behaviour? If so, how can I use an infinite stream of |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 16 replies
-
|
Maybe it's not var sum = SourceT
.forever<IO, int>(1)
.FoldWhile((s, x) => s + x, (s, x) => s >= 10, 0)
.Take(1)
.Last()
.Run();
Console.WriteLine(sum); |
Beta Was this translation helpful? Give feedback.
-
|
I just stumbled across this closed PR which seems to be relevant to the problem. I'll subscribe to the linked issue, assuming it's the root cause of the symptom I see. |
Beta Was this translation helpful? Give feedback.
-
|
@mysticfall This should be resolved in v5.0.0-beta-69. The usual caveats apply in that Oh, and btw, use |
Beta Was this translation helpful? Give feedback.
I've made some improvements in
v5.0.0-beta-75:Delaycombinator that allows delaying the yielding of the items in aSourceTIn your original example you never needed to fold at all, but if you wanted to merge two streams and take the first item yielded, then this will work: