You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the doc comment for sequtils.toSeq we find this example:
let
numeric =@[1, 2, 3, 4, 5, 6, 7, 8, 9]
odd_numbers =toSeq(filter(numeric) do (x: int) -> bool:
if x mod2==1:
result=true)
If you run this, the filtered sequence is produced twice, as can be seen here on the nim playground with my instrumented copies of filter and toSeq. I think its the same problem that was fixed eg. in mapIt by copying the iterable to a local variable and therefore forcing the iteration to take place.
My proposed fix looks like this:
templatetoSeqFixed*(iter: untyped): untyped=whencompiles(iter.len):
iter
else:
varresult: seq[type(iter)] =@[]
for x in iter:
result.add(x)
result
but, as usual, i am not sure if this fix is correct...