elixir - How to add computed values to a map inside a pipe? -


i have situation. collect files ftp servers. example sample file
41199999
32355830
00003800
484e0040
48096e40
479e9b80
471b3f00
470a2100
431f0000
30305332
00003000
00003432 ...

each line in each file converted using conversion formula each line converted key in map. have %{"ax"=>value} being x number of line , value converted value.

apart need more keys,calculated keys, based on keys read each file in code

i map this

%{"a1"=>1,"a2"=>2, etc} 

at line enum.at(0) in next code

|>enum.map(&tools.processfile(pid,&1,conversion)) |>enum.at(0) 

then problem how add calculated keys map. have example f1 function takes map , calculates f1 key

def f1 map     %{"f1": map["a1"]+2} end 

how add f1 key map in pipe code above

%{"a1"=>1,"a2"=>2, "f1"=>3}

regards

if understand right, should define f1 function such append value existing map, rather returning new value. can use map.put/3 this:

def f1(map)   new_value = map["a1"] + 2   map.put(map, "f1", new_value) end 

then can add end of pipeline:

# ... |> enum.map(&tools.processfile(pid,&1,conversion)) |> enum.at(0) |> f1 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -