sihui_io

sihui_io

String interpolation with pipe

rest is [“a”] and last_gift is “b”.
rest |> Enum.join(", “) returns “a”, which is a string.
“a” |> “#{}, and #{last_gift}” returns “a, and b”.
But when I pipe them together, I get ArgumentError.
rest |> Enum.join(”, ") |> “#{}, and #{last_gift}”
** (ArgumentError) argument error

What do I miss? :thinking:

Most Liked

cantiero

cantiero

This version looks ok IMO:

"test"
|> then(&"shmest #{&1}")
voltone

voltone

Right, so "234#{five}" is actually <<"234", five::binary>>, which is invoking Kernel.SpecialForms.<<>>. Piping something into that prepends the value at the front of that binary, if it is a legal parameter to <<>>.

So in the end "1" |> "234#{five}" expands to <<"1", "234", five::binary>> which happens to be legal. I don’t think it’s intentional.

sihui_io

sihui_io

It turns out a |> "#{}" doesn’t mean we are actually interpolating a into the position of #{}

iex(71)> "a" |> "This is: #{}, and #{last}"
"aThis is: , and b"
iex(72)> "a" |> "This is: , and #{last}"
"aThis is: , and b"

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
beno
I will often find my self writing things similar to: case some_value do nil -&gt; something() "" -&gt; something() _ -&gt; somethi...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
New

Other popular topics Top

hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29703 241
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement