dsounded
Another pipe enhancement topc: |>> (Ruby Object#tap like pipe)
Hello dear community!
So it came from my daily tasks, it’s just a proposal which once approved I’d gladly try to implement.
Before creating the topic I tried to search if something like that was already asked, so seems like not.
The idea is to have a pipe which returns the value that was passed as a first argument from the previous pipe back (even though the function itself can return something else) eg:
defmodule Test do
def call do
"users.csv"
|> File.stream!() # raw data
|> prepare() # list of maps
|>> insert() # the same list of maps
|>> send_emails() # the same list of maps
|> log()
end
...
defp insert(records) do
Repo.insert(User, records)
end
defp send_emails(records) do
MailService.send(to: records)
end
defp log(records) do
# do some logs related things
end
end
Right now it’s possible to design it in a way:
defp insert(records) do
Repo.insert(User, records)
records
end
defp send_emails(records) do
MailService.send(to: records)
records
end
So I’d like to hear your thoughts on this. The benefits I can see are: you can still test in isolation (it’s original returning value) and also compose related things into one pipe. (|>> shows it goes one step further (like to pass to the one after the next pipe)
It’s pretty subjective though that’s why I want to ask your opinion on this before I start investigating the pull request.
Most Liked
LostKobrakai
Last Post!
dsounded
Popular in Discussions
Other popular topics
Chat & Discussions>Discussions
Latest on Elixir Forum
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









