Created
July 17, 2020 12:53
-
-
Save benvp/791f574f79190787c9a656a4cbaf4acd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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