0
votes

I have a hashmap of data with the key a string description and value an integer weight.

{:a 2 :b 3 ......}

I need to transform the hash into a vector of vectors. Each internal vector contains the map entries.

[[[:a 2][:b 3]...][......]]

each internal vector is built based upon some rules. Ex the sum of all weights should not exceed a certain value

Normally this seems to be a good case for a reduce where a hash is transformed into a vector of vectors of map entries. However I may need to iterate over the hash more than once as I may need to reshuffle the entries between the internal vectors so that all of the vectors sum up to a certain num.

Any suggestions on how the problem should me modelled?

1

1 Answers

0
votes

Well, for starters, Clojure maps are already sequences of vectors. So no reduce needed:

=> (for [e {:a 1 :b 2}] e)
([:a 1] [:b 2])

Instead of thinking of it as "iterating," you should take the approach of defining a function that takes your input vectors and returns a new sequence with the adjustment. Recursively call this function until the sum you need is reached.