我在F#中有一个bool [,],我想获取true的存在计数。在不进行命令式编程的情况下该如何做?
这是我当前的解决方案,实际上只是用f#编写的c#。
let mutable x = 0
for cell in cells do
if cell = true then x <- x + 1
x
这是一种方法:
let x = cells |> Seq.cast |> Seq.filter id |> Seq.length
它的作用是过滤出false
值(请参阅Seq.filter),然后仅计算剩余的内容。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句