Something like this?
import sequtils
let a = (1..5).toSeq
echo a.mapIt(1.0*it.float)
Thank for you for the quick reply. It works!
But if I replay the second line with
let a = @[1..5]
It shows compiling error. Something subtle here?
It's because @[1..5] is not equivalent to @[1, 2, 3, 4, 5].
It's actually a sequence of one element of type HSlice:
echo @[1..5].type # prints seq[HSlice[system.int, system.int]]
This is why you'd want to write (1..5).toSeq to obtain @[1, 2, 3, 4, 5], it creates a range then converts it to a seq.
There is (IMO) an easier to read syntax with sugar :
import sequtils
import sugar
var xx = toSeq(1..5).map(x => x.float)
Here comes the zero_functional solution:
import sequtils, zero_functional
let s = toSeq(1..5) --> map(it.float).to(seq)
Complete overkill for this simple case, but I just won't stop plugging this ingenious lib. :o)