#Shorthand for Option.map(|x| some_predicate(x)).unwrap_or_default()

4 messages · Page 1 of 1 (latest)

half roost
#

Hi! I've been finding myself wanting to evaluate some predicate against the contents of an Option, and get the resulting bool out, such that None => false, Some(x) if !some_predicate(x) => false, Some(x) if some_predicate(x) => true.

Is there a convenient shorthand from this? I've looked at the Option doc and can't find one, but I feel like I'm maybe missing something. I can also think of into_iter().any(|x| some_predicate(x)), but I don't know if that's really an improvement.

sinful ice
half roost
#

ah, dang, that is quite nice otherwise - thanks, I'll consider adding it to my nightly features!

agile sun
#

you can also do opt.map_or(false, some_predicate)