Transform a pattern into a pattern of booleans

Is there a way to transform a pattern into a pattern of Booleans, with rests mapped to false, and anything else mapped to true? For example "~ 2 ~ 2" becomes "f t f t".

I have tried this, which I thought could work for positive integers: (> 0) <$> "~ 2 ~ 2". However, while numbers are mapped true, rests seem to be mapped to nothing. And unfortunately, many functions like while etc, require the false values to be there.

And a further question, can anyone point me to the documentation for <$>? It is ungooglable!


1 Like

~ just creates a gap in the pattern, it's not actually represented as an event. That's why nothing works, there's nothing there to work on. There used to be a function fill that could fill in gaps but it looks like it got lost in the transition to Tidal v1. I can't immediately think of a workaround for this, apart from starting with a binary pattern in the first place.

<$> is indeed the infix version of fmap. Rather than google, try hoogle:

That will search through all the haskell packages, including tidal.

1 Like

This is abusing some functions and notation a bit and will probably blow up if used improperly (it doesn't work on Pattern Bool correctly), but you could try doing a direct substitution on the string and then turning it into a pattern, for example:

toB :: String -> Pattern Bool
toB s = fmap (/= "F") $ parseBP_E $ map (\x -> if x=='~' then 'F' else x) s

Thanks for the help everyone!

Directly parsing the string seems to work.