replace_if_exists function:

  • Can also be called as insert_if_exists

  • Can also be called as put_if_exists

  • Can also be called as {+}

Add a new entry to a map if it has such key. The first argument should be an object. The second argument should be a key. The third argument should be a value. If the object dosen't has that key, it will not be replaced.

Examples:

  • running: (replace_if_exists {}, "a", 1) will give: {} Because The object has no value for key a.

  • running: (replace_if_exists {"a": 10, "b": 22}, "a", -1) will give: {"a": -1, "b": 22}

  • running: (replace_if_exists [], "a", 1) will return nothing

  • running: (replace_if_exists {}, 1, 1) will return nothing

  • running: (replace_if_exists {}, "1", ({} {} 1 1)) will return nothing