Sugar works with map
import sugar
proc map2*[T, R](list: openArray[T]; cb: proc (x: T): R): seq[R] =
for v in list: result.add(cb(v))
result
echo @[1, 2].map2((v) => v*v)
But not with each
, seems like it somehow related to void
, is there a way to make it work with void
too?
import sugar
proc each2*[T](list: openArray[T]; cb: proc (x: T): void): void =
for v in list: cb(v)
@[1, 2].each2((v) => echo v)