Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# array flatmap

Tags:

arrays

f#

I have the following function:

let fetchTickerGroup (tickers: string[])  (sqlServer:SQLServerClient) (schema: string) = 
tickers |> Array.map(fun x -> sqlServer.FetchTimeSerie(schema,x))

The function takes an array of strings and, through sqlServer fetches data which is returned by sqlServer.FetchTimeSerie as a List<b> where b is a custom defined object. Now, mapping the array means that the function fetchTickerGroup returns List<b>[].

I was wondering if it would be possible to flatMap the result, rather than just mapping the array values.

like image 699
NoIdeaHowToFixThis Avatar asked Nov 04 '13 10:11

NoIdeaHowToFixThis


1 Answers

I have no Idea what Flatmap is but I think you want to use *.collect.

I think the best solution would be something like

tickers |> Array.toList |> List.collect (fun x -> sqlServer.FetchTimeSerie(schema,x))

you need to convert so that you have only list or array types

like image 58
John Palmer Avatar answered Sep 22 '22 16:09

John Palmer