3 ms·
For the example that the OP listed in regards to pipes I prefer to leverage something like https://github.com/CrowdHailer/OK https://github.com/CrowdHailer/OK i
by allanmacgregor 5y ago
For the example that the OP listed in regards to pipes I prefer to leverage something like https://github.com/CrowdHailer/OK https://github.com/CrowdHailer/OK it allows to retain the expressiveness you get with pipes but cleanly handles result tuples:
require OK
OK.for do
user <- fetch_user(1) # `<-` operator means func returns {:ok, user}
cart <- fetch_cart(1) # `<-` again, {:ok, cart}
order = checkout(cart, user) # `=` allows pattern matching on non-tagged funcs
saved_order <- save_order(order)
after
saved_order # Value will be wrapped if not already a result tuple
end