Hey Djordje, what you’re hinting at – and what I think you’re looking for – is function composition which can be pulled off using the Transactable gem. Example:

pipe 1, method(:first), method(:second)

Further details are explained in the links above, though.

Oh, interesting, thanks!
Is this related to dry-transaction in some way? I used to use it years ago and I’m wondering if this is similar.
Thank you very much for this, I got to look into it and learn how to use it.

Yep! So Transactable is an alternative approach to Dry Transaction with a strong focus on function composition. The concept is the same, though, where you compose multiple steps together using monads.

You could achieve this with a built-in concept in dry-monads called do notation

class Operation
include Dry::Monads[:result]
include Dry::Monads::Do.for(:call)
def call(a)
result = yield first(a)
result = yield second(**result)
Success(result)
end
private
def first(a)
Success(x: a)
end
def second(x:)
Success(:anything)
end
end

Yeah, I know about do notation, but I find it cumbersome to come up with the names for every intermediate step and it somehow seems unnatural. Especially when the situation becomes more complicated and some “or” and “tee” cases are added, it soon loses readability in my opinion.
Thanks!