I currently have:

self.filter_map(|entry| { if let TocEntry::FirstTrackInfo { track, control, .. } = entry && control.is_audio() { Some(*track) } else { None } }) 

which, I hope for obvious reasons, I don't really like :ferris_clueless:

Is there a reasonable syntax for this? Or some kind of chainable set of methods?

My solution will be avoid the closure completely by using a chain of filters and maps, but it would still be nice to know if there is a better option for the above closure for the future ...

self.filter(|entry| entry.control().is_audio()) .filter(|entry| matches!(entry, TocEntry::FirstTrackInfo { .. })) .map(TocEntry::track) .flatten() .next() 

1 post - 1 participant

Read full topic