# revOn (subdivide a pattern and reverse the order of its parts)

**URL:** <https://uzu.lurk.org/t/revon-subdivide-a-pattern-and-reverse-the-order-of-its-parts/5092>\
**Category:** TidalCycles\
**Tags:** resources\
**Created:** [28 February 2024 04:25 UTC](https://uzu.lurk.org/t/revon-subdivide-a-pattern-and-reverse-the-order-of-its-parts/5092 "2024-02-28T04:25:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![geikha](https://uzu.lurk.org/user_avatar/uzu.lurk.org/geikha/32/2701_2.png) [@geikha](https://uzu.lurk.org/u/geikha)\
**Post date:** [28 February 2024 04:25 UTC](https://uzu.lurk.org/t/revon-subdivide-a-pattern-and-reverse-the-order-of-its-parts/5092/1 "2024-02-28T04:25:10Z")

</div>

Here's a function I made that quickly creates a lot of variation for patterns, specially when used in its list form. This function basically takes a number, divides the pattern (or rather, the current cycle) into that amount of pieces, and then reverses the order of those pieces. The list form allows you to easily do this concatenatively.

```haskell
revOn' vs f = case vs of
    [] -> f
    (x:xs) -> inside x rev $ rev $ revOn' xs f

revOn x = revOn' [x]

drawLine $ rev $ "0..7"
-- |76543210|76543210

drawLine $ revOn 2 $ "0..7"
-- |45670123|45670123

drawLine $ revOn 4 $ "0..7"
-- |67452301|67452301

drawLine $ revOn' [2,4] $ "0..7"
-- |23016745|23016745

```

The divisor can be fractional and can even be patterned, be it as part of the list or not. Which makes it super easy to create super scrambled, complex variations of patterns that are not random.

```haskell
do
  d1 $ revOn' [8,0.5,2,"<1 4>"] $ note (scale "phrygian" "0..7") # s "arpy" # room 0.3
  d2 $ "bd"

```

* * *

Strudel version:

```haskell
// will add soon

```

---

<div class="post-metadata">

**Author:** ![jwaldmann](https://uzu.lurk.org/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@jwaldmann](https://uzu.lurk.org/u/jwaldmann)\
**Post date:** [29 February 2024 16:54 UTC](https://uzu.lurk.org/t/revon-subdivide-a-pattern-and-reverse-the-order-of-its-parts/5092/2 "2024-02-29T16:54:39Z")

</div>

Yes. Just as a code-golfing exercise, and advertisment for higher-order functions, the following is equivalent:

```haskell
revOn' vs f = foldr (\x -> inside x rev . rev) f vs

```

And just for fun: `revOn' [2]` is rotation by 1/2,

```haskell
tidal> drawLine $ revOn' [2] "0..7"
|45670123|...
tidal> drawLine $ (1/2) ~> "0..7"
|45670123|...

```

and this also works if the split is uneven (two parts, different lengths), and this is actually used in a Java standard library: [https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/util/Collections.java#L843](https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/util/Collections.java#L843)
