Created
November 29, 2016 17:37
-
-
Save narze/942ddbeaada619c7e3a91f1af7a741ca to your computer and use it in GitHub Desktop.
Filter words with specified characters in a file
This file contains 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
# 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