Repeating a pattern in a cat?

(At the risk of reviving something that was discussed two years ago Repeating items in a cat? …)

Say I havw two patterns concatenated, and I want each one to play twice:

d1 $ cat[
n " 0 3 ~ 9 8 4 5 7",
n "6 5 3 2 1 2 3 4"
] # s "arpy"

Came up with this:

d1 $ slow 2 $ cat[
fast 2 $ n " 0 3 ~ 9 8 4 5 7",
fast 2 $ n "6 5 3 2 1 2 3 4"
] # s "arpy"

Feels a bit of a convoluted solution, but works! Any better ideas?

1 Like

@tedthetrumpet you'll want to use the very handy custom function ncat.

ncat :: [(Time, Pattern a)] -> Pattern a
    ncat = seqPLoop . go 0
      where
        go _     []          = []
        go t_acc ((0, _):ps) = go t_acc ps
        go t_acc ((t, p):ps) = (t_acc, t', p) : go t' ps
          where
            t' = t_acc + t

your code would then look like this:

d1 $ ncat [
(2, n " 0 3 ~ 9 8 4 5 7"),
(2, n "6 5 3 2 1 2 3 4")
] # s "arpy"
2 Likes

That looks great, thanks!

Unfortunately… this is for a project where we are working with MiniTidal in the browser using Estuary, so I don't think we can add custom functions :frowning:

But still a useful function :slight_smile: