Hello all, I have a list of objects taken from the database (organizations), is there an efficient way to check if ANY of the objects in the list have a specific value to a field (employees == 5)?
Let me see if I got this right, if I want to check if ANY organization.employees == 5, does it look like this?
Enum.any?(organizations_list,
fn organization -> organization.employees == 5 end)
Sorry if this seems like an easy question, it’s been a long day
Yes like this… You can also use the shortcut.
Enum.any?(list, & &1.employees == 5)
2 Likes