I am trying to reduce a list and add some data into a map. The code is something like this:
map = Enum.reduce(1..1000, %{}, fn(x, accumalator) ->(
calculate a hash of a string
if condition is fulfilled do
Map.put(accumalator, string, hash)
end
)end)
This is giving me a bad map error saying that Map.put()
is receiving a nil
value for the put function.
What I want to do is this: For all the iterations calculate the hash and if some condition is fulfilled regarding the hash add the hash and the nonce into the map. So I want the map to be persistent. Where am I going wrong? This answer also suggests the same thing, but is failing.