I split the string into a character and would like to trim all the items as a result of the split. I expect the following to work as it String.trim/1exists:
iex> "My delimited ! string of doom" |> String.split("!") |> Enum.map(String.trim)
** (UndefinedFunctionError) function String.trim/0 is undefined or private. Did you mean one of:
* trim/1
* trim/2
(elixir) String.trim()
I get UndefinedFunctionErrorindicating that the function String.trim/0does not exist. What I want is easy to do with an anonymous function passed to Enum.map:
iex> "My delimited ! string of doom" |> String.split("!") |> Enum.map(fn (word) -> String.trim(word) end)
["My delimited", "string of doom"]
Does it use an Enum.map/2anonymous function as a second parameter? Is it possible to specify the desired function as a parameter?
source
share