# \[Dry::Transaction\] Pattern matching of steps inside the around step

**URL:** <https://discourse.dry-rb.org/t/dry-transaction-pattern-matching-of-steps-inside-the-around-step/514>\
**Category:** Uncategorized\
**Created:** [March 15, 2018, 8:36am UTC](https://discourse.dry-rb.org/t/dry-transaction-pattern-matching-of-steps-inside-the-around-step/514 "2018-03-15T08:36:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sineed](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/sineed/32/239_2.png) [@sineed](https://discourse.dry-rb.org/u/sineed)\
**Post date:** [March 15, 2018, 8:36am UTC](https://discourse.dry-rb.org/t/dry-transaction-pattern-matching-of-steps-inside-the-around-step/514/1 "2018-03-15T08:36:36Z")

</div>

Hi! I started using `dry-transaction` gem and noticed a small problem. What I’m trying to do is to replace the huge service classes with `dry` abstractions. I started with `Dry::Transaction` by adding steps.  
Currently I have a file with 10 steps, and the third one is the `around` step. And I want the ability to pattern match steps below the `around` one. I started with the straightforward implementation:

```ruby
transaction = MyTransaction.new
transaction.(input) do |m|
  m.success { |v| v }
  m.failure :some_step_below_the_around do |v|
    puts "Failed in some step"
  end
  m.failure :around_step do |v|
    puts "Failed in around step"
  end
end

```

I noticed that the `failure` match is called for `failure :around_step` for all steps above the `around` one.

I found a workaround to have the ability to pattern match on specific step inside the around:

```ruby
results = []
transaction.(input) do |m|
  m.success {}

  m.failure :around do |value|
    ::Dry::Transaction::ResultMatcher.(Dry::Monads::Failure(value)) do |n|
      n.success {}

      n.failure :some_step_below_the_around do |v|
        results << "Failed in some step"
      end
    end
  end
end

results #["Failed in some step"]

```

But I thought that this is not good enough because api of the gem might change and wanted to share.  
I’ve added some specs about this problem [here](https://github.com/grabr/dry-transaction/commit/98bb6cdcb5a6490686c46bcfc3e466476b81c6ce).

---

<div class="post-metadata">

**Author:** ![timriley](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/timriley/32/25_2.png) [@timriley](https://discourse.dry-rb.org/u/timriley)\
**Post date:** [March 21, 2018, 10:41pm UTC](https://discourse.dry-rb.org/t/dry-transaction-pattern-matching-of-steps-inside-the-around-step/514/2 "2018-03-21T22:41:02Z")

</div>

Hi @sineed, thanks for writing this up. I think this is a legitimate bug, and we should fix it. I’ve opened [https://github.com/dry-rb/dry-transaction/issues/99](https://github.com/dry-rb/dry-transaction/issues/99) to track the issue.
