I have the following function in Haskell:
memdb = -- load the contents of a database into memory as a Map
And then I have the following line:
map (\x -> memdb ! x) values
I would like memdb to generate the Map only once, instead of on every iteration of map
. I could do it using something like this:
make_memdb = -- equivalent to memdb in previous example
memdb <- make_memdb
map (\x -> memdb ! x) values
But this would mean that I would have to pass memdb
in to every function that uses it. Is there any way I can:
a. avoid recalculating memdb
each time it is called OR
b. save the value produced in make_memdb
as a constant so I can avoid passing it in to every function that uses it?