Closed aaron-jack-manning closed 2 years ago
Th order of index and element parameters is reverse:
val vect = vector(6, 0)
vect.foreach-indexed fn(element, i)
i.print
Thank you. Seems like a strange decision that it would be backwards compared to foreach-indexed for lists...
Ah yes, it would be good if the order of arguments was consistent. In particular, we have
fun foreach-indexed( xs : list<a>, action : (int, a) -> e types/() ) : e types/()
fun foreach-indexed( v : vector<a>, f : (a, int) -> e types/() ) : e types/()
So the order of arguments for f
/action
is currently inconsistent.
Thanks for spotting this -- fixed by passing the index first.
Creating the simplest version of the error I am dealing with, if I run the following:
I get as output:
Not sure what I am doing wrong here, or if there is an error in the implementation of
foreach-indexed
but the value ofi
doesn't seem to change.