I'm seeing this error when I pass an empty seq to mapIt
C:\Users\slayc\.choosenim\toolchains\nim-#devel\lib\system\fatal.nim(54) sysFatal
Error: unhandled exception: index out of bounds, the container is empty [IndexDefect]
Error: execution of an external program failed: 'c:\Users\slayc\source\repos\AdventOfCode\Nim\nim2022\src\MainModule.exe'
Of course I can avoid this error by testing for len = 0 but I was wondering if I should raise this as an issue as mapIt should probably handle an empty sequence a bit more gracefully.
Looking at the code for mapIt it doesn't seem that there is an explicit test for an empty seq.
I am not a novice at nim programming. Such a claim would be implying I have far more competence and capability than in reality.
Passing an empty seq to mapIt works with devel and 1.6.10:
import std/sequtils
let
nums: seq[int] = @[]
strings = nums.mapIt($it)
echo strings
Thanks for the feedback.
my comment came from this
if myNewTracks.len > 0:
var myTrackMin: int = myNewTracks.mapIt(it.len).min - 1
if myTrackMin < myMin:
myMin = myTrackMin
where myNewTracks is a seq[seq[Coord]] and Coord is an object of col:int, row:int
The test for zero was added because I was getting the error message at the mapIt line.
my assumption is that the mapIt gives me a sequence of int (the lengths of the inner seq) and I then find the minimum value from that new seq.