Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a performance difference between using flatten(…map()…) vs flatMap()?

I’m trying to understand if using flatMap() is exactly the same that doing a map() inside flatten() with regards to performance and resource usage.

For example in my tests comparing

%dw 2.0
output application/json
---
flatten(payload.prefixes map {
      "ip_prefix": $.ip_prefix,
      "region": $.region++"-beta",
      "service": "NewCorp",
      "network_border_group": $.network_border_group
} 
)

and

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

%dw 2.0
output application/json
---
payload.prefixes flatMap {
      "ip_prefix": $.ip_prefix,
      "region": $.region++"-beta",
      "service": "NewCorp",
      "network_border_group": $.network_border_group
} 

I didn’t notice a performance difference.

>Solution :

It should be the same no mayor performance implications between one and the other. I usually prefer using flatMap as it reads better, but that is a personal opinion.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading