How do I convert an array of floats to array of ints?. I've tried
import math
from sequtils import map
proc toInt(x: float64): int =
return int(x)
let xx = @[42.3, 48.5, 43.4]
var x = xx.map(toInt)
echo x
and I got
Error: type mismatch: got <seq[float64], proc (x: float64): int{.noSideEffect, gcsafe, locks: 0.} | proc (f: float): int{.noSideEffect, gcsafe, locks: 0.}>
but expected one of:
proc map[T, S](s: openArray[T]; op: proc (x: T): S {.closure.}): seq[S]
first type mismatch at position: 2
required type for op: proc (x: T): S{.closure.}
but expression 'toInt' is of type: None
expression: map(xx, toInt)
You can use mapIt instead of map (which takes a procedure or an anonymous procedure)
So it would look like this:
import sequtils
let xx = @[42.3, 48.5, 43.4]
var x = xx.mapIt(int(it))