Hello everyone, is there a function similar to foldlIt
var numbers = @[1, 2, 3]
echo foldl(numbers, a+b)
This works fine and is equal to 6
But the following compiles and reports an error
type
TWPT* = object
x*: int
y*: int
var pts = @[TWPT(x: 0, y: 0), TWPT(x: 1, y: 1)]
echo foldl(pts, a.x + b.x)
#echo foldlIt(pts, a.x + b.x)
I think there should be such a function, but I can't find a way, can someone tell me, thank you
type
TWPT* = object
x*: int
y*: int
var pts = @[TWPT(x: 0, y: 0), TWPT(x: 1, y: 1)]
echo foldl(pts, a.x + b.x)
But this compilation fails, and an error is reported
You need to do this:
import sequtils
type
TWPT* = object
x*: int
y*: int
var pts = @[TWPT(x: 0, y: 0), TWPT(x: 1, y: 1)]
echo foldl(pts, a + b.x, 0)