如何解决F#如何在管道前进序列中打印出序列?
let rec crawlPage (page : String,nestingLevel : int) : seq<string> =
System.Threading.Thread.Sleep 1200
//printfn "URL: %s" page
//printfn "nesting Level: %i \n" nestingLevel
HtmlDocument.Load(page)
|> fun m -> m.CssSelect("a")
|> List.map(fun a -> a.AttributeValue("href"))
|> Seq.distinctBy id
|> Seq.filter (fun x -> x.Contains baseUrl1)
//|> Seq.map (printfn "%A") // I would like to be able to do something like this.
|> Seq.map (fun x -> https + x)
|> Seq.map (fun x ->
match nestingLevel with
| _ when (nestingLevel > 0) -> crawlPage(x,(nestingLevel - 1))
| _ -> Seq.singleton x)
|> Seq.concat
|> Seq.distinctBy id
我能够通过编写如下帮助程序来解决此问题:
let strPrint (str : string) : string =
printfn "%s" str
str
如果可能的话,我宁愿只使用管道转发。
解决方法
当然,您可以使用匿名函数内联进行完全相同的操作:
...
|> Seq.map (fun str ->
printfn "%s" str
str)
|>
...
通常,如果您有let f x = e
,则始终可以用其匿名等效项f
替换任何出现的(fun x -> e)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。