Ruby-Like `split` in Elixir
Elixir's split
function is a bit different from the Ruby version you might be familiar with.
Here's Ruby's split
:
2.1.0 :001 > "FOOBAR".split("")
=> ["F", "O", "O", "B", "A", "R"]
And Elixir's:
iex(1)> String.split("FOOBAR", "")
["F", "O", "O", "B", "A", "R", ""]
Whoa, what's that extra ""
doing in there? Drink in the Elixir. A small amount of message board reading has led me to conclude this was very deliberate and isn't going to be changed.
Here's one way to get a Ruby-like split
:
iex(1)> String.split("FOOBAR", "", trim: true)
["F", "O", "O", "B", "A", "R"]
Tweet