F# 将列表管道化到F中的行中#

F# 将列表管道化到F中的行中#,f#,pipeline,forward,F#,Pipeline,Forward,现在我可以向管道中添加single,我的下一个问题是我可以添加列表/数组吗: filesUnderFolder |> Seq.map FileInfo 我的问题是我无法使用管道|>,或者我可以吗 Assembly.GetExecutingAssembly.GetFiles() |>Array.map (fun file -> file.ReadAllText().Contains(keyword)) 我不明白你的问题是关于什么的,但正确的说法是: open System.Reflecti

现在我可以向管道中添加single,我的下一个问题是我可以添加列表/数组吗:

filesUnderFolder
|> Seq.map FileInfo  
我的问题是我无法使用管道|>,或者我可以吗

Assembly.GetExecutingAssembly.GetFiles()
|>Array.map (fun file -> file.ReadAllText().Contains(keyword))

我不明白你的问题是关于什么的,但正确的说法是:

open System.Reflection
open System.IO

Assembly.GetExecutingAssembly().GetFiles() 
|> Seq.map (fun file -> new StreamReader(file)) 
|> Seq.map (fun file -> file.ReadToEnd().Contains(keyword)) 
|> Seq.iter(printfn "%s")
首先,您需要GetExecutionGassembly和它的结果。所以
()
。 第二个
GetFiles()
,返回
流的数组
,而不是您可能期望的
FileInfo
。因此,您必须将
Stream
包装到
StreamWriter


就这样。

我不明白你的问题是关于什么的,但正确的说法是:

open System.Reflection
open System.IO

Assembly.GetExecutingAssembly().GetFiles() 
|> Seq.map (fun file -> new StreamReader(file)) 
|> Seq.map (fun file -> file.ReadToEnd().Contains(keyword)) 
|> Seq.iter(printfn "%s")
首先,您需要GetExecutionGassembly和它的结果。所以
()
。 第二个
GetFiles()
,返回
流的数组
,而不是您可能期望的
FileInfo
。因此,您必须将
Stream
包装到
StreamWriter


就是这样。

看看你的评论,你想这么做吗

Assembly.GetExecutingAssembly().GetFiles() 
|> Seq.map (fun file -> 
    let stream = new StreamReader(file)
    file, stream.ReadToEnd().Contains(keyword))
|> Seq.filter snd
|> Seq.map fst
|> Seq.iter (fun file -> printfn "%s" file.Name)
命令式风格可以更简洁

for file in Assembly.GetExecutingAssembly().GetFiles() do
    let stream = new StreamReader(file)
    if stream.ReadToEnd().Contains(keyword) then
        printfn "%s" file.Name

看看你的评论,你想这么做吗

Assembly.GetExecutingAssembly().GetFiles() 
|> Seq.map (fun file -> 
    let stream = new StreamReader(file)
    file, stream.ReadToEnd().Contains(keyword))
|> Seq.filter snd
|> Seq.map fst
|> Seq.iter (fun file -> printfn "%s" file.Name)
命令式风格可以更简洁

for file in Assembly.GetExecutingAssembly().GetFiles() do
    let stream = new StreamReader(file)
    if stream.ReadToEnd().Contains(keyword) then
        printfn "%s" file.Name

是的,有点。但是,使用您编写的代码,我无法打印第二行的filename/access文件值。有什么想法吗?而且“你的第二个”评论与我上一个问题的主题有关,这个问题被链接了…很抱歉混淆了…streams中没有文件名。所以你无论如何也不能用proint
ReadToEnd()
读取整个流。因此,它将打印整个文件,而不是逐行打印。如果需要打印行,只需使用ReadLine()。如果你需要例子,请告诉我。是的,有点。但是,使用您编写的代码,我无法打印第二行的filename/access文件值。有什么想法吗?而且“你的第二个”评论与我上一个问题的主题有关,这个问题被链接了…很抱歉混淆了…streams中没有文件名。所以你无论如何也不能用proint
ReadToEnd()
读取整个流。因此,它将打印整个文件,而不是逐行打印。如果需要打印行,只需使用ReadLine()。如果您需要示例,请告诉我。