Given the following MWE, where:
lst = {<|"a" -> 1, "b" -> 2|>, <|"a" -> 2, "b" -> 2|>, <|"a" -> 3, "b" -> 2|>, <|"a" -> 4, "b" -> 2|>, <|"a" -> 5, "b" -> 2|>}; and the problem is that:
if the value of a is greater than 3 then "c"-> True must be added to the association. I have the following =working= code
Map[If[#[[1]] > 3, var = #; AssociateTo[var, "c" -> True], #] &, lst] which yields:
{<|"a" -> 1, "b" -> 2|>, <|"a" -> 2, "b" -> 2|>, <|"a" -> 3, "b" -> 2|>, <|"a" -> 4, "b" -> 2, "c" -> True|>, <|"a" -> 5, "b" -> 2, "c" -> True|>} I prefer If-less programming and the var=# looks so unnecessary.
Is there a more "elegant" solution to this problem?
Join,Append,Prepend,<|..., key -> val|>. I guess this was your real question. $\endgroup$