script
April 19, 2018, 4:47am
1
I have a list which contain multiple key value pairs like this;
[
id: :id,
description: :string,
inserted_by: :integer,
updated_by: :integer,
inserted_at: :utc_datetime,
updated_at: :utc_datetime,
type_id: :id
deleted_by: :integer,
]
How can i delete the specific tuple from the list like type_id
and inserted_by
.
for now Enum.reject
is working for single tuple:
Enum.reject(list, fn(k) -> k == {:type_id, :id} end)
Thanks
Nicd
April 19, 2018, 5:41am
2
That is a keyword list. You may want to check the Keyword
module functions delete/2
, delete/3
, delete_first/2
, and drop/2
. I think Keyword.drop/2
is closest to your description.
Here are the docs: https://hexdocs.pm/elixir/Keyword.html
4 Likes
script:
deleted_by: :integer,
]
Try this:
list = [
id: :id,
description: :string,
inserted_by: :integer,
updated_by: :integer,
inserted_at: :utc_datetime,
updated_at: :utc_datetime,
type_id: :id,
deleted_by: :integer,
]
Keyword.delete(list, :type_id)
2 Likes