We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
It could be called something like Trie.from_enumerable. Its definition is simple:
Trie.from_enumerable
def Trie.from_enumerable(enumerable) enumerable.reduce(Trie.new) do |trie, item| trie.add(item); trie end end
I would use this in my program to easily build a Trie from a text file:
Trie
words_trie = File.open(WORDLIST_FILE_PATH, 'r') do |wordlist_file| Trie.from_enumerable(wordlist_file.each_line) end
If you want, you could also provide a version that adds both keys and values:
def Trie.from_key_value_enumerable(kv_enumerable) trie = Trie.new kv_enumerable.each do |key, value| trie.add(key, value) end trie end
The text was updated successfully, but these errors were encountered:
Love it. Patches accepted. :D
Sorry, something went wrong.
No branches or pull requests
It could be called something like
Trie.from_enumerable
. Its definition is simple:I would use this in my program to easily build a
Trie
from a text file:If you want, you could also provide a version that adds both keys and values:
The text was updated successfully, but these errors were encountered: