Before setting the new value, get the previous one to deindex it. Then
        call the command and index the new value, if exists
160774
def _call_lset(self, command, index, value, *args, **kwargs):
        
        if self.indexable:
            old_value = self.lindex(index)
            self.deindex([old_value])
        result = self._traverse_command(command, index, value, *args, **kwargs)
        if self.indexable:
            self.index([value])
        return result
1190716
public V putIfNew(K key, V value)
  {
    V oldValue = compareAndPut(null, key, value, true);

    if (oldValue != null)
      return oldValue;
    else
      return value;
  }
336855
def update_property(self, name, old_value, new_value):
        # type: (str, Any, Any) -> None
        
        with self._lock:
            self.__safe_handlers_callback(
                "on_property_change", name, old_value, new_value
            )
482838
def _del(self, command, *args, **kwargs):
        
        if self.indexable:
            self.deindex()
        return self._traverse_command(command, *args, **kwargs)
144052
private V setValueInsideWriteLock(V newValue) {
		CachedValue<V> cached = cachedValue; // read the cached value
		V oldValue = cached != null ? cached.value : null;

		if (newValue != null) {
			long expiresAt = ttlInMs > 0 ? U.time() + ttlInMs : Long.MAX_VALUE;
			cachedValue = new CachedValue<>(newValue, expiresAt);

		} else {
			cachedValue = null;
		}

		return oldValue;
	}
1191472
function(compute, newValue, oldValue, batchNum) {
            // Only trigger event when value has changed
            if (newValue !== oldValue) {
                can.batch.trigger(compute, batchNum ? {
                        type: "change",
                        batchNum: batchNum
                    } : 'change', [
                        newValue,
                        oldValue
                    ]);
            }
        }
580490
def updateCurrentValue(self, value):
        
        xsnap = None
        ysnap = None
        
        if value != self.endValue():
            xsnap = self.targetObject().isXSnappedToGrid()
            ysnap = self.targetObject().isYSnappedToGrid()
            
            self.targetObject().setXSnapToGrid(False)
            self.targetObject().setYSnapToGrid(False)
        
        super(XNodeAnimation, self).updateCurrentValue(value)
        
        if value != self.endValue():
            self.targetObject().setXSnapToGrid(xsnap)
            self.targetObject().setYSnapToGrid(ysnap)
859285
def update(self, value):
        

        value = int(value)

        with self.lock:
            self.value += value
1187595
def use(self, key, value):
        
        old_value = self[key]
        try:
            self[key] = value
            yield self
        finally:
            self[key] = old_value
251931
function() {
    var value = this.get();

    // Don't call the callback if `skipNextSync` was called on the observer
    if (this.skip || !this.callback) {
      this.skip = false;

      if (this.getChangeRecords) {
        // Store an immutable version of the value, allowing for arrays and objects to change instance but not content and
        // still refrain from dispatching callbacks (e.g. when using an object in bind-class or when using array formatters
        // in bind-each)
        this.oldValue = diff.clone(value);
      } else {
        this.oldValue = value;
      }
    } else {
      var change;
      var useCompareBy = this.getChangeRecords &&
                         this.compareBy &&
                         Array.isArray(value) &&
                         Array.isArray(this.oldValue);

      if (useCompareBy) {
        var compareExpression = this.compareBy;
        var name = this.compareByName;
        var index = this.compareByIndex || '__index__';
        var ctx = this.context;
        var globals = this.observations.globals;
        var formatters = this.observations.formatters;
        var oldValue = this.oldValue;
        if (!name) {
          name = '__item__';
          // Turn "id" into "__item__.id"
          compareExpression = name + '.' + compareExpression;
        }

        var getCompareValue = expressions.parse(compareExpression, globals, formatters, name, index);
        changed = diff.values(value.map(getCompareValue, ctx), oldValue.map(getCompareValue, ctx));
      } else if (this.getChangeRecords) {
        changed = diff.values(value, this.oldValue);
      } else {
        changed = diff.basic(value, this.oldValue);
      }

      var oldValue = this.oldValue;

      if (this.getChangeRecords) {
        // Store an immutable version of the value, allowing for arrays and objects to change instance but not content and
        // still refrain from dispatching callbacks (e.g. when using an object in bind-class or when using array formatters
        // in bind-each)
        this.oldValue = diff.clone(value);
      } else {
        this.oldValue = value;
      }

      // If an array has changed calculate the splices and call the callback.
      if (!changed && !this.forceUpdateNextSync) return;
      this.forceUpdateNextSync = false;
      if (Array.isArray(changed)) {
        this.callback.call(this.callbackContext, value, oldValue, changed);
      } else {
        this.callback.call(this.callbackContext, value, oldValue);
      }
    }
  }
1263102
protected void setValue(int newPosition, T1 valueSum, long valueN,
      boolean currentExisting) {
    if (valueN > 0) {
      if (currentExisting) {
        newBasicValueSumList[newPosition] = operations
            .add11(newBasicValueSumList[newPosition], valueSum);
        newBasicValueNList[newPosition] += valueN;
      } else {
        newBasicValueSumList[newPosition] = valueSum;
        newBasicValueNList[newPosition] = valueN;
      }
    }
  }
199479
function(key, oldval, value) {
    if (store._changed_keys.indexOf(key) === -1) {
      store._changed_keys.push(key)
    }

    // suppress active timeout (if any)
    if (store._debounce_timeout) {
      store._clearDebounceTimeout()
    }

    if (store.options.debounce_ms) {
      // delay event emission and set new timeout id
      store._debounce_timeout = setTimeout(store._publish, store.options.debounce_ms)
    } else {
      // publish immediately
      store._publish()
    }
  }
384220
def update(self, value=None):
        ''

        if value is not None and value is not UnknownLength:
            if (self.maxval is not UnknownLength
                and not 0 <= value <= self.maxval):

                raise ValueError('Value out of range')

            self.currval = value


        if not self._need_update(): return
        if self.start_time is None:
            raise RuntimeError('You must call "start" before calling "update"')

        now = time.time()
        self.seconds_elapsed = now - self.start_time
        self.next_update = self.currval + self.update_interval
        self.fd.write(self._format_line() + '\r')
        self.last_update_time = now
1243938
def present_value_changed(self, old_value, new_value):
        """"""
        if _debug: LocalScheduleInterpreter._debug("present_value_changed %s %s", old_value, new_value)

        # if this hasn't been added to an application, there's nothing to do
        if not self.sched_obj._app:
            if _debug: LocalScheduleInterpreter._debug("    - no application")
            return

        # process the list of [device] object property [array index] references
        obj_prop_refs = self.sched_obj.listOfObjectPropertyReferences
        if not obj_prop_refs:
            if _debug: LocalScheduleInterpreter._debug("    - no writes defined")
            return

        # primitive values just set the value part
        new_value = new_value.value

        # loop through the writes
        for obj_prop_ref in obj_prop_refs:
            if obj_prop_ref.deviceIdentifier:
                if _debug: LocalScheduleInterpreter._debug("    - no externals")
                continue

            # get the object from the application
            obj = self.sched_obj._app.get_object_id(obj_prop_ref.objectIdentifier)
            if not obj:
                if _debug: LocalScheduleInterpreter._debug("    - no object")
                continue

            # try to change the value
            try:
                obj.WriteProperty(
                    obj_prop_ref.propertyIdentifier,
                    new_value,
                    arrayIndex=obj_prop_ref.propertyArrayIndex,
                    priority=self.sched_obj.priorityForWriting,
                    )
                if _debug: LocalScheduleInterpreter._debug("    - success")
            except Exception as err:
                if _debug: LocalScheduleInterpreter._debug("    - error: %r", err)
449005
def _pfp__set_value(self, new_val):
        
        if self._pfp__frozen:
            raise errors.UnmodifiableConst()
        self._pfp__value = self._pfp__get_root_value(new_val)
        self._pfp__notify_parent()
969139
private void updateScalarReplaceValue(String currentValue, String newValue) {
        m_dbTran.addScalarValueColumn(m_tableDef, m_dbObj.getObjectID(), m_fieldName, newValue);
        Set<String> currTermSet = tokenize(Utils.isEmpty(currentValue) ? "" : currentValue);
        Set<String> newTermSet = tokenize(newValue);
        for (String term : currTermSet) {
            if (!newTermSet.remove(term)) {
                unindexTerm(term);
            }
        }
        indexTerms(newTermSet);
        addFieldTermReferences(newTermSet);
        if (Utils.isEmpty(currentValue)) {
            addFieldReference();
        }
    }
1148744
def new_value(self, key, value):
        """"""
        data = self.model.get_data()
        data[key] = value
        self.set_data(data)