Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8404681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:39:39+00:00 2026-06-09T22:39:39+00:00

I have a datatype defined with defrecord, which contains two vectors: (defrecord MyType [a

  • 0

I have a datatype defined with defrecord, which contains two vectors:

(defrecord MyType [a b])

(def mytype (->MyType [1 2 3] [4 5 6]))

I want to have a function update both vectors and return a new MyType. The only way I can think of to do that is via nested assoc calls:

(defn mutate-mytype [mytype x y]
  (assoc mytype :a (assoc (:a mytype) x y)
                :b (assoc (:b mytype) x y)))

Example output:

user=> (mutate-mytype mytype 1 7)
#user.MyType{:a [1 7 3], :b [4 7 6]}

Question: Is there a better way to write that mutate-mytype method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:39:40+00:00Added an answer on June 9, 2026 at 10:39 pm

    Your implementation is perfectly fine.

    There are a few alternatives, e.g. you might consider using assoc-in and the -> threading operator:

    (defn mutate-mytype [mytype x y]
      (-> mytype 
          (assoc-in [:a x] y)
          (assoc-in [:b x] y)))
    

    This doesn’t really have any advantages over your approach in this case, but it might make the code more readable if you had more deep nesting going on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have address table in which city field have nvarchar datatype, but I want
I have this function which returns a datatype InetAddress[] public InetAddress [] lookupAllHostAddr(String host)
I have a DATE datatype mysql column in a table. I want to set
I have some function where I need to pass a point datatype . somefunc(United
I have this field from the database which is: DataType: Numeric (7, 3) So
Windows SDK features IsEqualGUID() function and operator==() for two GUIDs that return BOOL (equivalent
I have defined a generic tree-node class like this: template<class DataType> class GenericNode {
I have the following grid defined: $(#list).jqGrid({ url:'listOpenQueryInXML.php', datatype: 'xml', colNames:['Id','name1', 'name2', 'status', 'type'],
I have my ViewModel on which I've defined my properties; one of them is
Suppose I have a Vector datatype defined as follows: data Vector = Vector {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.