FlowscopeDocs

T430

collection transform must be its own statement

Severity Error

map, filter and reduce may only appear as the whole right-hand side of a let, an assignment, or as a statement of their own. Nesting them inside a larger expression or condition is not allowed, so the cost of each transform stays visible in the code.

Bind the transform to a local first and use that local in the larger expression.

Failing example

Flowscope Script
script "Whale count"
data tape = subscribe(data.trades, minNotional: 50_000.0)
state recent = rolling<float>(100)
alert whales = alert(title: "Three whales in the last 100 prints")
on tape.trade(tr) {
  recent.push(tr.notional)
  if recent.filter(v => v >= 1_000_000.0).len >= 3 {
    whales.trigger()
  }
}

Fixed example

Flowscope Script
script "Whale count"
data tape = subscribe(data.trades, minNotional: 50_000.0)
state recent = rolling<float>(100)
alert whales = alert(title: "Three whales in the last 100 prints")
on tape.trade(tr) {
  recent.push(tr.notional)
  let big = recent.filter(v => v >= 1_000_000.0)
  if big.len >= 3 {
    whales.trigger()
  }
}