Does pipe always apply partial evaluation?

First of all, I am new to elixir so I’m sorry if this question seems trivial.
I’m currently confused about partial evaluation application in elixir. Does pipe operator always apply partial evaluation? What makes me confused is because every function in pipe operator can be written with less arguments than it should.
e.g.

payload
    |> Map.put("custom_id", payload["id"])
    |> Map.drop(["id"])

As we can see, Map.put can receive 2 arguments when it should be 3 arguments, as well as Map.drop can receive 1 argument when it should be 2 arguments. Is this an example of partial evaluation in elixir?

If not so, can I have some examples of partial evaluation application in elixir?

I appreciate any help that I can get, thank you in advance

1 Like

Hey @glendaesutanto, the pipe operator does not use partial evaluation at all. The pipe operator is much simpler than that, it does a compile time transformation.

When you do:

list |> IO.inspect(pretty: true)

it transforms it at compile time to:

IO.inspect(list, pretty: true)

Partial application is a completely different thing:

Enum.map(["hello", "world"], &IO.inspect(&1, pretty: true))

The second arg to Enum.map is a partially applied function: &IO.inspect(&1, pretty: true). IO.inspect can take 2 arguments, and here one of them has been applied already, the pretty: true option.

8 Likes

I see, thank you so much for your answer :grinning:

2 Likes