Assoc¶
Name | Mandatory | Description | Default | Type |
---|---|---|---|---|
⬅️ Input |
Input sequence that defines which element in the target sequence or table needs to be updated and with what value. Should have even number of elements. | [Any] |
||
Output ➡️ |
Modified array or table. Has the same type as the array or table on which Assoc was applied. | [Any] |
||
Name |
No | The name of the sequence or table to be updated. | `` | String Var(Any) |
Key |
No | Table key for the value that is to be updated. Parameter applicable if target is table. | none |
Any |
Global |
No | If the variable is or should be available to all the wires in the same mesh. The default value (false) makes the variable local to the wire. | false |
Bool |
Updates a sequence or a table based on the input sequence.
Details¶
The input sequence should contain pairs of elements. The first value in each pair specifies the index or key to update, and the second value in the pair provides the new value for the earlier index/key.
For example, [0 1]
will update the value at index 0 in the sequence to 1. Similarly, ["firstkey" 1]
will update key "firstkey" in the table with the value of 1. When using Assoc
to update the values of a table, if the key specified in the input sequence does not exist, it will add it as a new key.
Examples¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
[info] [sample-wire] [10 20]
[info] [sample-wire] [2 3]
[info] [sample-wire] {key1: [10 20] key2: [30 40]}
[info] [sample-wire] {key1: [2 3] key2: [30 40]}
[info] [sample-wire] {key1: [10 20] key2: [30 40]}
[info] [sample-wire] {key1: [10 20] key2: [2 3]}