Instantly share code, notes, and snippets.

Embed
What would you like to do?
Filter words with specified characters in a file
# Filter words with specified characters in a file
# Usage : `filter_in_file("thai.txt", "ทงกานเ")`
def filter_in_file(filename, chars) do
File.read!(filename)
|> filter(chars)
end
def filter(words, chars) do
words
|> String.split(~r{[ \n]}, trim: true)
|> Enum.filter(fn(word) ->
Enum.all?(String.codepoints(word), fn(c) ->
String.contains?(chars, c)
end)
end)
|> Enum.join(" ")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment