Passing values down a dry-transaction path

Hi everyone,

I’m wondering if there is a preferred way of passing values down the steps of a dry-transaction? Two use-cases I have in mind:

  1. All the steps need to check the params passed to the transaction at start.
  2. Each step wants to add its own results to a pipeline, while also transferring its inputs to the next step.

I’m currently doing something that feels clumsy: each step takes a hash of inputs, and then adds to that hash and passes it onwards in a Right monad. Alternatives like using instance level variables don’t sound appealing either.

How do others deal with this?

Hi @soumyaray, there’s actually no “blessed” or preferred way of doing what you describe. This is mostly because I haven’t wanted to enshrine one particular approach when it may not be appropriate for everyone’s specific domains.

If a hash works for you, then that’s fine, IMO! If you want to make it feel a little less informal, then you could build some sort of “context” object that gets passed around instead, with a particular API that fully suits your needs. How does that sound to you?

You definitely want to avoid using instance variables, since steps intended to work with dry-transaction shouldn’t be mutating their state from call to call.

Thanks @timriley! I’m happy I haven’t missed some well known pattern for doing this. I’ll try both ways you describe and see how they feel. I’m really loving dry-transactions and what it does for my code. If you or others are using it actively in production code, it would be really nice to see actual examples and use-cases as part of the documentation.