现在我可以向管道添加单个值或 tubles,我的下一个问题是我可以添加一个列表/数组:
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")
首先你需要 GetExecutingAssembly 并且你需要它的结果。所以()
。其次GetFiles()
,返回数组Stream
,而不是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