overrideIfPresent method

V? overrideIfPresent(
  1. K key,
  2. V ifPresent()
)

Replaces the value associated with a key if it exists

Example :

Channel channel = Channel.from({...});
guild.channels.cache.overrideIfPresent(channel.id, () => channel);

Implementation

V? overrideIfPresent (K key, V Function() ifPresent) {
  if (this[key] != null) this[key] = ifPresent();
  return this[key];
}