我有一个类型的元组的序列(x: int, y:bool)
,我想找到最小x
谁拥有的项目y=isMin
中valList
,如果isMin
是真实的。
let valList = seq{ for i =0 to 8 do yield (GetVal (i,not isMin),not isMin) }
let onlyMinType (x: int, y:bool) = if y==isMin then x
let maxVal = valList |> Seq.collect(onlyMinType) |> if isMin then Seq.min else Seq.max
maxVal
我不知道该怎么办Seq.collect(onlyMinType)
并起作用onlyMinType
您可以通过Seq.minBy
几种不同的方式使用:
[(1, false); (2, true); (0, true); (-1, false)]
|> Seq.filter snd
|> Seq.minBy fst
|> fst
或者
[(1, false); (2, true); (0, true); (-1, false)]
|> Seq.minBy (fun (n, b) -> if b then n else Int32.MaxValue)
|> fst
会很好地工作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句