Deduct "New List" with "new Value" only for some "specific Tag", from Old List, using "List Comprehension".
Oliver Korpilla
Oliver.Korpilla@REDACTED
Sun Jul 19 09:31:44 CEST 2020
TV = [{a,1}, {off,1234}, {d,4}, {e,5}, {off,5678}],
Change = fun ({off, _}) -> {off, 255};
(Any) -> Any
end,
NewTV = lists:map(Change, TV).
Gesendet: Sonntag, 19. Juli 2020 um 08:55 Uhr
Von: "Papa Tana" <papa.tana101@REDACTED>
An: "erlang-questions" <erlang-questions@REDACTED>
Betreff: Deduct "New List" with "new Value" only for some "specific Tag", from Old List, using "List Comprehension".
Hi All,
I have a list "TV" Containing some {Tag, Value} as below:
TV = [{a,1}, {off,1234}, {d,4}, {e,5}, {off,5678}].
I would like to replace all tag name "off" in this list, to a new value = 255.
Wanted result:
[{a,1}, {off,255}, {d,4}, {e,5}, {off,255}].
I can only get the below, I don't know how to change them:
[ {Tag1, Value1} || {Tag1, Value1} <- TV, Tag1/=off].
[ {Tag1, Value1} || {Tag1, Value1} <- TV, Tag1==off].
Any advice please?
Thanks,
Best Regards,
More information about the erlang-questions
mailing list