gpt4 book ai didi

f# - 需要返回 seq 而不是 seq> 吗?

转载 作者:行者123 更新时间:2023-12-03 04:44:21 26 4
gpt4 key购买 nike

以下函数files返回seq<seq<R>> 。如何让它返回seq<R>相反?

type R = { .... }
let files = seqOfStrs |> Seq.choose(fun s ->
match s with
| Helper.ParseRegex "(\w+) xxxxx" month ->
let currentMonth = .....
if currentMonth = month.[0] then
doc.LoadHtml(s)
Some (
doc.DucumentNode.SelectNodes("....")
|> Seq.map(fun tr ->
{ ..... } ) //R. Some code return record type R. Omitted
)
else
printfn "Expect %s found %s." currentMonth month.[0]
None
| _ ->
printfn "No '(Month) Payment Data On Line' prompt."
None

最佳答案

您的代码片段不完整,因此我们无法为您提供完整的答案。但是:

  • 您的代码正在使用 Seq.choose,并且您将返回 NoneSome 以及值集合。然后你会得到一系列序列...

  • 您可以使用 Seq.collect 来展平序列,并将 None 替换为空序列,将 Some 替换为序列.

沿着这些思路(未经测试):

let files = seqOfStrs |> Seq.collect (fun s ->
match s with
| Helper.ParseRegex "(\w+) xxxxx" month ->
let currentMonth = .....
if currentMonth = month.[0] then
doc.LoadHtml(s)
doc.DucumentNode.SelectNodes("....")
|> Seq.map(fun tr ->
{ ..... } ) //R. Some code return record type R. Omitted
else
printfn "Expect %s found %s." currentMonth month.[0]
Seq.empty
| _ ->
printfn "No '(Month) Payment Data On Line' prompt."
Seq.empty )

其他选项,例如将 Seq.concatSeq.collect id 添加到管道末尾显然也可以工作。

关于f# - 需要返回 seq<R> 而不是 seq<seq<R>> 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29884792/

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