# Mapper logic reuse - suggestions needed

**URL:** <https://discourse.rom-rb.org/t/mapper-logic-reuse-suggestions-needed/559>\
**Category:** Issues\
**Created:** [September 29, 2022, 3:13pm UTC](https://discourse.rom-rb.org/t/mapper-logic-reuse-suggestions-needed/559 "2022-09-29T15:13:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![codeslinger](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@codeslinger](https://discourse.rom-rb.org/u/codeslinger)\
**Post date:** [September 29, 2022, 3:13pm UTC](https://discourse.rom-rb.org/t/mapper-logic-reuse-suggestions-needed/559/1 "2022-09-29T15:13:26Z")

</div>

Hello,  
I am noticing two patterns:

1. I am creating a mapper for each unique combination of #combine inputs
2. I having a lot of repeating code in my mappers across different relations when I combine associations.

Do you have any suggestion on how to not repeat code in different mappers OR even the same mapper?

For example I have this block in 3 different mappers OR repeating in the same mapper:

```auto
        guard(->(issue) { !issue[:feature].nil? }) do
          map_value(:feature) do
            unwrap :issue, [:comments]
            reject_keys [:issue]

            constructor_inject Feature
          end
        end

```

---

<div class="post-metadata">

**Author:** ![solnic](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/solnic/32/279_2.png) [@solnic](https://discourse.rom-rb.org/u/solnic)\
**Post date:** [October 1, 2022, 8:29am UTC](https://discourse.rom-rb.org/t/mapper-logic-reuse-suggestions-needed/559/2 "2022-10-01T08:29:37Z")

</div>

You can simply define re-usable mapping procs as constants and…re-use them 🙂

---

<div class="post-metadata">

**Author:** ![codeslinger](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@codeslinger](https://discourse.rom-rb.org/u/codeslinger)\
**Post date:** [October 4, 2022, 2:46pm UTC](https://discourse.rom-rb.org/t/mapper-logic-reuse-suggestions-needed/559/3 "2022-10-04T14:46:23Z")

</div>

No way to call a registered mapper from within another mapper?

If I have to go with the constant / proc solution where in the ROM framework should I be declaring them?

---

<div class="post-metadata">

**Author:** ![alassek](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/alassek/32/260_2.png) [@alassek](https://discourse.rom-rb.org/u/alassek)\
**Post date:** [October 17, 2022, 7:22pm UTC](https://discourse.rom-rb.org/t/mapper-logic-reuse-suggestions-needed/559/4 "2022-10-17T19:22:29Z")

</div>

The [ROM documentation](https://rom-rb.org/5.0/learn/core/mappers/) has an example of what this looks like. In addition to using `register_as`, if you’d prefer to use a custom callable object you could also register it manually as part of the configuration step.
