Skip to main content

Transformation functions

cycle

Commentary

added in 1.1.9

Given a sequence of elements, cycle emits one element at a time in-order, looping when it reaches the end of the sequence.


Examples

Cycling a constant

The most simple example is setting sequence to a constant array. cycle will emit each element in order, and then go back to the start.

{
"_gen": "cycle",
"sequence": [
"a",
"b",
"c"
]
}
[
"a",
"b",
"c",
"a",
"b"
]

Cycling a function

sequence can also be a function call. Note that this function will only be called once and its value immutably frozen so that cycle has a stable target to iterate over.

{
"_gen": "cycle",
"sequence": {
"_gen": "var",
"var": "colors"
}
}
[
"red",
"green",
"blue",
"red",
"green"
]

Specification

JSON schema

{
"type": "object",
"properties": {
"sequence": {
"oneOf": [
{
"type": "array",
"items": {}
},
{
"type": "object",
"properties": {
"_gen": {
"type": "string"
}
},
"required": [
"_gen"
]
}
]
}
},
"required": [
"sequence"
]
}