I’m trying to figure out how to use Elixir’s version of for comprehensions.
The Phoenix live view generator creates this code in the live/page_live.ex file to get the search results:
for {app, desc, vsn} <- Application.started_applications(),
app = to_string(app),
String.starts_with?(app, query) and not List.starts_with?(desc, ~c"ERTS"),
into: %{},
do: {app, vsn}
How could I go about making this return at most 5 results? I tried using Enum.with_index on the first line and adding an index < 5 filter, but that just limited the search space to the first 5 dependencies.