You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This'd be a nice ergonomic tweak, an operator in the style of Iterator::filter_map() would be really great. Currently there's a somewhat strange workaround using .flat_map(), e.g.
and while this would functionally be nearly identical, the FilterMap operator could likely specialize somewhat since it only has to handle a single output value
Implementation-wise yes, filter_map and flat_map are equivalent. However, they do have the semantic difference of "flattening an expanding collection" vs. "removing some items from a collection". It's a very slight thing that tripped me up until I discovered the flat_map pattern, it works but it feels like a slight misuse of impl Iterator for Option, almost like writing for x in Some(thing) {}
Activity
frankmcsherry commentedon Jan 25, 2021
I think
filter_mapis justflat_map, isn't it? The latter takes something that implementsIntoIterator<Item=T>andOption<T>implements that trait.ryzhyk commentedon Jan 25, 2021
Heh, sorry about my (deleted) posts, I'm used to seeing your messages in the DDlog repo :)
But yeah, I use flat_map to express filter_map in DD.
Kixiron commentedon Jan 26, 2021
Implementation-wise yes,
filter_mapandflat_mapare equivalent. However, they do have the semantic difference of "flattening an expanding collection" vs. "removing some items from a collection". It's a very slight thing that tripped me up until I discovered theflat_mappattern, it works but it feels like a slight misuse ofimpl Iterator for Option, almost like writingfor x in Some(thing) {}