Reputation: 6509
I want to return a list of arguments from a function and have them put straight into a hash-map. I'm using a vector to enclose these arguments, working under the assumption that only one value can be returned from a Clojure function. So on the return part of the call I am wanting to strip away the vector.
This is what the function is successfully returning:
[:top-edge {3 [[0 0]]}]
As you can see if you strip away the vector you get something that should be able to be placed straight into a hash-map (because it has a key and a value):
:top-edge {3 [[0 0]]}
I have experimented with apply
and flatten
, and know that in some circumstances concat
can be used for stripping away the outermost vector, but still have not found a solution.
For the moment I have left the code so it is not stripping away the vector, and the error message makes perfect sense: java.lang.IllegalArgumentException: No value supplied for key: [:top-edge {3 [[0 0]]}]
Edit: Question already answered, but just to show the actual code and what does and does not work. This does work:
(conj {:rep (->Blob rgb pos)} (new-edge-map pos edge-keyword seg-id))
, and this does not:
{:rep (->Blob rgb pos) (apply hash-map (new-edge-map pos edge-keyword seg-id))}
The error I get is 'Map literal must contain an even number of forms'.
Upvotes: 2
Views: 237
Reputation: 13069
From the documentation of hash-map
:
Returns a new hash map with supplied mappings. If any keys are
equal, they are handled as if by repeated uses of assoc.
So,
(apply hash-map [:top-edge {3 [[0 0]]}])
=> {:top-edge {3 [[0 0]]}}
Upvotes: 0