iex(19)> Isogram.isogram?("DEMONSTRABLY")
** (FunctionClauseError) no function clause matching in IO.inspect/3
The following arguments were given to IO.inspect/3:
# 1
:stdio
# 2
["D"]
# 3
"D"
Attempted function clauses (showing 1 out of 1):
def inspect(device, item, opts) when is_list(opts)
(elixir) lib/io.ex:399: IO.inspect/3
(elixir) lib/enum.ex:1948: Enum."-reduce/3-lists^foldl/2-0-"/3
When I do that, I get this. What does the error mean?
"D"
** (FunctionClauseError) no function clause matching in :lists.do_flatten/2
The following arguments were given to :lists.do_flatten/2:
# 1
"D"
# 2
[]
defmodule Isogram do
@doc """
Determines if a word or sentence is an isogram
"""
@spec isogram?(String.t()) :: boolean
def isogram?(sentence) do
sentence
|> String.upcase()
# turn into list
|> String.split()
|> Enum.map(fn x -> String.graphemes(x) end)
|> List.flatten()
|> Enum.reduce([], fn el, acc ->
[[el] | acc]
|> List.flatten()
end)
end
end
I’m still unable to do IO.inspect(el) at the end. The idea is that within the reduce function, I would check if the element currently being passed in, is in the accumulator already. If yes, return false. If not, continue.
defmodule Isogram do
@doc """
Determines if a word or sentence is an isogram
"""
@spec isogram?(String.t()) :: boolean
def isogram?(sentence) do
sentence
|> String.upcase()
# turn into list
|> String.split()
|> Enum.map(fn x -> String.graphemes(x) end)
|> List.flatten()
|> Enum.reduce_while([], fn el, acc ->
if el in acc do
{:halt, false}
else
{:cont, [el | acc]}
end
end)
|> case do
false -> false
_other -> true
end
end
end