FlowscopeDocs

T426

lambda in an invalid position or with a block body

Severity Error

Lambdas exist only as the function argument of collection methods such as map, filter, reduce, any, all and count. Their body is a single expression without braces. A lambda stored in a variable, passed elsewhere, or written with a { } body is rejected.

Write the lambda inline in the collection call with an expression body. For reusable logic, declare a named fn and call it from the lambda.

Failing example

Flowscope Script
script "Notional in thousands"
data tape = subscribe(data.trades, minNotional: 25_000.0)
state recent = rolling<float>(50)
on tape.trade(tr) {
  recent.push(tr.notional)
  let inK = recent.map(v => { v / 1000.0 })
  log.debug(str.format("max {0:.1}k", inK.max() ?? 0.0))
}

Fixed example

Flowscope Script
script "Notional in thousands"
data tape = subscribe(data.trades, minNotional: 25_000.0)
state recent = rolling<float>(50)
on tape.trade(tr) {
  recent.push(tr.notional)
  let inK = recent.map(v => v / 1000.0)
  log.debug(str.format("max {0:.1}k", inK.max() ?? 0.0))
}