# Passing values to mapper without using "map\_with"

**URL:** <https://discourse.rom-rb.org/t/passing-values-to-mapper-without-using-map-with/593>\
**Category:** Uncategorized\
**Created:** [February 9, 2023, 9:14pm UTC](https://discourse.rom-rb.org/t/passing-values-to-mapper-without-using-map-with/593 "2023-02-09T21:14:30Z")\
**Posts on this page:** 6\
**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:** [February 9, 2023, 9:14pm UTC](https://discourse.rom-rb.org/t/passing-values-to-mapper-without-using-map-with/593/1 "2023-02-09T21:14:31Z")

</div>

In the documentation ([ROM - Mappers](https://rom-rb.org/learn/core/5.2/mappers/#using-custom-mappers)) you can use the \>\> operator to pass data to a custom mapper.

If I have defined a mapper class inheriting from ROM::Transformer, what would the syntax be to pass data to it via \>\> (or other method)?

I’m aware of `Relation#map_with` but I need to pass a cached value into the mapper. How can I do this?

Many thanks!!

---

<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:** [February 14, 2023, 7:17am UTC](https://discourse.rom-rb.org/t/passing-values-to-mapper-without-using-map-with/593/2 "2023-02-14T07:17:20Z")

</div>

Could you show an example of what you’re trying to achieve? I’m not sure what you’re after exactly.

---

<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:** [February 15, 2023, 4:34pm UTC](https://discourse.rom-rb.org/t/passing-values-to-mapper-without-using-map-with/593/3 "2023-02-15T16:34:02Z")

</div>

Given that I have a mapper class defined MyMapper:

result = my\_relation.by\_pk(id)  
…some other code  
send result through mapper here without hitting the db…  
mapped\_results = results \>\> MyMapper.new ??

Is this possible and what is the correct syntax?

---

<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:** [February 16, 2023, 9:36am UTC](https://discourse.rom-rb.org/t/passing-values-to-mapper-without-using-map-with/593/4 "2023-02-16T09:36:31Z")

</div>

Ohh, it’s just a function. So `my_mapper.call(results)` 🙂

---

<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:** [February 16, 2023, 3:54pm UTC](https://discourse.rom-rb.org/t/passing-values-to-mapper-without-using-map-with/593/5 "2023-02-16T15:54:56Z")

</div>

Thank you! That seems obvious now given " A mapper can be any object which responds to `#call`, which accepts a relation and return an array with results back".  
🙂 Sorry to take your time for this.

---

<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:** [February 17, 2023, 7:47am UTC](https://discourse.rom-rb.org/t/passing-values-to-mapper-without-using-map-with/593/7 "2023-02-17T07:47:18Z")

</div>

No worries 🙂 I hope it does the trick for you.
