You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just stumbled upon some code and I was wondering whether this could be something for styler to rewrite 🤔
movies|>Enum.filter(&is_cool/1)|>List.first()
to:
Enum.find(movies,&is_cool/1)
When using Enum.filter/2 followed by List.first/1all items within the list are processed independently of whether the first would already be enough as it matched is_cool?/1. Replacing it with Enum.find/2 would stop the processing the items with the first match.
Even when List.first/3 is used, replacing it with Enum.find/3 would work.
movies|>Enum.filter(&is_cool/1)# or Enum.reject/2|>List.first(:not_found)