given an array
is there a way to get a list/array/sequence/whatever of each value and its associated index? Similar to .items()
in python or Object.fromEntries()
(or even just map
) in js?
Are you talking about array
from the math
library, or the actual “array” for Racket which is called vector
?
from the math
library
(used in a for-loop)
ah, yes, I think that could work
I actually think I tried searching that too, but searched in-array-indicies
I use indices too. According to https://www.nasdaq.com/articles/indexes-or-indices-whats-the-deal-2016-05-12 it’s even the “mathematical” spelling.
It would be nice if the elements in in-array
and in-array-indexes
match. They probably do.
There’s in-indexed
which works with any sequence
not with array
it would seem #+begin_src racket
<<racket/my-imports>>
(define board (list*->matrix '((water water water water)
(water water land water)
(land land land water)
(water land water water)
(land land water water))))
(~> board
in-indexed
sequence->list)
#+end_src
#+RESULTS:
: in-indexed: contract violation
: expected: sequence?
: given: (array #[#['water 'water 'water 'water] #['water 'water 'land 'water] #['land 'land 'land 'water] #['water 'land 'water 'water] #['land 'land 'water 'water]])
: context...:
: /tmp/ob-racket-wqzp30/ob-racketcNUWZZrkt:22:4
: body of "/tmp/ob-racket-wqzp30/ob-racketcNUWZZrkt"
it’s meant for 1d sequences