What does "|>" mean in an elixir?
it gives you a way to avoid wrong code like this:
orders = Order.get_orders(current_user)
transactions = Transaction.make_transactions(orders)
payments = Payment.make_payments(transaction, true)
the same code using a pipeline operator:
current_user
|> Order.get_orders
|> Transaction.make_transactions
|> Payment.make_payments(true)
Look at the Payment.make_payments function, there is a second bool parameter if it is the first parameter:
def make_payments(bool_parameter, transactions) do
//function
end
it didn't work anymore.
When developing an elixir application, keep in mind that important parameters should come first, in the future this will give you the opportunity to use a pipeline operator.
I hate this question when writing non-elixir code: what should I name this variable? I spend a lot of time answering.
source to share
In addition to Stefan's excellent comment, you can read the "Pipeline Operator" section of this blog post for a better understanding of the use case that the Pipeline Operator is designed to address in Elixir. The important idea is this:
The pipeline operator allows you to combine different operations without using intermediate variables.,. The code can be easily followed by reading from top to bottom. We pass the state through various transformations to get the desired result, each transform returning some modified version of the state.
source to share