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"
kokolegorille

kokolegorille

Underneath, it’s

iex> quote do: "aa" |> "bb#{}" 
{:|>, [context: Elixir, import: Kernel],
 [
   "aa",
   {:<<>>, [],
    [
      "bb",
      {:::, [],
       [
         {{:., [], [Kernel, :to_string]}, [], [{:__block__, [], []}]},
         {:binary, [], Elixir}
       ]}
    ]}
 ]}
adworse

adworse

Looks totally OK, it’s relatively new though; there was no such syntax three years ago :slight_smile:

Where Next?

Popular in Questions Top

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
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
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
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 27727 240
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New

We're in Beta

About us Mission Statement