[erlang-questions] Pipe Operator in Erlang?

Loïc Hoguin essen@REDACTED
Fri Jul 10 10:15:54 CEST 2015


On 07/10/2015 07:17 AM, Pierre Fenoll wrote:
> A pipe operator would turn this structure-specific code into something
> more readable and editable too.
> Maybe like something like this:
>
>      NewContext = Context
>          |> cb_context:set_doc(_, [])
>          |> cb_context:set_resp_status(_, success)
>          |> cb_context:set_resp_data(_, [])
>          |> cb_context:set_resp_etag(_, undefined)
>
> Where m:f(_, A2) is fun (_1) -> m:f(_1, A2) end; thus redefining _ for
> pipes (in non-matching contexts…).

What's wrong with this?

NewContext = cb_context:set(#{doc=>[], resp_status=success...}, Context)

Has less repetition/verbosity, is most likely faster, already works 
today, and you can also use a proplist if you're a map hater.

-- 
Loïc Hoguin
http://ninenines.eu
Author of The Erlanger Playbook,
A book about software development using Erlang



More information about the erlang-questions mailing list