upsert method
dynamic
upsert(
- dynamic insertIdx,
- dynamic val, [
- UpsertFn? fn
])
Implementation
upsert(insertIdx, val, [UpsertFn? fn]) {
_magnitude = 0;
int position = positionForIndex(insertIdx);
if (elements.length > position && elements[position] == insertIdx) {
if (fn == null) {
throw Exception('fn required for this scenario');
}
elements[position + 1] = fn(elements[position + 1], val);
} else {
//elements.splice(position, 0, insertIdx, val);
elements.insertAll(position, [insertIdx, val]);
}
}