开发者

Erlang BIF's to delete tuples in list

开发者 https://www.devze.com 2023-01-20 09:04 出处:网络
How can I delete a tuple with key from a list? Ex: T开发者_运维问答upleList = [ {apple, {0,0,0}}, {orange, {0,0,0}}, {bannana, {0,0,0}}]

How can I delete a tuple with key from a list?

Ex:

T开发者_运维问答upleList = [ {apple, {0,0,0}}, {orange, {0,0,0}}, {bannana, {0,0,0}}]

Then I need to delete the tuple whos key matches orange.

So I should get back

[ {apple, {0,0,0}},  {bannana, {0,0,0}}]

Im looking for a BIF instead of a function as I am using right now.

Thanks and Regards


There is not BIF for this. There is lists:keydelete/3 which is not BIF in contrast of lists:member/2, lists:reverse/2, lists:keymember/3, lists:keysearch/3 and lists:keyfind/3 which are BIFs. Anyway lists:keydelete/3 performs better than proplists:delete/2 because proplists are little bit more tricky. If you would be interested in performance, your own crafted local function or probably nif would be better solution as well as list comprehension (which should perform same as local function).


proplists:delete(orange, TupleList).


solution accomplished:

[NewHold] = [{N, X} || {N, X} <- Hold, N =/= Who],
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号