9
votes

Given the following:

open System.Linq

let even n = n % 2 = 0

let seqA = seq { 0..2..10 }

this is a valid expression:

seqA.Where(even)

but this is not:

seqA.All(even)

Why is passing even to Where allowed but not to All?

1
My guess is you've discovered a bug. I would send this to [email protected]. - Daniel
This seems to be another case of this. As a workaround, seqA.All(System.Func<_,_>(even)) should work, or seqA.All(fun x -> even x). - Christoph Rüegg
FYI, I've just opened an idea on uservoice for this. - Christoph Rüegg
@Daniel fsbugs requested that I open an issue on their codeplex site. Here it is. - dharmatech
even |> seqA.All does work (on mono). Just to make things more interesting. - albertjan

1 Answers

1
votes

While there may be a bug there, I think the better approach would be to use the Seq higher order functions when dealing with IEnumerable<T> in F# rather than Linq

let even n = n % 2 = 0
let seqA = seq { 0..2..10 }

seqA |> Seq.filter even
//val it : seq<int> = seq [0; 2; 4; 6; ...]

seqA |> Seq.forall even
//val it : bool = true