Link Search Menu Expand Document

Preserving item orders

Table of contents

  1. Ordering
  2. Ordering inline and non-contiguous shuffles

Ordering

Sometimes you want to shuffle items, however you still want to preserve some relation in the text. In these cases, the ord tag can come in handy. Let’s look at a first example:

/** Default Shuffle */
filterManager.install(closet.recipes.shuffle({ tagname: 'mix' }))

/** Ordering */
filterManager.install(closet.recipes.order({ tagname: 'ord' }))
Countries of Asia: [[mix1::India||China||South Korea||Kazakhstan]]
Capitals of Asia: [[mix2::New Delhi||Beijing||Seoul||Nur-Sultan]]
[[ord::mix1,mix2]]

In this example, we shuffle the countries, and the capitals. However we don’t want to get countries and capitals to get out of order with each other respectively. The ord tag alters the mix tag in a way, that it will still shuffle at random, but preserve this connection.

/** Default Shuffle */
filterManager.install(closet.recipes.shuffle({ tagname: 'mix' }))

/** Ordering */
filterManager.install(closet.recipes.order({ tagname: 'ord' }))
Capital of [[mix1::India[[ord::mix1,mix2]]]]: [[mix2::New Delhi]]
Capital of [[mix1::China]]: [[mix2::Beijing]]
Population of [[mix3::South Korea[[ord::mix3,mix4]]]]: [[mix4::51,709,098]]
Population of [[mix3::Kazakhstan]]: [[mix4::18,448,600]]

When shuffling sentences, the ord tag is especially handy, because you can focus on the important parts.


Ordering inline and non-contiguous shuffles

/** Fancy shuffle */
const colorWheel = function*() {
  while (true) {
    yield 'pink'
    yield 'lime'
    yield 'yellow'
  }
}

const cw = colorWheel()
cw.next()

const colorfulWithMiddleDot = closet.Stylizer.make({
  separator: '・',
  mapper: v => (
    `<span style="color: ${cw.next().value};">${v}</span>`
  ),
  processor: v => `〈${v}〉`,
})

const withMiddleDot = closet.Stylizer.make({
  separator: '・',
})

const withSlash = closet.Stylizer.make({
  separator: ' / ',
})

const withVs = closet.Stylizer.make({
  separator: ' vs ',
  mapper: (v, i) => `${i}: ${v}`
})

filterManager.install(
  closet.recipes.shuffle({
    tagname: 'cmix',
    stylizer: colorfulWithMiddleDot,
  }),

  closet.recipes.shuffle({
    tagname: 'amix',
    stylizer: withMiddleDot,
  }),

  closet.recipes.shuffle({
    tagname: 'vmix',
    stylizer: withVs,
  }),

  closet.recipes.shuffle({
    tagname: 'mix',
    stylizer: withSlash
  }),
)

/** Ordering */
filterManager.install(closet.recipes.order({ tagname: 'ord' }))
[[mix1::Russell's sign||Granulosa cell tumor[[ord::mix1,mix2]]]]
- [[mix2::indirect sign of bulimia nervosa or anorexia nervosa]]
- [[mix2::ovarian tumor associated with estrogen secretion]]

The ord tag can also relate values from a mix single with individual mix tags