logoalt Hacker News

himata4113yesterday at 8:24 PM1 replyview on HN

  items.filter(|(i)| cond(i)).map(Pointer::idx).collect()
you can probably get away with this if you implement a Trait, not sure how but I know for a fact this is possible, idk why there's an enumerate there when you aren't even using it.

items is already an iteratible so you can do direct .filter on it as well

tl;dr if the code looks ugly you're probably not taking advantage of a language feature that allows it to look pretty.


Replies

sgarlandyesterday at 8:42 PM

This is in fact more readable, thank you.

I still don’t know that I find it more intuitive or readable than the simple loop, but it’s much less awful than before.

show 1 reply