{
"id": "fn-array-assoc",
"dataComponent": "array",
"heading": {
"title": "assoc",
"badges": ["Array", "PARTIAL"]
},
"synopsis": "Sets or updates a key-value pair in a keyed array, returning a new keyed array. Supports placeholders for key, value, or object.",
"codeBlocks": [
"extend(\"array\")\\n\\nkeyed = [ name:\"Alice\" ]\\nsput( array:assoc(\"city\", \"London\", keyed) )\\n// => [ name:\"Alice\", city:\"London\" ]\\n\\n# Partial usage\\nsetter = array:assoc(\"color\", \"blue\")\\nsput( setter(keyed) )\\n// => [ name:\"Alice\", color:\"blue\" ]\\n\\n# Placeholder usage\\nbananaSetter = array:assoc(_, \"banana\", keyed)\\nsput( bananaSetter(\"fruit\") )\\n// => [ name:\"Alice\", fruit:\"banana\" ]"
],
"notes": [
"Expects (key, value, object). The object must be a KeyedArray. The key must be a single string. If the key already exists, its value is replaced.",
"If you only supply (key, value), it returns a partial function waiting for the object. If you skip any of them with `_`, it returns a partial needing more calls.",
"Raises an error if the object is not keyed or if the key is invalid."
]
}