Skip to main content

Selection functions

previousEvent

Commentary​

added in 0.0.5

stateful function

Obtains the last event generated. This function is usually useful when combined with stateMachine.

Can optionally drill into a subvalue using path.

You may also want to set a default value if your data is heterogeneously structured. 1


Examples​

Getting the last event​

{
"_gen": "oneOf",
"choices": [
{
"_gen": "previousEvent",
"path": [
"value"
]
},
{
"_gen": "uniformDistribution",
"bounds": [
1,
4
]
}
]
}
[
{
"headers": null,
"topic": "sandbox",
"value": 2.254341867377076,
"key": null
},
{
"headers": null,
"topic": "sandbox",
"value": 2.254341867377076,
"key": null
},
{
"headers": null,
"topic": "sandbox",
"value": 2.254341867377076,
"key": null
},
{
"headers": null,
"topic": "sandbox",
"value": 2.254341867377076,
"key": null
},
{
"headers": null,
"topic": "sandbox",
"value": 2.254341867377076,
"key": null
}
]

Setting a default value​

Use defaultValue to set a fallback.

If you're using path, remember that path is applied after the function evaluates, so make sure to structure your default value exactly as your happy path value would look.

In this example, the fallback value (42) is wrapped in a map with value because that's what previousValue will return on subsequent invocations.

{
"_gen": "previousEvent",
"path": [
"value"
],
"defaultValue": {
"value": 42
}
}
[
{
"headers": null,
"topic": "sandbox",
"value": 42,
"key": null
}
]

Specification​

JSON schema​

{
"type": "object",
"properties": {
"path": {
"type": "array",
"items": {
"oneOf": [
{
"type": "integer",
"minimum": 0
},
{
"type": "string"
}
]
}
},
"defaultValue": {}
}
}