Check if value matches a field in a list of objects

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)?

Yes, You just named it… Enum.any? :slight_smile:

1 Like

Let me see if I got this right, if I want to check if ANY organization.employees == 5, does it look like this?

  fn organization -> organization.employees == 5 end)

Sorry if this seems like an easy question, it’s been a long day :rofl:

Yes like this… You can also use the shortcut.

Enum.any?(list, & &1.employees == 5)