How global scaling is done in F #

I need to create a collection in F # that has a pair of key values ​​and is global in volume.

+5
source share
2 answers

You can do it:

[<AutoOpen>]
module Globals =
  let map = System.Collections.Generic.Dictionary<_,_>()

Then use it unskilled throughout the program:

map.Add(1, "a")
map.Add(2, "b")
map |> Seq.iter (fun (KeyValue(k, v)) -> printfn "Key: %d, Value: %s" k v)
+7
source

depending on which project you are doing in the best way, maybe just declare it in a module:

module GlobalVals =

    let myCollection = .... // whatever

you can just use it with

GlobalVals.myCollection...
+4
source

All Articles