Why is this OK,
iex(23)> << "Halo" >>
"Halo"
while this is not OK in Elixir?
iex(24)> << String.reverse("Halo") >>
** (ArgumentError) argument error
When you have an expression inside << >>, the type of that expression is assumed to be an integer representing one byte by default.
iex(1)> << trunc(65.2) >>
"A"
iex(2)> << trunc(1000.3) >>
<<232>>
If your expression is a binary (also called a String in Elixir), you need to specify the type of the expression explicitly:
iex(3)> << String.reverse("Halo")::binary >>
"olaH"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With