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
]
}
]
}
[
{
"topic": "sandbox",
"key": null,
"value": 2.81903025207377,
"headers": null
},
{
"topic": "sandbox",
"key": null,
"value": 2.81903025207377,
"headers": null
},
{
"topic": "sandbox",
"key": null,
"value": 1.603019501303062,
"headers": null
},
{
"topic": "sandbox",
"key": null,
"value": 3.1634957943967197,
"headers": null
},
{
"topic": "sandbox",
"key": null,
"value": 3.495495497068669,
"headers": 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
}
}
[
{
"topic": "sandbox",
"key": null,
"value": 42,
"headers": null
}
]

Specification

JSON schema

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