0
$\begingroup$

I want to write a pure function to change the key's value of an association, it must return the new association, so it can be mapped to a table of associations.

The AssociateTo can change key's value of an association, but it seems not working. I don't know why, perhaps because it is not a pure function?

AssociateTo

So if I have a pure function doing the same thing, this job can be done very well.

Can you help me? Thanks!

$\endgroup$
4
  • 2
    $\begingroup$ Use Append. AssociateTo is for changing the value of a variable. You have no variables. $\endgroup$ Commented Mar 2, 2017 at 8:07
  • 1
    $\begingroup$ In general case Merge[Last], in even more general case 102466, but here, in addition to what Szabolcs said, you can <|#, "key"->value|>&/@data $\endgroup$ Commented Mar 2, 2017 at 8:13
  • $\begingroup$ Thank you. <|#, "key"->value|> works well. $\endgroup$ Commented Mar 2, 2017 at 8:15
  • $\begingroup$ closely related: 74165, 137455 $\endgroup$ Commented Mar 2, 2017 at 8:29

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.