views:

87

answers:

2

Hi, 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))

+3  A: 

I do not understand what is your question about, but correct version is:

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")

First you need GetExecutingAssembly and you need its result. So (). Second GetFiles(), return array of Stream, not FileInfo as you may expect. Because of this you have to wrap Stream to StreamWriter.

Thats it.

Mike Chaliy
Yes, kind of.However with the code you have written, i can't print the filename/access file value of the second line. Any idea?
demokritos
and "your Second" comment is related to the topic of my previous question which was linked...sorry for confusion...
demokritos
There is no file names in streams. So you cannot proint it anyway. `ReadToEnd()` reads whole stream. So it will print whole file not line by line. If you need print lines just use ReadLine(). Let me know if you need example.
Mike Chaliy
+2  A: 

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
gradbot