f# - How to project (transform) an array of FileInfo to a list of strings with fsharp -


what trying this:

let getfiles path =  (directoryinfo path).getfiles().tolist 

but gives me list of fileinfos instead of list of strings. how can project list of strings?

thx in advance

assuming want paths associated each file can do:

let getfiles path = (directoryinfo path).getfiles() |> array.map (fun fi -> fi.fullname) |> list.ofseq 

note creates f# list, not system.collections.generic.list<string>. if want create 1 of these can use resizearray:

let getfiles path = (directoryinfo path).getfiles() |> array.map (fun fi -> fi.fullname) |> (fun s -> resizearray<_>(s)) 

edit: comment points out, since getfiles returns array, can use array.map , avoid converting list/resize array if don't need it.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -