Best way to pass new parameters to the next step


#1

I have a scenario where a transaction calls another transaction (which I am reusing elsewhere) and adds a parameter from the result of that transaction to the call to the next step. The code is as follows:

 ┆ def validate_attributes(gig:, indie:)
 ┆ ┆ Operations::ValidateGig.new.call(gig: gig).bind do |result_value|
       gig = result_value.fetch(:gig)
 ┆ ┆ ┆ Success(gig: gig, indie: indie)
 ┆ ┆ end
 ┆ end

Is there a more elegant way that is recommended to accomplish the above? My worry is that I am using the library in a way that is not documented and this could possibly break in future versions.


#2

Hi @cmavromoustakos, I don’t see any problem with this. You’re using the intended public behaviour of dry-transaction and dry-monads (i.e. calling bind, then returning a Result from the step method respectively), so I don’t see you having any problems with future compatibility.

(FWIW, if I was designing such a transaction class, I’d look to inject the ValidateGig dependency rather than calling it directly)