Details and Options
The rules must be of the form lhs→rhs or lhs⧴rhs.
A list of rules can be given. The rules are tried in order. The result of the first one that applies is returned. If none of the rules apply, the original assoc is returned.
Delayed rules defined with ⧴ can contain /; conditions.
KeyReplace uses standard level specifications:
n | levels 1 through n |
Infinity | levels 1 through Infinity |
All | all levels, including zero |
{n} | level n only |
{n1,n2} | levels n1 through n2 |
The default value for levelspec in KeyReplace is {0}, corresponding to the whole expression.
A positive level n consists of all parts of assoc specified by n indices.
A negative level -n consists of all parts of assoc with depth n.
Level -1 consists of numbers, symbols and other objects that do not have subparts.
If levelspec includes multiple levels, expressions at deeper levels in a given subexpression are matched first.
With the option setting
Heads→True,
KeyReplace includes heads of expressions and their parts.
Replacements are performed to parts specified by
levelspec even when those parts have
Hold or related wrappers.
KeyReplace[rules][expr] is equivalent to KeyReplace[expr,rules].