The closure takes a different number of parameters than the function it is passed to expects.
For example, map passes one item, reduce passes two values.
Wrong#
fn total(xs: [int]): [int] = xs.map((a, b) => a + b)Fixed#
fn total(xs: [int]): [int] = xs.map(a => a + 1)Common causes#
- Using
(i, x) =>withmapto get the index: writexs.enum().map((i, x) => ...). - Mixing up
map(one parameter) andreduce(two). - A closure with zero parameters is written
() => ....