[erlang-questions] Help on dictionary search

Christian S <>
Fri Nov 10 00:48:11 CET 2006


> remove_pid(Classes, Pid) ->
>  Classes1 = [{Class, sets:del_element(Pid, Set)} || {Class, Set} <- Classes],
>  Classes2 = [{Class, Set} || {Class, Set} <- Classes1, sets:size(Set) =/= 0].
>
> [also untested]

I just learned more about the '--' operator's semantics:

C = [{a, [1,2,3]}, {b, [4,5,6]}, {c, [1]}].

Pid = 1.

[{Class, Set--[Pid]} || {Class, Set} <- C, [] =/= Set--[Pid]].

gives [{a, [2,3]}, {b, [4,5,6]}]


It isnt pretty, but it is silly! :)



More information about the erlang-questions mailing list