list_diff 1.1.3 copy "list_diff: ^1.1.3" to clipboard
list_diff: ^1.1.3 copied to clipboard

outdated

📃 Calculates a minimal list of operations that convert one list into another if applied in order.

example/main.dart

import 'package:list_diff/list_diff.dart';

void main() async {
  //var nutMix = ['coconut', 'nut', 'peanut'];
  //var tropic = ['kiwi', 'coconut', 'maracuja', 'nut', 'banana'];
  var nutMix = [1, 2, 3];
  var tropic = [1, 2, 3];

  // Now, let's turn the nut mix into the tropical mix.
  var recipe = await diff(nutMix, tropic);

  // Let's try it out!
  var bowl = List<int>.from(nutMix);
  print(bowl);

  for (var operation in recipe) {
    operation.applyTo(bowl);
    print('$operation\n$bowl');
  }

  // Output:
  // [coconut, nut, peanut]
  // Insertion of kiwi at 0.
  // [kiwi, coconut, nut, peanut]
  // Insertion of maracuja at 2.
  // [kiwi, coconut, maracuja, nut, peanut]
  // Insertion of banana at 4.
  // [kiwi, coconut, maracuja, nut, banana, peanut]
  // Deletion of peanut at 5.
  // [kiwi, coconut, maracuja, nut, banana]
}
11
likes
0
pub points
76%
popularity

Publisher

unverified uploader

📃 Calculates a minimal list of operations that convert one list into another if applied in order.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

async

More

Packages that depend on list_diff