Scanned List (Expression) — skLambda

Addon: skLambda · Category: Expression · Since: 1.2.0

Syntax

%objects% scanned (with|using) %object% from %object%

Description

Like `reduced`, but keeps every intermediate result instead of just the final one, so it's handy for cumulative totals. The list is combined pairwise left-to-right with a two-argument lambda (accumulator, next element), and each running result is emitted. For `3, 5, 2` and an adding lambda this yields `3, 8, 10`. Without a seed, a one-element list scans to that element and an empty list scans to nothing. With `from %object%`, that value seeds the accumulator and is itself the first result, so `3, 5, 2` from 100 yields `100, 103, 108, 110` and an empty list scans to just the seed.

Examples

# {_add} = lambda (a: number, b: number) -> number: return {_a} + {_b}
set {_totals::*} to {_nums::*} scanned with {_add}
set {_totals::*} to {_nums::*} scanned with {_add} from 100   # 100, then each running total

View source