Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure: Getting single value and map in structmap

I have a sequence of values that I get from somewhere else, in a known order. I also have one separate value. Both of these I want to put into a struct. I.e.

(defstruct location :name :id :type :visited)

Now I have a list

(list "Name" "Id" "Type")

that is the result of a regexp.

Then I want to put a boolean in :visited; yielding a struct that looks like this:

{:name "Name" :id "Id" :type "Type" :visited true}

How do I do this? I tried various combinations of apply and struct-map. I got as far as:

(apply struct-map location (zipmap [:visited :name :id :type] (cons true (rest match))))

but that may be the wrong way to go about it altogether.

like image 675
Kurt Schelfthout Avatar asked Feb 13 '26 07:02

Kurt Schelfthout


1 Answers

How about:

(def l (list "Name" "Id" "Type"))
(defstruct location :name :id :type :visited)
(assoc
   (apply struct location l)
   :visited true)
like image 63
Arthur Edelstein Avatar answered Feb 14 '26 21:02

Arthur Edelstein



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!