In general, you should try to use immutable data types and avoid real constructs such as global variables and imperative loops, although using them in F # is great in many cases, they should only be used when there is a good reason for this. Here are some examples where you can use a functional approach:
, , . RefreshCache ( , F # Map):
let PopulateCache quoteList =
quoteList
|> Seq.map (fun result -> result.RicCode, result)
|> Map.ofSeq
:
let cache =
sr.ReadLine()
|> ParseQuoteString
|> PopulateCache
printfn "[F#]Quot Size, %d" m_cache.Count
let quot = m_cache.["MSFT.OQ"]
EstablishConnection sr, null. option, , :
let EstablishConnection() =
let pipeServer =
new NamedPipeServerStream("testpipe", PipeDirection.InOut, 4)
printfn "[F#] NamedPipeServerStream thread created..."
pipeServer.WaitForConnection()
printfn "[F#] Client connected."
try
Some(new StreamReader(pipeServer))
with e ->
printfn "[F#]ERROR: %s" e.Message
None
, , EstablishConnection :
let rec loop() =
match EstablishConnection() with
| Some(conn) ->
printfn "[F#] Ready to Receive data"
loop()
| _ -> ()