Given let ra = ResizeArray<int> ():
Seq.forall (fun i ->
let q = i % 2
if 0 = q then ra.Add i
true ) <| seq { 1..10 }
If I do that, ra.Count returns 5.
Seq.forall (fun i ->
let q = i % 2
if 0 = q then ra.Add i
0 = q ) <| seq { 1..10 }
If I do that, ra.Count returns 0.
So, what, unless every iteration of the lambda function evaluates to true, then effectively none of the code in the function is executed, or what??
What’s going on, here?
You use a value of “false” to cease the
Seq.forallfunction from processing further elements.Since
1 % 2 = 0is false, this stops the evaluation on the first iteration.