Applying a function when boolean pattern matches

I have a feeling that there probably is function that already does this, but I don't know how to look it up.

In the docs for mask it reads:

mask takes a boolean (aka binary) pattern and 'masks' another pattern with it. That is, events are only carried over if they match within a 'true' event in the binary pattern.

Is there a function which takes another function (e.g., ply 2 or (# speed (-1))) and only applies it to events if they match within a 'true' event in a binary pattern?

d1 $ missingFunction "t(3,8)" (ply 2) $ s "bd*8" would be the same as
d1 $ s "bd*2 bd bd bd*2 bd bd bd*2 bd"

i think while does this


That's exactly what I needed. Thanks!