Passing F# function to IEnumerable.Where vs IEnumerable.All

前端 未结 1 830
予麋鹿
予麋鹿 2020-12-20 15:06

Given the following:

open System.Linq

let even n = n % 2 = 0

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

this is a valid expression:

seqA         


        
相关标签:
1条回答
  • 2020-12-20 15:23

    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
    
    0 讨论(0)
提交回复
热议问题