Skip to content

Instantly share code, notes, and snippets.

Last active July 26, 2022 15:49
What would you like to do?
extension PutListX<E> on List<E> {
List<E> putAllBy<K>(Iterable<E> other, K onKey(E item), [void onAdd(E item)?]) {
final Map<K, E> otherMap = other.associateBy<K>((it) => onKey(it));
for (final i in indices) {
final key = onKey(this[i]);
if (otherMap.containsKey(key)) {
this[i] = otherMap.remove(key) as E;
otherMap.forEach((key, value) {
return this;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment