Skip to content

Instantly share code, notes, and snippets.

@benvp
Created July 17, 2020 12:53
Show Gist options
  • Save benvp/791f574f79190787c9a656a4cbaf4acd to your computer and use it in GitHub Desktop.
Save benvp/791f574f79190787c9a656a4cbaf4acd to your computer and use it in GitHub Desktop.
def handle_event("suggest", %{"search" => search}, socket) do
suggestions = Items.list_items() |> suggest(search)
{:noreply, assign(socket, suggestions: suggestions)}
end
defp suggest(items, search) do
Enum.filter(items, fn i ->
i.name
|> String.downcase()
|> String.contains?(String.downcase(search))
end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment