Clojure

Allow map-indexed to accept multiple collections (a la map)

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Trivial Trivial
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code and Test

Description

Bring external interface of map-indexed in line with map. Existing usages of map-indexed unchanged both in implementation and interface.

examples
(map vector (range 10 20) (range 30 35)) ;=> ([10 30] [11 31] [12 32] [13 33] [14 34])
(map-indexed vector (range 10 20) (range 30 35)) ;=> ([0 10 30] [1 11 31] [2 12 32] [3 13 33] [4 14 34])

The attached patch is not necessarily the best implementation (I haven't benchmarked it or tried any alternatives yet) but hopefully enough to start a conversation about whether this is an addition that is warranted. I know I wished for this behavior a few weeks ago though I ended up finding another way.

(I haven't sent my CA yet, but I have it signed and ready to send in the next few days)

Activity

Hide
Aaron Bedra added a comment -

Can you add a test for the improved functionality?

Show
Aaron Bedra added a comment - Can you add a test for the improved functionality?
Hide
Bo Jeanes added a comment -

You bet. I tried to before submitting this but found no existing tests for map-indexed to expand upon. Given that, I decided to just start the conversation first. If you think this is a good addition, I'll find a place to stick the tests and add a new patch file.

Show
Bo Jeanes added a comment - You bet. I tried to before submitting this but found no existing tests for map-indexed to expand upon. Given that, I decided to just start the conversation first. If you think this is a good addition, I'll find a place to stick the tests and add a new patch file.
Hide
Bo Jeanes added a comment -

Add two unit tests for map-indexed. One tests old behavior (single collection) and the second tests mapping across 3 collections.

There were no existing tests for map-indexed that I could see to expand upon (using git grep map-indexed src/clojure)

Show
Bo Jeanes added a comment - Add two unit tests for map-indexed. One tests old behavior (single collection) and the second tests mapping across 3 collections. There were no existing tests for map-indexed that I could see to expand upon (using git grep map-indexed src/clojure)
Bo Jeanes made changes -
Field Original Value New Value
Attachment 0002-Add-test-for-multi-collection-map-indexed-fn.patch [ 11616 ]
Andy Fingerhut made changes -
Patch Code and Test [ 10002 ]

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated: