This has been proposed before, and it was rejected then as well. You're 
only saving a few characters, and it obfuscates that two completely 
different things are happening (assignment, function calling).

On Friday, May 19, 2017 at 1:27:29 PM UTC-4, OvermindDL1 wrote:
>
> Actually that specific example would not work now that I think of it, but 
> you could do it via a bit more macro-work.
>
>
> On Friday, May 19, 2017 at 11:26:19 AM UTC-6, OvermindDL1 wrote:
>>
>> You could easily make that into a library (in fact similar ones already 
>> exist, though not for 'just' that feature).
>>
>> Just define a new operator, say `<|>` since you are piping 'both ways' 
>> I'd say as a macro, then you can do it, it might even be as simple as 
>> (untested):
>> ```elixir
>> defmacro left <|> right do
>>   quote do
>>     unquote(left) = unquote(left) |> unquote(right)
>>   end
>> end
>> ```
>> Then you could do:
>> ```elixir
>> conn
>> <|> put_assign(:blah, :bloop)
>>  |> more_stuff()
>>  |> render(:index)
>> ```
>> or so.  Easily done as a library though, or just add it to your own 
>> project and require it where you want.
>>
>>
>>
>> On Friday, May 19, 2017 at 11:06:28 AM UTC-6, Mario Campa wrote:
>>>
>>> Hello, 
>>>
>>> I'm new to Elixir, so forgive me if this idea sounds silly.
>>>
>>> I keep repeating this pattern in multiple controllers:
>>>
>>> conn = Plug.Conn.put_session(conn, :foo, bar)
>>>
>>> or
>>>
>>> conn = conn |> Plug.Conn.put_session(:foo, bar)
>>>
>>>
>>> IMO it would be cool to have a shorter version to this where I can pipe 
>>> and assign like this:
>>>
>>> conn |>= Plug.Conn.put_session(:foo, bar)
>>>
>>>
>>> Similar to
>>>
>>> a = a + 2
>>> # or
>>> a += 2
>>>
>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/14a96e51-b032-4907-903a-7d35df33b6e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to