Skip to content

Instantly share code, notes, and snippets.

@narze
Created November 29, 2016 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save narze/942ddbeaada619c7e3a91f1af7a741ca to your computer and use it in GitHub Desktop.
Save narze/942ddbeaada619c7e3a91f1af7a741ca to your computer and use it in GitHub Desktop.
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