gpt4 book ai didi

f# - Array.select 元组的元素

转载 作者:行者123 更新时间:2023-12-01 06:17:24 25 4
gpt4 key购买 nike

这是我当前的代码:

placeId
|> Sql.getEOByPlace
|> Array.map (fun eo -> (eo, getType eo)) // (Item * ItemType option)
|> Array.filter (fun (i, it) -> it.IsSome)
|> Array.map (fun (i, it) -> (i, it.Value) // (Item * ItemType)

有什么办法可以简化最后三行代码吗?我需要类似于 Array.choose 的东西,但是对于元组的一个元素。

最佳答案

您可以返回(a * b)选项而不是a * b选项并使用Array.choose:

placeId
|> Sql.getEOByPlace
|> Array.choose (fun eo -> (getType eo) |> Option.map (t -> (eo, t)))

关于f# - Array.select 元组的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49108284/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com