Search code examples
f#pipelineforward

Piping a list into the line in F#


Now I can add single value or tubles to the pipeline, my next question is can I add a list/array:

filesUnderFolder
|> Seq.map FileInfo  

my problem is I can't process this with pipeline |>, or can I?

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


Solution

  • Looking at your comment are you trying to do this?

    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)
    

    Imperative style can be cleaner.

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