Skip to content

Instantly share code, notes, and snippets.

@ephe-meral
Created August 16, 2016 16:14
Show Gist options
  • Save ephe-meral/2ab27186028ff701014b7e6dca5bf764 to your computer and use it in GitHub Desktop.
Save ephe-meral/2ab27186028ff701014b7e6dca5bf764 to your computer and use it in GitHub Desktop.
def find_many(list, funs), do: do_find_many(list, funs |> Enum.map(&({&1, nil})))
defp do_find_many([h | t], funs, acc) do
new_funs = funs |> Enum.map(
fn {fun, nil} -> if fun.(h), do: {fun, h}, else: {fun, nil}
other -> other
end)
if Enum.any?(new_funs, fn {_, x} -> is_nil(x) end), do: t, else: []
|> do_find_many(new_funs)
end
defp do_find_many([], funs) do
new_funs |> Enum.unzip |> elem(1)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment