Perhaps
map = conditionally_add_value(%{field1: "value1"}, color == :green, :field2, "value2")
Whereas conditionally_add_value/3 could be implemented as:
def conditionally_add_value(map, cond, _key, _value) when cond in [nil, false], do: map
def conditionally_add_value(map, _cond, key, value), do: Map.put(map, key, value)
edit
If calculating the value of the key or value though is computationally expensive, I’d use an if instead as @OvermindDL1 suggested. My version will always calculate those values, whether they are needed or not. Besides of using if one could also avoid that by using a macro, but that one I’m not able to write free hand right now, still undercoffeeinated 




















