View Source Hangman.Dictionary (Hangman Dictionary v0.1.42)

Dictionary for the Hangman Game. Returns a random word.

Based on the course Elixir for Programmers by Dave Thomas.

Summary

Types

A word with letters from a to z

Functions

Returns the longest words in the dictionary agent (longer than floor). Note that word lengths will be enclosed in parentheses after each word.

Returns a random word from the dictionary agent.

Returns all the repeated words in the dictionary agent. Note that repetition counts will be enclosed in parentheses after each word.

Returns the shortest words in the dictionary agent (shorter than ceil).

Returns the number of words in the dictionary agent.

Returns all the words in the dictionary agent of length word_length.

Types

@type word() :: String.t()

A word with letters from a to z

Functions

Link to this function

longest_words(floor \\ 13)

View Source
@spec longest_words(non_neg_integer()) :: [String.t()]

Returns the longest words in the dictionary agent (longer than floor). Note that word lengths will be enclosed in parentheses after each word.

In iex, you may want to run:

IEx.configure(inspect: [limit: :infinity])

Examples

iex> alias Hangman.Dictionary
iex> Dictionary.longest_words() |> Enum.take(9)
[
  "telecommunications (18)",
  "characterization (16)",
  "responsibilities (16)",
  "sublimedirectory (16)",
  "characteristics (15)",
  "confidentiality (15)",
  "congratulations (15)",
  "instrumentation (15)",
  "internationally (15)"
]

iex> alias Hangman.Dictionary
iex> Dictionary.longest_words(14)
[
  "telecommunications (18)",
  "characterization (16)",
  "responsibilities (16)",
  "sublimedirectory (16)",
  "characteristics (15)",
  "confidentiality (15)",
  "congratulations (15)",
  "instrumentation (15)",
  "internationally (15)",
  "pharmaceuticals (15)",
  "recommendations (15)",
  "representations (15)",
  "representatives (15)",
  "troubleshooting (15)"
]
@spec random_word() :: word()

Returns a random word from the dictionary agent.

Examples

iex> alias Hangman.Dictionary
iex> for _ <- 0..99, uniq: true do
iex>   Dictionary.random_word() =~ ~r/^[a-z]+$/
iex> end
[true]

iex> alias Hangman.Dictionary.WordsAgent
iex> words = Agent.get(WordsAgent, & &1)
iex> Enum.all?(words, & &1 =~ ~r/^[a-z]+$/)
true
@spec repeated_words() :: [String.t()]

Returns all the repeated words in the dictionary agent. Note that repetition counts will be enclosed in parentheses after each word.

Examples

iex> alias Hangman.Dictionary
iex> Dictionary.repeated_words()
["echo (3)", "hello (2)"]
Link to this function

shortest_words(ceil \\ 5)

View Source
@spec shortest_words(pos_integer()) :: [word()]

Returns the shortest words in the dictionary agent (shorter than ceil).

In iex, you may want to run:

IEx.configure(inspect: [limit: :infinity])

Examples

iex> alias Hangman.Dictionary
iex> Dictionary.shortest_words() |> Enum.take(49) |> Enum.take(-10)
["act", "add", "ado", "ads", "adz", "aft", "age", "ago", "aid", "ail"]

iex> alias Hangman.Dictionary
iex> Dictionary.shortest_words(2)
["a", "i"]
@spec word_count() :: pos_integer()

Returns the number of words in the dictionary agent.

Examples

iex> alias Hangman.Dictionary
iex> Dictionary.word_count
57708
Link to this function

words_of_length(word_length)

View Source
@spec words_of_length(pos_integer()) :: [word()]

Returns all the words in the dictionary agent of length word_length.

In iex, you may want to run:

IEx.configure(inspect: [limit: :infinity])

Examples

iex> alias Hangman.Dictionary
iex> Dictionary.words_of_length(16)
["characterization", "responsibilities", "sublimedirectory"]

iex> alias Hangman.Dictionary
iex> Dictionary.words_of_length(3) |> Enum.take(10)
["ace", "act", "add", "ado", "ads", "adz", "aft", "age", "ago", "aid"]