# Using map, filters in complex pipelines - a.k.a Stupid Jinja2 Tricks no. 42

**URL:** <https://forum.ansible.com/t/using-map-filters-in-complex-pipelines-a-k-a-stupid-jinja2-tricks-no-42/2340>\
**Category:** Get Help\
**Tags:** jinja2\
**Created:** [November 13, 2023, 9:33pm UTC](https://forum.ansible.com/t/using-map-filters-in-complex-pipelines-a-k-a-stupid-jinja2-tricks-no-42/2340 "2023-11-13T21:33:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [November 13, 2023, 9:33pm UTC](https://forum.ansible.com/t/using-map-filters-in-complex-pipelines-a-k-a-stupid-jinja2-tricks-no-42/2340/1 "2023-11-13T21:33:30Z")

</div>

Is there any way to do what this does with just `map`, pipes, and filters instead of the `{% for … %}` old school style of looping? (Example borrowed from earlier discussion over on [https://matrix.to/#/#users:ansible.com.](https://matrix.to/#/#users:ansible.com.))

```yaml
    - name: Filter pain point - product
      ansible.builtin.debug:
        msg: |-
         {% for p in starter | map('map', 'list') -%}
         {{ p[0] | product(p[1]) -}}
         {{ '' if loop.last else ', ' -}}
         {% endfor %}
      vars:
        starter: [[ [ 11, 12, 13], "a" ],
                   [[ 21, 22, 23], "b" ] ]

```

The result is the product of the number lists with their corresponding letters:

```json
[[[11, "a"], [12, "a"], [13, "a"]], [[21, "b"], [22, "b"], [23, "b"]]]

```

I keep trying to sneak up on a solution like the one below, but `product` only ever takes the first parameter. I can’t get `map()` to feed the second element to the filter as the “inside parens” parameter. This isn’t just an issue with `product`; it seems to hold for any filter that expects “something left of the pipe” and “something in the parameter list.”

```yaml
    - name: Filter pain point - product
      ansible.builtin.debug:
        msg: 
          - "{{ starter }}"
          - "{{ starter | map('map', 'list') }}"
          - "{{ starter | map('map', 'list') | map('product') }}" # borken!
      vars:
        starter: [[ [ 11, 12, 13], "a" ],
                   [[ 21, 22, 23], "b" ] ]
# hand-tweaked output:
# [[[[11, 12, 13], 'a'], [[21, 22, 23], 'b']],
# [[[11, 12, 13], ['a']], [[21, 22, 23], ['b']]],
# [[([11, 12, 13],), (['a'],)], [([21, 22, 23],), (['b'],)]]]

```

Is there really no way to use these filters in complex pipelines?
