{"id":18048801,"url":"https://github.com/marcelgarus/list_diff","last_synced_at":"2025-04-10T09:53:03.552Z","repository":{"id":56834017,"uuid":"213789038","full_name":"MarcelGarus/list_diff","owner":"MarcelGarus","description":"📃 Calculates a minimal list of operations that convert one list into another if applied in order.","archived":false,"fork":false,"pushed_at":"2022-01-07T17:41:54.000Z","size":117,"stargazers_count":11,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T08:47:51.694Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MarcelGarus.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-09T01:08:20.000Z","updated_at":"2024-11-01T03:14:34.000Z","dependencies_parsed_at":"2022-09-10T04:14:07.637Z","dependency_job_id":null,"html_url":"https://github.com/MarcelGarus/list_diff","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcelGarus%2Flist_diff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcelGarus%2Flist_diff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcelGarus%2Flist_diff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarcelGarus%2Flist_diff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MarcelGarus","download_url":"https://codeload.github.com/MarcelGarus/list_diff/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248198225,"owners_count":21063626,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-30T20:15:26.370Z","updated_at":"2025-04-10T09:53:03.515Z","avatar_url":"https://github.com/MarcelGarus.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"Offers a `diff` method that accepts two `List`s and returns a list of\n`Operation`s for turning the first list into the second one:\n\n```dart\nvar operations = await diff(\n  ['coconut', 'nut', 'peanut'],\n  ['kiwi', 'coconut', 'maracuja', 'nut', 'banana'],\n);\noperations.forEach(print);\n\n// Operations:\n// Insertion of kiwi at 0.\n// Insertion of maracuja at 2.\n// Insertion of banana at 4.\n// Deletion of peanut at 5.\n```\n\n`Operation`s are either an insertion or deletion of an item at an index. You\ncan also directly apply them to a list:\n\n```dart\n// Let's try it out!\nvar fruitBowl = ['coconut', 'nut', 'peanut'];\n\nfor (var operation in operations) {\n  fruitBowl.apply(operation);\n}\n\n// Transforming:\n// [coconut, nut, peanut]\n// [kiwi, coconut, nut, peanut]\n// [kiwi, coconut, maracuja, nut, peanut]\n// [kiwi, coconut, maracuja, nut, banana, peanut]\n// [kiwi, coconut, maracuja, nut, banana]\n```\n\nThe lists' items are compared using their `==` operator and `hashCode` by default.\nBut you can specify a custom comparison method and hash code:\n\n```dart\nvar operations = await diff(\n  first,\n  second,\n  areEqual: (a, b) =\u003e ...,\n  getHashCode: (a) =\u003e ...,\n);\n```\n\n### A word about performance and threading\n\nI'm not sure the current version is as performant as it could be.\nThe runtime is currently O(N*M), where N and M are the lengths of the lists.\nIf you know a better algorithm, feel welcome to open an issue or file a pull request.\n\nIf the data sets are large, the `diff` function automatically spawns an\nisolate. If you want more control on whether an isolate should be\nspawned, you can also explicitly set the `spawnIsolate` parameter:\n\n```dart\nvar operations = await diff(first, second, spawnIsolate: true);\n```\n\n### For Flutter users\n\n`diff` can be used to calculate updates for an `AnimatedList`.\nThe [implicitly_animated_list](https://pub.dev/packages/implicitly_animated_list) package does that for you.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcelgarus%2Flist_diff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcelgarus%2Flist_diff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcelgarus%2Flist_diff/lists"}