rewrite icon indicating copy to clipboard operation
rewrite copied to clipboard

Swap `filter()` and `map()`

Open yeikel opened this issue 2 years ago • 2 comments

Before :


incidents.stream().filter(e-> e.getIncidentID().equalsIgnoreCase("123").map(Results::getIncdntId)

After :


incidents.stream().map(Results::getIncdntId).filter(e-> e.equalsIgnoreCase("123"))

yeikel avatar May 20 '22 17:05 yeikel

Hi @yeikel! I think there may be a typo in the After. The map would return the values from Object#get(), so the filter can only act on the mapped objects. So, in this case the filter should be e -> e.equalsIgnoreCase("123");

I'll add it to recipes wanted, and mark it for uses-dataflow. Thanks!

traceyyoshima avatar May 25 '22 23:05 traceyyoshima

Hi @yeikel! I think there may be a typo in the After. The map would return the values from Object#get(), so the filter can only act on the mapped objects. So, in this case the filter should be e -> e.equalsIgnoreCase("123");

I'll add it to recipes wanted, and mark it for uses-dataflow. Thanks!

That's correct. I updated it

Thanks!

yeikel avatar May 26 '22 00:05 yeikel