diff --git a/app/lib/account.dart b/app/lib/account.dart index 3f22a5be..bbb63c64 100644 --- a/app/lib/account.dart +++ b/app/lib/account.dart @@ -5,8 +5,8 @@ import 'package:copy_with/copy_with.dart'; import 'package:equatable/equatable.dart'; import 'package:flutter/foundation.dart'; import 'package:logging/logging.dart'; -import 'package:nc_photos/iterable_extension.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:np_common/type.dart'; import 'package:np_string/np_string.dart'; import 'package:to_string/to_string.dart'; diff --git a/app/lib/bloc/home_search_suggestion.dart b/app/lib/bloc/home_search_suggestion.dart index da9d22de..7af230bc 100644 --- a/app/lib/bloc/home_search_suggestion.dart +++ b/app/lib/bloc/home_search_suggestion.dart @@ -11,12 +11,12 @@ import 'package:nc_photos/di_container.dart'; import 'package:nc_photos/entity/collection.dart'; import 'package:nc_photos/entity/person.dart'; import 'package:nc_photos/entity/tag.dart'; -import 'package:nc_photos/iterable_extension.dart'; import 'package:nc_photos/use_case/collection/list_collection.dart'; import 'package:nc_photos/use_case/list_location_group.dart'; import 'package:nc_photos/use_case/list_tag.dart'; import 'package:nc_photos/use_case/person/list_person.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:np_string/np_string.dart'; import 'package:to_string/to_string.dart'; import 'package:tuple/tuple.dart'; diff --git a/app/lib/bloc/list_album_share_outlier.dart b/app/lib/bloc/list_album_share_outlier.dart index 1452e8b8..efaf26d1 100644 --- a/app/lib/bloc/list_album_share_outlier.dart +++ b/app/lib/bloc/list_album_share_outlier.dart @@ -10,11 +10,11 @@ import 'package:nc_photos/entity/album/item.dart'; import 'package:nc_photos/entity/album/provider.dart'; import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/share.dart'; -import 'package:nc_photos/iterable_extension.dart'; import 'package:nc_photos/object_extension.dart'; import 'package:nc_photos/use_case/list_share.dart'; import 'package:nc_photos/use_case/list_sharee.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:np_string/np_string.dart'; import 'package:to_string/to_string.dart'; diff --git a/app/lib/bloc/list_importable_album.dart b/app/lib/bloc/list_importable_album.dart index 9a78c0d6..73dc6a76 100644 --- a/app/lib/bloc/list_importable_album.dart +++ b/app/lib/bloc/list_importable_album.dart @@ -8,11 +8,11 @@ import 'package:nc_photos/entity/album.dart'; import 'package:nc_photos/entity/album/provider.dart'; import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/file_util.dart' as file_util; -import 'package:nc_photos/iterable_extension.dart'; import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util; import 'package:nc_photos/use_case/album/list_album.dart'; import 'package:nc_photos/use_case/ls.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:to_string/to_string.dart'; part 'list_importable_album.g.dart'; diff --git a/app/lib/bloc/list_sharing.dart b/app/lib/bloc/list_sharing.dart index 81211592..80a75217 100644 --- a/app/lib/bloc/list_sharing.dart +++ b/app/lib/bloc/list_sharing.dart @@ -11,7 +11,6 @@ import 'package:nc_photos/entity/file_descriptor.dart'; import 'package:nc_photos/entity/file_util.dart' as file_util; import 'package:nc_photos/entity/share.dart'; import 'package:nc_photos/event/event.dart'; -import 'package:nc_photos/iterable_extension.dart'; import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util; import 'package:nc_photos/throttler.dart'; import 'package:nc_photos/use_case/find_file.dart'; @@ -19,6 +18,7 @@ import 'package:nc_photos/use_case/list_share_with_me.dart'; import 'package:nc_photos/use_case/ls.dart'; import 'package:nc_photos/use_case/ls_single_file.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:path/path.dart' as path_lib; import 'package:to_string/to_string.dart'; diff --git a/app/lib/bloc/scan_local_dir.dart b/app/lib/bloc/scan_local_dir.dart index 15eb7291..efbab194 100644 --- a/app/lib/bloc/scan_local_dir.dart +++ b/app/lib/bloc/scan_local_dir.dart @@ -5,9 +5,9 @@ import 'package:logging/logging.dart'; import 'package:nc_photos/di_container.dart'; import 'package:nc_photos/entity/local_file.dart'; import 'package:nc_photos/event/event.dart'; -import 'package:nc_photos/iterable_extension.dart'; import 'package:nc_photos/use_case/scan_local_dir.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:to_string/to_string.dart'; part 'scan_local_dir.g.dart'; diff --git a/app/lib/bloc/search_suggestion.dart b/app/lib/bloc/search_suggestion.dart index 8b94c533..b744d93c 100644 --- a/app/lib/bloc/search_suggestion.dart +++ b/app/lib/bloc/search_suggestion.dart @@ -2,8 +2,8 @@ import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:logging/logging.dart'; -import 'package:nc_photos/iterable_extension.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:np_string/np_string.dart'; import 'package:to_string/to_string.dart'; import 'package:tuple/tuple.dart'; diff --git a/app/lib/controller/collection_items_controller.dart b/app/lib/controller/collection_items_controller.dart index 08075be5..1c2a869a 100644 --- a/app/lib/controller/collection_items_controller.dart +++ b/app/lib/controller/collection_items_controller.dart @@ -15,7 +15,6 @@ import 'package:nc_photos/entity/collection_item/new_item.dart'; import 'package:nc_photos/entity/file_descriptor.dart'; import 'package:nc_photos/event/event.dart'; import 'package:nc_photos/exception_event.dart'; -import 'package:nc_photos/list_extension.dart'; import 'package:nc_photos/object_extension.dart'; import 'package:nc_photos/rx_extension.dart'; import 'package:nc_photos/use_case/collection/add_file_to_collection.dart'; @@ -24,6 +23,7 @@ import 'package:nc_photos/use_case/collection/remove_from_collection.dart'; import 'package:nc_photos/use_case/collection/update_collection_post_load.dart'; import 'package:nc_photos/use_case/remove.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:rxdart/rxdart.dart'; part 'collection_items_controller.g.dart'; diff --git a/app/lib/entity/album.dart b/app/lib/entity/album.dart index 54b6e411..01282a69 100644 --- a/app/lib/entity/album.dart +++ b/app/lib/entity/album.dart @@ -7,9 +7,9 @@ import 'package:nc_photos/entity/album/provider.dart'; import 'package:nc_photos/entity/album/sort_provider.dart'; import 'package:nc_photos/entity/album/upgrader.dart'; import 'package:nc_photos/entity/file.dart'; -import 'package:nc_photos/iterable_extension.dart'; import 'package:nc_photos/object_extension.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:np_common/or_null.dart'; import 'package:np_common/type.dart'; import 'package:np_string/np_string.dart'; diff --git a/app/lib/entity/album/data_source.dart b/app/lib/entity/album/data_source.dart index 94e93f07..9adb19d2 100644 --- a/app/lib/entity/album/data_source.dart +++ b/app/lib/entity/album/data_source.dart @@ -9,8 +9,8 @@ import 'package:nc_photos/entity/file_descriptor.dart'; import 'package:nc_photos/entity/sqlite/database.dart' as sql; import 'package:nc_photos/exception.dart'; import 'package:nc_photos/exception_event.dart'; -import 'package:nc_photos/iterable_extension.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; part 'data_source.g.dart'; diff --git a/app/lib/entity/album/provider.dart b/app/lib/entity/album/provider.dart index 2cdd3e46..07415761 100644 --- a/app/lib/entity/album/provider.dart +++ b/app/lib/entity/album/provider.dart @@ -7,8 +7,8 @@ import 'package:nc_photos/entity/album.dart'; import 'package:nc_photos/entity/album/item.dart'; import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/tag.dart'; -import 'package:nc_photos/iterable_extension.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:np_common/or_null.dart'; import 'package:np_common/type.dart'; import 'package:to_string/to_string.dart'; diff --git a/app/lib/entity/collection/adapter/album.dart b/app/lib/entity/collection/adapter/album.dart index a768d8de..7953bbda 100644 --- a/app/lib/entity/collection/adapter/album.dart +++ b/app/lib/entity/collection/adapter/album.dart @@ -19,7 +19,6 @@ import 'package:nc_photos/entity/collection_item/util.dart'; import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/file_descriptor.dart'; import 'package:nc_photos/entity/sharee.dart'; -import 'package:nc_photos/iterable_extension.dart'; import 'package:nc_photos/object_extension.dart'; import 'package:nc_photos/use_case/album/add_file_to_album.dart'; import 'package:nc_photos/use_case/album/edit_album.dart'; @@ -32,6 +31,7 @@ import 'package:nc_photos/use_case/preprocess_album.dart'; import 'package:nc_photos/use_case/unimport_shared_album.dart'; import 'package:nc_photos/use_case/update_album_with_actual_items.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:np_common/or_null.dart'; import 'package:np_common/type.dart'; import 'package:np_string/np_string.dart'; diff --git a/app/lib/entity/collection_item/sorter.dart b/app/lib/entity/collection_item/sorter.dart index 346d517a..56d3bf3a 100644 --- a/app/lib/entity/collection_item/sorter.dart +++ b/app/lib/entity/collection_item/sorter.dart @@ -4,8 +4,8 @@ import 'package:nc_photos/entity/album/sort_provider.dart'; import 'package:nc_photos/entity/collection_item.dart'; import 'package:nc_photos/entity/collection_item/util.dart'; import 'package:nc_photos/entity/file_descriptor.dart'; -import 'package:nc_photos/iterable_extension.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:tuple/tuple.dart'; part 'sorter.g.dart'; diff --git a/app/lib/entity/file/data_source.dart b/app/lib/entity/file/data_source.dart index 88c07a46..18e0f0af 100644 --- a/app/lib/entity/file/data_source.dart +++ b/app/lib/entity/file/data_source.dart @@ -14,12 +14,12 @@ import 'package:nc_photos/entity/file_util.dart' as file_util; import 'package:nc_photos/entity/sqlite/database.dart' as sql; import 'package:nc_photos/entity/sqlite/files_query_builder.dart' as sql; import 'package:nc_photos/exception.dart'; -import 'package:nc_photos/iterable_extension.dart'; import 'package:nc_photos/np_api_util.dart'; import 'package:nc_photos/object_extension.dart'; import 'package:nc_photos/use_case/compat/v32.dart'; import 'package:np_api/np_api.dart' as api; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:np_common/or_null.dart'; import 'package:path/path.dart' as path_lib; diff --git a/app/lib/entity/file/file_cache_manager.dart b/app/lib/entity/file/file_cache_manager.dart index a462dc53..fc9ea794 100644 --- a/app/lib/entity/file/file_cache_manager.dart +++ b/app/lib/entity/file/file_cache_manager.dart @@ -12,10 +12,9 @@ import 'package:nc_photos/entity/sqlite/database.dart' as sql; import 'package:nc_photos/entity/sqlite/files_query_builder.dart' as sql; import 'package:nc_photos/entity/sqlite/type_converter.dart'; import 'package:nc_photos/exception.dart'; -import 'package:nc_photos/iterable_extension.dart'; -import 'package:nc_photos/list_util.dart' as list_util; import 'package:nc_photos/object_extension.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; part 'file_cache_manager.g.dart'; @@ -136,7 +135,7 @@ class FileSqliteCacheUpdater { ..where((t) => t.dir.equals(_dirRowId!)) ..orderBy([(t) => sql.OrderingTerm.asc(t.rowId)]); final dirFiles = await dirFileQuery.get(); - final diff = list_util.diff(dirFiles.map((e) => e.child), + final diff = getDiff(dirFiles.map((e) => e.child), _childRowIds.sorted(Comparable.compare)); if (diff.onlyInB.isNotEmpty) { await db.batch((batch) { diff --git a/app/lib/entity/local_file/data_source.dart b/app/lib/entity/local_file/data_source.dart index 63dae0aa..ddd46dff 100644 --- a/app/lib/entity/local_file/data_source.dart +++ b/app/lib/entity/local_file/data_source.dart @@ -2,7 +2,6 @@ import 'package:collection/collection.dart'; import 'package:logging/logging.dart'; import 'package:nc_photos/entity/file_util.dart' as file_util; import 'package:nc_photos/entity/local_file.dart'; -import 'package:nc_photos/iterable_extension.dart'; import 'package:nc_photos/mobile/android/android_info.dart'; import 'package:nc_photos/mobile/android/k.dart' as android; import 'package:nc_photos/mobile/share.dart'; @@ -10,6 +9,7 @@ import 'package:nc_photos/object_extension.dart'; import 'package:nc_photos/stream_extension.dart'; import 'package:nc_photos_plugin/nc_photos_plugin.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; part 'data_source.g.dart'; diff --git a/app/lib/entity/nc_album/data_source.dart b/app/lib/entity/nc_album/data_source.dart index 1a1e48a9..337dc7e0 100644 --- a/app/lib/entity/nc_album/data_source.dart +++ b/app/lib/entity/nc_album/data_source.dart @@ -9,10 +9,10 @@ import 'package:nc_photos/entity/nc_album_item.dart'; import 'package:nc_photos/entity/sqlite/database.dart' as sql; import 'package:nc_photos/entity/sqlite/type_converter.dart'; import 'package:nc_photos/exception.dart'; -import 'package:nc_photos/list_util.dart' as list_util; import 'package:nc_photos/np_api_util.dart'; import 'package:np_api/np_api.dart' as api; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; part 'data_source.g.dart'; @@ -236,7 +236,7 @@ class NcAlbumSqliteDbDataSource implements NcAlbumCacheDataSource { final existingItems = await db.ncAlbumItemsByParent( parent: dbAlbum!, ); - final diff = list_util.diffWith( + final diff = getDiffWith( existingItems .map((e) => SqliteNcAlbumItemConverter.fromSql( account.userId.raw, album.strippedPath, e)) diff --git a/app/lib/entity/recognize_face/data_source.dart b/app/lib/entity/recognize_face/data_source.dart index 1960d55e..123c6b4c 100644 --- a/app/lib/entity/recognize_face/data_source.dart +++ b/app/lib/entity/recognize_face/data_source.dart @@ -9,11 +9,10 @@ import 'package:nc_photos/entity/sqlite/database.dart' as sql; import 'package:nc_photos/entity/sqlite/table.dart'; import 'package:nc_photos/entity/sqlite/type_converter.dart'; import 'package:nc_photos/exception.dart'; -import 'package:nc_photos/iterable_extension.dart'; -import 'package:nc_photos/map_extension.dart'; import 'package:nc_photos/np_api_util.dart'; import 'package:np_api/np_api.dart' as api; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:np_common/type.dart'; part 'data_source.g.dart'; diff --git a/app/lib/entity/search.dart b/app/lib/entity/search.dart index 2411c745..9e1b6935 100644 --- a/app/lib/entity/search.dart +++ b/app/lib/entity/search.dart @@ -2,7 +2,7 @@ import 'package:nc_photos/account.dart'; import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/file_util.dart' as file_util; import 'package:nc_photos/entity/sqlite/files_query_builder.dart' as sql; -import 'package:nc_photos/iterable_extension.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:to_string/to_string.dart'; part 'search.g.dart'; diff --git a/app/lib/entity/search/data_source.dart b/app/lib/entity/search/data_source.dart index 15e660b5..af245b22 100644 --- a/app/lib/entity/search/data_source.dart +++ b/app/lib/entity/search/data_source.dart @@ -10,12 +10,12 @@ import 'package:nc_photos/entity/search_util.dart' as search_util; import 'package:nc_photos/entity/sqlite/database.dart' as sql; import 'package:nc_photos/entity/sqlite/files_query_builder.dart' as sql; import 'package:nc_photos/entity/sqlite/type_converter.dart'; -import 'package:nc_photos/iterable_extension.dart'; import 'package:nc_photos/object_extension.dart'; import 'package:nc_photos/use_case/inflate_file_descriptor.dart'; import 'package:nc_photos/use_case/list_tagged_file.dart'; import 'package:nc_photos/use_case/person/list_person_face.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:np_string/np_string.dart'; part 'data_source.g.dart'; diff --git a/app/lib/entity/sqlite/database.dart b/app/lib/entity/sqlite/database.dart index 692a3161..06c7e85f 100644 --- a/app/lib/entity/sqlite/database.dart +++ b/app/lib/entity/sqlite/database.dart @@ -16,6 +16,7 @@ import 'package:nc_photos/mobile/platform.dart' import 'package:nc_photos/object_extension.dart'; import 'package:nc_photos/platform/k.dart' as platform_k; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; part 'database.g.dart'; part 'database/nc_album_extension.dart'; diff --git a/app/lib/entity/tagged_file/data_source.dart b/app/lib/entity/tagged_file/data_source.dart index e016290d..9954a51a 100644 --- a/app/lib/entity/tagged_file/data_source.dart +++ b/app/lib/entity/tagged_file/data_source.dart @@ -5,10 +5,10 @@ import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/tag.dart'; import 'package:nc_photos/entity/tagged_file.dart'; import 'package:nc_photos/exception.dart'; -import 'package:nc_photos/iterable_extension.dart'; import 'package:nc_photos/np_api_util.dart'; import 'package:np_api/np_api.dart' as api; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; part 'data_source.g.dart'; diff --git a/app/lib/future_util.dart b/app/lib/future_util.dart index 6f6d6dcb..1f9e9805 100644 --- a/app/lib/future_util.dart +++ b/app/lib/future_util.dart @@ -1,6 +1,6 @@ import 'dart:async'; -import 'package:nc_photos/iterable_extension.dart'; +import 'package:np_collection/np_collection.dart'; Future> waitOr( Iterable> futures, diff --git a/app/lib/internal_download_handler.dart b/app/lib/internal_download_handler.dart index 27c0a52a..b5456a18 100644 --- a/app/lib/internal_download_handler.dart +++ b/app/lib/internal_download_handler.dart @@ -7,15 +7,14 @@ import 'package:nc_photos/app_localizations.dart'; import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/file_util.dart' as file_util; import 'package:nc_photos/exception_util.dart' as exception_util; -import 'package:nc_photos/iterable_extension.dart'; import 'package:nc_photos/k.dart' as k; -import 'package:nc_photos/map_extension.dart'; import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/use_case/download_file.dart'; import 'package:nc_photos/use_case/download_preview.dart'; import 'package:nc_photos/widget/processing_dialog.dart'; import 'package:nc_photos_plugin/nc_photos_plugin.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; part 'internal_download_handler.g.dart'; diff --git a/app/lib/iterable_extension.dart b/app/lib/iterable_extension.dart index 0b3de2f0..ffbc146f 100644 --- a/app/lib/iterable_extension.dart +++ b/app/lib/iterable_extension.dart @@ -1,62 +1,9 @@ import 'dart:async'; -import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; -import 'package:nc_photos/list_extension.dart'; -import 'package:nc_photos/override_comparator.dart'; -import 'package:quiver/iterables.dart'; -import 'package:tuple/tuple.dart'; +import 'package:np_collection/np_collection.dart'; extension IterableExtension on Iterable { - /// Return a new stable sorted list - List stableSorted([int Function(T a, T b)? compare]) => - toList()..stableSort(compare); - - /// Return a string representation of this iterable by joining the result of - /// toString for each items - String toReadableString() => "[${join(', ')}]"; - - Iterable> withIndex() => mapIndexed((i, e) => Tuple2(i, e)); - - /// Whether the collection contains an element equal to [element] using the - /// equality function [equalFn] - bool containsIf(T element, bool Function(T a, T b) equalFn) => - any((e) => equalFn(e, element)); - - /// Same as [contains] but uses [identical] to compare the objects - bool containsIdentical(T element) => - containsIf(element, (a, b) => identical(a, b)); - - Map> groupBy({required U Function(T e) key}) { - return fold>>( - {}, - (previousValue, element) => - previousValue..putIfAbsent(key(element), () => []).add(element)); - } - - /// Return a new list with only distinct elements - List distinct() { - final s = {}; - return where((element) => s.add(element)).toList(); - } - - /// Return a new list with only distinct elements determined by [equalFn] - List distinctIf( - bool Function(T a, T b) equalFn, int Function(T a) hashCodeFn) { - final s = >{}; - return where((element) => - s.add(OverrideComparator(element, equalFn, hashCodeFn))).toList(); - } - - /// Invokes [action] on each element of this iterable in iteration order - /// lazily - Iterable forEachLazy(void Function(T element) action) sync* { - for (final e in this) { - action(e); - yield e; - } - } - Future> computeAll(ComputeCallback callback) async { final list = asList(); if (list.isEmpty) { @@ -66,63 +13,6 @@ extension IterableExtension on Iterable { _computeAllImpl, _ComputeAllMessage(callback, list)); } } - - /// Return a list containing elements in this iterable - /// - /// If this Iterable is itself a list, this will be returned directly with no - /// copying - List asList() { - if (this is List) { - return this as List; - } else { - return toList(); - } - } - - /// The first index of [element] in this iterable - /// - /// Searches the list from index start to the end of the list. The first time - /// an object o is encountered so that o == element, the index of o is - /// returned. Returns -1 if element is not found. - int indexOf(T element, [int start = 0]) { - var i = 0; - for (final e in this) { - final j = i++; - if (j < start) { - continue; - } - if (e == element) { - return j; - } - } - return -1; - } - - Future> withPartition( - FutureOr> Function(Iterable sublist) fn, int size) async { - final products = []; - final sublists = partition(this, size); - for (final l in sublists) { - products.addAll(await fn(l)); - } - return products; - } - - Future withPartitionNoReturn( - FutureOr Function(Iterable sublist) fn, int size) async { - final sublists = partition(this, size); - for (final l in sublists) { - await fn(l); - } - } -} - -extension IterableFlattenExtension on Iterable> { - /// Flattens an [Iterable] of [Iterable] values of type [T] to a [Iterable] of - /// values of type [T]. - /// - /// This function originated in the xml package - Iterable flatten() => expand((values) => values); } class _ComputeAllMessage { diff --git a/app/lib/legacy/sign_in.dart b/app/lib/legacy/sign_in.dart index f543ee28..dadc6954 100644 --- a/app/lib/legacy/sign_in.dart +++ b/app/lib/legacy/sign_in.dart @@ -10,7 +10,6 @@ import 'package:nc_photos/entity/pref.dart'; import 'package:nc_photos/entity/pref_util.dart' as pref_util; import 'package:nc_photos/entity/sqlite/database.dart' as sql; import 'package:nc_photos/help_utils.dart' as help_utils; -import 'package:nc_photos/iterable_extension.dart'; import 'package:nc_photos/legacy/connect.dart'; import 'package:nc_photos/platform/k.dart' as platform_k; import 'package:nc_photos/theme.dart'; @@ -18,6 +17,7 @@ import 'package:nc_photos/url_launcher_util.dart'; import 'package:nc_photos/widget/home.dart'; import 'package:nc_photos/widget/root_picker.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:np_string/np_string.dart'; part 'sign_in.g.dart'; diff --git a/app/lib/suggester.dart b/app/lib/suggester.dart index b415ccb5..b82a3a44 100644 --- a/app/lib/suggester.dart +++ b/app/lib/suggester.dart @@ -1,8 +1,8 @@ import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; import 'package:logging/logging.dart'; -import 'package:nc_photos/iterable_extension.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:np_string/np_string.dart'; import 'package:tuple/tuple.dart'; import 'package:woozy_search/woozy_search.dart'; diff --git a/app/lib/use_case/album/remove_from_album.dart b/app/lib/use_case/album/remove_from_album.dart index cf8deb56..9716af59 100644 --- a/app/lib/use_case/album/remove_from_album.dart +++ b/app/lib/use_case/album/remove_from_album.dart @@ -9,12 +9,12 @@ import 'package:nc_photos/entity/album/provider.dart'; import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/file_descriptor.dart'; import 'package:nc_photos/exception.dart'; -import 'package:nc_photos/iterable_extension.dart'; import 'package:nc_photos/use_case/album/unshare_file_from_album.dart'; import 'package:nc_photos/use_case/preprocess_album.dart'; import 'package:nc_photos/use_case/update_album.dart'; import 'package:nc_photos/use_case/update_album_with_actual_items.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:np_common/type.dart'; part 'remove_from_album.g.dart'; diff --git a/app/lib/use_case/album/share_album_with_user.dart b/app/lib/use_case/album/share_album_with_user.dart index f2d0af20..484440a7 100644 --- a/app/lib/use_case/album/share_album_with_user.dart +++ b/app/lib/use_case/album/share_album_with_user.dart @@ -7,10 +7,10 @@ import 'package:nc_photos/entity/album/provider.dart'; import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/share.dart'; import 'package:nc_photos/entity/sharee.dart'; -import 'package:nc_photos/iterable_extension.dart'; import 'package:nc_photos/use_case/create_share.dart'; import 'package:nc_photos/use_case/update_album.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:np_common/or_null.dart'; import 'package:np_common/type.dart'; import 'package:np_string/np_string.dart'; diff --git a/app/lib/use_case/cache_favorite.dart b/app/lib/use_case/cache_favorite.dart index fff59516..f9c10174 100644 --- a/app/lib/use_case/cache_favorite.dart +++ b/app/lib/use_case/cache_favorite.dart @@ -8,10 +8,9 @@ import 'package:nc_photos/di_container.dart'; import 'package:nc_photos/entity/sqlite/database.dart' as sql; import 'package:nc_photos/entity/sqlite/files_query_builder.dart' as sql; import 'package:nc_photos/event/event.dart'; -import 'package:nc_photos/iterable_extension.dart'; -import 'package:nc_photos/list_util.dart' as list_util; import 'package:nc_photos/object_extension.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; part 'cache_favorite.g.dart'; @@ -32,8 +31,7 @@ class CacheFavorite { final cache = await _getCacheFavorites(db, dbAccount); final cacheMap = Map.fromEntries(cache.map((e) => MapEntry(e.fileId, e.rowId))); - final diff = - list_util.diff(cacheMap.keys.sorted(Comparable.compare), remote); + final diff = getDiff(cacheMap.keys.sorted(Comparable.compare), remote); final newFileIds = diff.onlyInB; _log.info("[call] New favorites: ${newFileIds.toReadableString()}"); final removedFildIds = diff.onlyInA; diff --git a/app/lib/use_case/compat/v55.dart b/app/lib/use_case/compat/v55.dart index bd014f6a..6dc04906 100644 --- a/app/lib/use_case/compat/v55.dart +++ b/app/lib/use_case/compat/v55.dart @@ -3,8 +3,8 @@ import 'package:flutter/foundation.dart'; import 'package:logging/logging.dart'; import 'package:nc_photos/entity/file_util.dart' as file_util; import 'package:nc_photos/entity/sqlite/database.dart' as sql; -import 'package:nc_photos/iterable_extension.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:tuple/tuple.dart'; part 'v55.g.dart'; diff --git a/app/lib/use_case/face_recognition_person/sync_face_recognition_person.dart b/app/lib/use_case/face_recognition_person/sync_face_recognition_person.dart index a6ea2073..4b20c2e9 100644 --- a/app/lib/use_case/face_recognition_person/sync_face_recognition_person.dart +++ b/app/lib/use_case/face_recognition_person/sync_face_recognition_person.dart @@ -7,10 +7,9 @@ import 'package:nc_photos/entity/face_recognition_person.dart'; import 'package:nc_photos/entity/sqlite/database.dart' as sql; import 'package:nc_photos/entity/sqlite/type_converter.dart'; import 'package:nc_photos/exception.dart'; -import 'package:nc_photos/iterable_extension.dart'; -import 'package:nc_photos/list_util.dart' as list_util; import 'package:nc_photos/use_case/face_recognition_person/list_face_recognition_person.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; part 'sync_face_recognition_person.g.dart'; @@ -41,7 +40,7 @@ class SyncFaceRecognitionPerson { final cache = (await ListFaceRecognitionPerson(_c.withLocalRepo())(account) .last) ..sort(personSorter); - final diff = list_util.diffWith(cache, remote, personSorter); + final diff = getDiffWith(cache, remote, personSorter); final inserts = diff.onlyInB; _log.info("[call] New people: ${inserts.toReadableString()}"); final deletes = diff.onlyInA; diff --git a/app/lib/use_case/find_file.dart b/app/lib/use_case/find_file.dart index 7d462f47..d3e3d4c9 100644 --- a/app/lib/use_case/find_file.dart +++ b/app/lib/use_case/find_file.dart @@ -3,8 +3,8 @@ import 'package:nc_photos/account.dart'; import 'package:nc_photos/di_container.dart'; import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/sqlite/database.dart' as sql; -import 'package:nc_photos/iterable_extension.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; part 'find_file.g.dart'; diff --git a/app/lib/use_case/find_file_descriptor.dart b/app/lib/use_case/find_file_descriptor.dart index 559110f8..47f9b3f8 100644 --- a/app/lib/use_case/find_file_descriptor.dart +++ b/app/lib/use_case/find_file_descriptor.dart @@ -3,8 +3,8 @@ import 'package:nc_photos/account.dart'; import 'package:nc_photos/di_container.dart'; import 'package:nc_photos/entity/file_descriptor.dart'; import 'package:nc_photos/entity/sqlite/database.dart' as sql; -import 'package:nc_photos/iterable_extension.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; part 'find_file_descriptor.g.dart'; diff --git a/app/lib/use_case/recognize_face/sync_recognize_face.dart b/app/lib/use_case/recognize_face/sync_recognize_face.dart index d28a1a0a..28484c8f 100644 --- a/app/lib/use_case/recognize_face/sync_recognize_face.dart +++ b/app/lib/use_case/recognize_face/sync_recognize_face.dart @@ -8,12 +8,10 @@ import 'package:nc_photos/entity/recognize_face_item.dart'; import 'package:nc_photos/entity/sqlite/database.dart' as sql; import 'package:nc_photos/entity/sqlite/type_converter.dart'; import 'package:nc_photos/exception.dart'; -import 'package:nc_photos/iterable_extension.dart'; -import 'package:nc_photos/list_util.dart' as list_util; -import 'package:nc_photos/map_extension.dart'; import 'package:nc_photos/use_case/recognize_face/list_recognize_face.dart'; import 'package:nc_photos/use_case/recognize_face/list_recognize_face_item.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; part 'sync_recognize_face.g.dart'; @@ -96,7 +94,7 @@ class SyncRecognizeFace { } final cache = (await ListRecognizeFace(_c.withLocalRepo())(account).last) ..sort(faceSorter); - final diff = list_util.diffWith(cache, remote, faceSorter); + final diff = getDiffWith(cache, remote, faceSorter); final inserts = diff.onlyInB; _log.info("[_getFaceResults] New face: ${inserts.toReadableString()}"); final deletes = diff.onlyInA; @@ -152,8 +150,8 @@ class SyncRecognizeFace { for (final f in faces) { final thisCache = (cache[f] ?? [])..sort(itemSorter); final thisRemote = (remote[f] ?? [])..sort(itemSorter); - final diff = list_util.diffWith( - thisCache, thisRemote, itemSorter); + final diff = + getDiffWith(thisCache, thisRemote, itemSorter); final inserts = diff.onlyInB; _log.info( "[_getFaceItemResults] New item: ${inserts.toReadableString()}"); @@ -194,7 +192,7 @@ class SyncRecognizeFace { // await ListRecognizeFaceItem(_c.withLocalRepo())(account, face).last; // int itemSorter(RecognizeFaceItem a, RecognizeFaceItem b) => // a.fileId.compareTo(b.fileId); - // final diff = list_util.diffWith(cache, remote, itemSorter); + // final diff = getDiffWith(cache, remote, itemSorter); // final inserts = diff.onlyInB; // _log.info("[_getFaceItemResults] New face: ${inserts.toReadableString()}"); // final deletes = diff.onlyInA; diff --git a/app/lib/use_case/remove.dart b/app/lib/use_case/remove.dart index 131728ee..0b0ab87b 100644 --- a/app/lib/use_case/remove.dart +++ b/app/lib/use_case/remove.dart @@ -10,13 +10,13 @@ import 'package:nc_photos/entity/album/provider.dart'; import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/file_descriptor.dart'; import 'package:nc_photos/event/event.dart'; -import 'package:nc_photos/iterable_extension.dart'; import 'package:nc_photos/stream_extension.dart'; import 'package:nc_photos/use_case/album/list_album.dart'; import 'package:nc_photos/use_case/album/remove_from_album.dart'; import 'package:nc_photos/use_case/list_share.dart'; import 'package:nc_photos/use_case/remove_share.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:np_common/type.dart'; import 'package:np_string/np_string.dart'; diff --git a/app/lib/use_case/sync_tag.dart b/app/lib/use_case/sync_tag.dart index 3358348f..0efab95e 100644 --- a/app/lib/use_case/sync_tag.dart +++ b/app/lib/use_case/sync_tag.dart @@ -6,9 +6,8 @@ import 'package:nc_photos/di_container.dart'; import 'package:nc_photos/entity/sqlite/database.dart' as sql; import 'package:nc_photos/entity/sqlite/type_converter.dart'; import 'package:nc_photos/entity/tag.dart'; -import 'package:nc_photos/iterable_extension.dart'; -import 'package:nc_photos/list_util.dart' as list_util; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; part 'sync_tag.g.dart'; @@ -26,7 +25,7 @@ class SyncTag { int tagSorter(Tag a, Tag b) => a.id.compareTo(b.id); final remote = (await _c.tagRepoRemote.list(account))..sort(tagSorter); final cache = (await _c.tagRepoLocal.list(account))..sort(tagSorter); - final diff = list_util.diffWith(cache, remote, tagSorter); + final diff = getDiffWith(cache, remote, tagSorter); final inserts = diff.onlyInB; _log.info("[call] New tags: ${inserts.toReadableString()}"); final deletes = diff.onlyInA; diff --git a/app/lib/widget/album_dir_picker.dart b/app/lib/widget/album_dir_picker.dart index e4b8de93..700ca82e 100644 --- a/app/lib/widget/album_dir_picker.dart +++ b/app/lib/widget/album_dir_picker.dart @@ -5,11 +5,11 @@ import 'package:nc_photos/api/api_util.dart' as api_util; import 'package:nc_photos/app_localizations.dart'; import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/file_descriptor.dart'; -import 'package:nc_photos/iterable_extension.dart'; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/widget/dir_picker.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; part 'album_dir_picker.g.dart'; diff --git a/app/lib/widget/album_importer.dart b/app/lib/widget/album_importer.dart index fa54e10c..7a7e9112 100644 --- a/app/lib/widget/album_importer.dart +++ b/app/lib/widget/album_importer.dart @@ -17,7 +17,6 @@ import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/file_descriptor.dart'; import 'package:nc_photos/entity/file_util.dart' as file_util; import 'package:nc_photos/exception_util.dart' as exception_util; -import 'package:nc_photos/iterable_extension.dart'; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/use_case/album/create_album.dart'; @@ -25,6 +24,7 @@ import 'package:nc_photos/use_case/preprocess_album.dart'; import 'package:nc_photos/use_case/update_album_with_actual_items.dart'; import 'package:nc_photos/widget/processing_dialog.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; part 'album_importer.g.dart'; diff --git a/app/lib/widget/enhanced_photo_browser.dart b/app/lib/widget/enhanced_photo_browser.dart index 0eb64ee8..81d63597 100644 --- a/app/lib/widget/enhanced_photo_browser.dart +++ b/app/lib/widget/enhanced_photo_browser.dart @@ -11,7 +11,6 @@ import 'package:nc_photos/entity/file_util.dart' as file_util; import 'package:nc_photos/entity/local_file.dart'; import 'package:nc_photos/entity/pref.dart'; import 'package:nc_photos/exception_util.dart' as exception_util; -import 'package:nc_photos/iterable_extension.dart'; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/mobile/android/android_info.dart'; import 'package:nc_photos/mobile/android/permission_util.dart'; @@ -28,6 +27,7 @@ import 'package:nc_photos/widget/selectable_item_stream_list_mixin.dart'; import 'package:nc_photos/widget/selection_app_bar.dart'; import 'package:nc_photos_plugin/nc_photos_plugin.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; part 'enhanced_photo_browser.g.dart'; diff --git a/app/lib/widget/file_sharer_dialog.dart b/app/lib/widget/file_sharer_dialog.dart index 26402d53..085cc572 100644 --- a/app/lib/widget/file_sharer_dialog.dart +++ b/app/lib/widget/file_sharer_dialog.dart @@ -17,7 +17,6 @@ import 'package:nc_photos/entity/file_descriptor.dart'; import 'package:nc_photos/entity/file_util.dart' as file_util; import 'package:nc_photos/exception_event.dart'; import 'package:nc_photos/exception_util.dart' as exception_util; -import 'package:nc_photos/iterable_extension.dart'; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/mobile/share.dart'; import 'package:nc_photos/platform/k.dart' as platform_k; @@ -34,6 +33,7 @@ import 'package:nc_photos/widget/share_link_multiple_files_dialog.dart'; import 'package:nc_photos/widget/simple_input_dialog.dart'; import 'package:nc_photos_plugin/nc_photos_plugin.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:to_string/to_string.dart'; import 'package:tuple/tuple.dart'; diff --git a/app/lib/widget/image_editor/color_toolbar.dart b/app/lib/widget/image_editor/color_toolbar.dart index 31b9cc56..3cdab079 100644 --- a/app/lib/widget/image_editor/color_toolbar.dart +++ b/app/lib/widget/image_editor/color_toolbar.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; import 'package:nc_photos/app_localizations.dart'; -import 'package:nc_photos/iterable_extension.dart'; import 'package:nc_photos/object_extension.dart'; import 'package:nc_photos/widget/image_editor/toolbar_button.dart'; import 'package:nc_photos_plugin/nc_photos_plugin.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:np_string/np_string.dart'; import 'package:np_ui/np_ui.dart'; diff --git a/app/lib/widget/selectable_item_list.dart b/app/lib/widget/selectable_item_list.dart index 05413984..9967080e 100644 --- a/app/lib/widget/selectable_item_list.dart +++ b/app/lib/widget/selectable_item_list.dart @@ -5,13 +5,13 @@ import 'package:flutter/material.dart'; import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; import 'package:logging/logging.dart'; import 'package:nc_photos/app_localizations.dart'; -import 'package:nc_photos/iterable_extension.dart'; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/platform/k.dart' as platform_k; import 'package:nc_photos/session_storage.dart'; import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/widget/selectable.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; part 'selectable_item_list.g.dart'; diff --git a/app/lib/widget/selectable_item_stream_list_mixin.dart b/app/lib/widget/selectable_item_stream_list_mixin.dart index a983e5de..cf5dbbd7 100644 --- a/app/lib/widget/selectable_item_stream_list_mixin.dart +++ b/app/lib/widget/selectable_item_stream_list_mixin.dart @@ -5,7 +5,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; import 'package:logging/logging.dart'; import 'package:nc_photos/app_localizations.dart'; -import 'package:nc_photos/iterable_extension.dart'; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/platform/k.dart' as platform_k; import 'package:nc_photos/session_storage.dart'; @@ -13,6 +12,7 @@ import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/widget/measurable_item_list.dart'; import 'package:nc_photos/widget/selectable.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:uuid/uuid.dart'; import 'package:visibility_detector/visibility_detector.dart'; diff --git a/app/lib/widget/share_folder_picker.dart b/app/lib/widget/share_folder_picker.dart index 5818c617..845df6bf 100644 --- a/app/lib/widget/share_folder_picker.dart +++ b/app/lib/widget/share_folder_picker.dart @@ -5,11 +5,11 @@ import 'package:nc_photos/app_localizations.dart'; import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/file_descriptor.dart'; import 'package:nc_photos/entity/file_util.dart' as file_util; -import 'package:nc_photos/iterable_extension.dart'; import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/widget/dir_picker.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; part 'share_folder_picker.g.dart'; diff --git a/app/lib/widget/sign_in.dart b/app/lib/widget/sign_in.dart index a809ddb9..402c0e63 100644 --- a/app/lib/widget/sign_in.dart +++ b/app/lib/widget/sign_in.dart @@ -10,13 +10,13 @@ import 'package:nc_photos/di_container.dart'; import 'package:nc_photos/entity/pref.dart'; import 'package:nc_photos/entity/pref_util.dart' as pref_util; import 'package:nc_photos/entity/sqlite/database.dart' as sql; -import 'package:nc_photos/iterable_extension.dart'; import 'package:nc_photos/legacy/sign_in.dart' as legacy; import 'package:nc_photos/theme.dart'; import 'package:nc_photos/widget/connect.dart'; import 'package:nc_photos/widget/home.dart'; import 'package:nc_photos/widget/root_picker.dart'; import 'package:np_codegen/np_codegen.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:np_string/np_string.dart'; part 'sign_in.g.dart'; diff --git a/app/pubspec.lock b/app/pubspec.lock index 96f18380..9c519f4e 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -962,6 +962,13 @@ packages: relative: true source: path version: "1.0.0" + np_collection: + dependency: "direct main" + description: + path: "../np_collection" + relative: true + source: path + version: "1.0.0" np_common: dependency: "direct main" description: @@ -1205,7 +1212,7 @@ packages: source: hosted version: "1.2.3" quiver: - dependency: "direct main" + dependency: transitive description: name: quiver sha256: b1c1ac5ce6688d77f65f3375a9abb9319b3cb32486bdc7a1e0fdf004d7ba4e47 diff --git a/app/pubspec.yaml b/app/pubspec.yaml index 79650acc..c3fbd18d 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -103,6 +103,8 @@ dependencies: path: ../codegen np_common: path: ../np_common + np_collection: + path: ../np_collection np_log: path: ../np_log np_math: @@ -115,7 +117,6 @@ dependencies: page_view_indicators: ^2.0.0 path: ^1.8.0 path_provider: ^2.0.15 - quiver: ^3.2.1 rxdart: ^0.27.7 screen_brightness: ^0.2.2 shared_preferences: ^2.0.8 diff --git a/app/test/entity/file/data_source_test.dart b/app/test/entity/file/data_source_test.dart index 57114ff2..fc49820b 100644 --- a/app/test/entity/file/data_source_test.dart +++ b/app/test/entity/file/data_source_test.dart @@ -2,7 +2,7 @@ import 'package:nc_photos/di_container.dart'; import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/file/data_source.dart'; import 'package:nc_photos/entity/sqlite/database.dart' as sql; -import 'package:nc_photos/list_extension.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:np_common/or_null.dart'; import 'package:test/test.dart'; diff --git a/app/test/entity/file/file_cache_manager_test.dart b/app/test/entity/file/file_cache_manager_test.dart index 07b3d7d5..5d97d0ce 100644 --- a/app/test/entity/file/file_cache_manager_test.dart +++ b/app/test/entity/file/file_cache_manager_test.dart @@ -3,7 +3,7 @@ import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/file/data_source.dart'; import 'package:nc_photos/entity/file/file_cache_manager.dart'; import 'package:nc_photos/entity/sqlite/database.dart' as sql; -import 'package:nc_photos/list_extension.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:np_common/or_null.dart'; import 'package:np_math/np_math.dart'; import 'package:test/test.dart'; diff --git a/app/test/test_util.dart b/app/test/test_util.dart index ea1f186b..2f21ea2b 100644 --- a/app/test/test_util.dart +++ b/app/test/test_util.dart @@ -16,7 +16,7 @@ import 'package:nc_photos/entity/share.dart'; import 'package:nc_photos/entity/sharee.dart'; import 'package:nc_photos/entity/sqlite/database.dart' as sql; import 'package:nc_photos/entity/sqlite/type_converter.dart'; -import 'package:nc_photos/iterable_extension.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:np_common/or_null.dart'; import 'package:np_string/np_string.dart'; import 'package:tuple/tuple.dart'; diff --git a/app/test/use_case/inflate_file_descriptor_test.dart b/app/test/use_case/inflate_file_descriptor_test.dart index 2e409ad7..3c679f15 100644 --- a/app/test/use_case/inflate_file_descriptor_test.dart +++ b/app/test/use_case/inflate_file_descriptor_test.dart @@ -2,8 +2,8 @@ import 'package:clock/clock.dart'; import 'package:nc_photos/di_container.dart'; import 'package:nc_photos/entity/file_descriptor.dart'; import 'package:nc_photos/entity/sqlite/database.dart' as sql; -import 'package:nc_photos/list_extension.dart'; import 'package:nc_photos/use_case/inflate_file_descriptor.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:test/test.dart'; import '../test_util.dart' as util; diff --git a/app/test/use_case/ls_test.dart b/app/test/use_case/ls_test.dart index 1be9698b..da53367a 100644 --- a/app/test/use_case/ls_test.dart +++ b/app/test/use_case/ls_test.dart @@ -1,7 +1,7 @@ import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/entity/file_util.dart' as file_util; -import 'package:nc_photos/list_extension.dart'; import 'package:nc_photos/use_case/ls.dart'; +import 'package:np_collection/np_collection.dart'; import 'package:test/test.dart'; import '../mock_type.dart'; diff --git a/np_collection/.gitignore b/np_collection/.gitignore new file mode 100644 index 00000000..3cceda55 --- /dev/null +++ b/np_collection/.gitignore @@ -0,0 +1,7 @@ +# https://dart.dev/guides/libraries/private-files +# Created by `dart pub` +.dart_tool/ + +# Avoid committing pubspec.lock for library packages; see +# https://dart.dev/guides/libraries/private-files#pubspeclock. +pubspec.lock diff --git a/np_collection/analysis_options.yaml b/np_collection/analysis_options.yaml new file mode 100644 index 00000000..f92d2567 --- /dev/null +++ b/np_collection/analysis_options.yaml @@ -0,0 +1 @@ +include: package:np_lints/np.yaml diff --git a/np_collection/lib/np_collection.dart b/np_collection/lib/np_collection.dart new file mode 100644 index 00000000..d3fff8b0 --- /dev/null +++ b/np_collection/lib/np_collection.dart @@ -0,0 +1,7 @@ +library np_collection; + +export 'src/iterable_extension.dart'; +export 'src/iterator_extension.dart'; +export 'src/list_extension.dart'; +export 'src/list_util.dart'; +export 'src/map_extension.dart'; diff --git a/np_collection/lib/src/iterable_extension.dart b/np_collection/lib/src/iterable_extension.dart new file mode 100644 index 00000000..72bf6a0c --- /dev/null +++ b/np_collection/lib/src/iterable_extension.dart @@ -0,0 +1,114 @@ +import 'dart:async'; +import 'dart:collection'; + +import 'package:collection/collection.dart'; +import 'package:np_collection/src/list_extension.dart'; +import 'package:quiver/iterables.dart'; +import 'package:tuple/tuple.dart'; + +extension IterableExtension on Iterable { + /// Return a new stable sorted list + List stableSorted([int Function(T a, T b)? compare]) => + toList()..stableSort(compare); + + /// Return a string representation of this iterable by joining the result of + /// toString for each items + String toReadableString() => "[${join(', ')}]"; + + Iterable> withIndex() => mapIndexed((i, e) => Tuple2(i, e)); + + /// Whether the collection contains an element equal to [element] using the + /// equality function [equalFn] + bool containsIf(T element, bool Function(T a, T b) equalFn) => + any((e) => equalFn(e, element)); + + /// Same as [contains] but uses [identical] to compare the objects + bool containsIdentical(T element) => + containsIf(element, (a, b) => identical(a, b)); + + Map> groupBy({required U Function(T e) key}) { + return fold>>( + {}, + (previousValue, element) => + previousValue..putIfAbsent(key(element), () => []).add(element)); + } + + /// Return a new list with only distinct elements + List distinct() { + final s = {}; + return where((element) => s.add(element)).toList(); + } + + /// Return a new list with only distinct elements determined by [equalFn] + List distinctIf( + bool Function(T a, T b) equalFn, int Function(T a) hashCodeFn) { + final s = LinkedHashSet(equals: equalFn, hashCode: hashCodeFn); + return where((element) => s.add(element)).toList(); + } + + /// Invokes [action] on each element of this iterable in iteration order + /// lazily + Iterable forEachLazy(void Function(T element) action) sync* { + for (final e in this) { + action(e); + yield e; + } + } + + /// Return a list containing elements in this iterable + /// + /// If this Iterable is itself a list, this will be returned directly with no + /// copying + List asList() { + if (this is List) { + return this as List; + } else { + return toList(); + } + } + + /// The first index of [element] in this iterable + /// + /// Searches the list from index start to the end of the list. The first time + /// an object o is encountered so that o == element, the index of o is + /// returned. Returns -1 if element is not found. + int indexOf(T element, [int start = 0]) { + var i = 0; + for (final e in this) { + final j = i++; + if (j < start) { + continue; + } + if (e == element) { + return j; + } + } + return -1; + } + + Future> withPartition( + FutureOr> Function(Iterable sublist) fn, int size) async { + final products = []; + final sublists = partition(this, size); + for (final l in sublists) { + products.addAll(await fn(l)); + } + return products; + } + + Future withPartitionNoReturn( + FutureOr Function(Iterable sublist) fn, int size) async { + final sublists = partition(this, size); + for (final l in sublists) { + await fn(l); + } + } +} + +extension IterableFlattenExtension on Iterable> { + /// Flattens an [Iterable] of [Iterable] values of type [T] to a [Iterable] of + /// values of type [T]. + /// + /// This function originated in the xml package + Iterable flatten() => expand((values) => values); +} diff --git a/app/lib/iterator_extension.dart b/np_collection/lib/src/iterator_extension.dart similarity index 100% rename from app/lib/iterator_extension.dart rename to np_collection/lib/src/iterator_extension.dart diff --git a/app/lib/list_extension.dart b/np_collection/lib/src/list_extension.dart similarity index 100% rename from app/lib/list_extension.dart rename to np_collection/lib/src/list_extension.dart diff --git a/app/lib/list_util.dart b/np_collection/lib/src/list_util.dart similarity index 90% rename from app/lib/list_util.dart rename to np_collection/lib/src/list_util.dart index 3e992e23..3266afce 100644 --- a/app/lib/list_util.dart +++ b/np_collection/lib/src/list_util.dart @@ -1,4 +1,4 @@ -import 'package:nc_photos/iterator_extension.dart'; +import 'package:np_collection/src/iterator_extension.dart'; /// Contain results from the diff functions /// @@ -18,7 +18,7 @@ class DiffResult { /// /// [a] and [b] MUST be sorted in ascending order, otherwise the result is /// undefined -DiffResult diffWith( +DiffResult getDiffWith( Iterable a, Iterable b, int Function(T a, T b) comparator) { final aIt = a.iterator, bIt = b.iterator; final aMissing = [], bMissing = []; @@ -41,8 +41,8 @@ DiffResult diffWith( } } -DiffResult diff(Iterable a, Iterable b) => - diffWith(a, b, Comparable.compare); +DiffResult getDiff(Iterable a, Iterable b) => + getDiffWith(a, b, Comparable.compare); DiffResult _diffUntilEqual( Iterator aIt, Iterator bIt, int Function(T a, T b) comparator) { diff --git a/app/lib/map_extension.dart b/np_collection/lib/src/map_extension.dart similarity index 100% rename from app/lib/map_extension.dart rename to np_collection/lib/src/map_extension.dart diff --git a/np_collection/pubspec.yaml b/np_collection/pubspec.yaml new file mode 100644 index 00000000..6ebb1f78 --- /dev/null +++ b/np_collection/pubspec.yaml @@ -0,0 +1,20 @@ +name: np_collection +description: A starting point for Dart libraries or applications. +version: 1.0.0 +# repository: https://github.com/my_org/my_repo +publish_to: none + +environment: + sdk: '>=2.19.6 <3.0.0' + +dependencies: + collection: ^1.15.0 + np_math: + path: ../np_math + quiver: ^3.2.1 + tuple: ^2.0.1 + +dev_dependencies: + np_lints: + path: ../np_lints + test: ^1.21.0 diff --git a/app/test/iterable_extension_test.dart b/np_collection/test/iterable_extension_test.dart similarity index 98% rename from app/test/iterable_extension_test.dart rename to np_collection/test/iterable_extension_test.dart index c94cb705..4cfea48c 100644 --- a/app/test/iterable_extension_test.dart +++ b/np_collection/test/iterable_extension_test.dart @@ -1,4 +1,4 @@ -import 'package:nc_photos/iterable_extension.dart'; +import 'package:np_collection/src/iterable_extension.dart'; import 'package:np_math/np_math.dart'; import 'package:quiver/core.dart'; import 'package:test/test.dart'; diff --git a/app/test/iterator_extension_test.dart b/np_collection/test/iterator_extension_test.dart similarity index 88% rename from app/test/iterator_extension_test.dart rename to np_collection/test/iterator_extension_test.dart index 85f883ab..19cac71f 100644 --- a/app/test/iterator_extension_test.dart +++ b/np_collection/test/iterator_extension_test.dart @@ -1,4 +1,4 @@ -import 'package:nc_photos/iterator_extension.dart'; +import 'package:np_collection/src/iterator_extension.dart'; import 'package:test/test.dart'; void main() { diff --git a/app/test/list_extension_test.dart b/np_collection/test/list_extension_test.dart similarity index 97% rename from app/test/list_extension_test.dart rename to np_collection/test/list_extension_test.dart index 3feb1c6a..9e472f7f 100644 --- a/app/test/list_extension_test.dart +++ b/np_collection/test/list_extension_test.dart @@ -1,4 +1,4 @@ -import 'package:nc_photos/list_extension.dart'; +import 'package:np_collection/src/list_extension.dart'; import 'package:test/test.dart'; void main() { diff --git a/app/test/list_util_test.dart b/np_collection/test/list_util_test.dart similarity index 80% rename from app/test/list_util_test.dart rename to np_collection/test/list_util_test.dart index 3e46ed76..e8bd7c89 100644 --- a/app/test/list_util_test.dart +++ b/np_collection/test/list_util_test.dart @@ -1,4 +1,4 @@ -import 'package:nc_photos/list_util.dart' as list_util; +import 'package:np_collection/src/list_util.dart'; import 'package:test/test.dart'; void main() { @@ -26,7 +26,7 @@ void main() { /// b: [1, 2, 3, 4, 5] /// Expect: [1, 2], [] void _diffExtraBBegin() { - final diff = list_util.diff([3, 4, 5], [1, 2, 3, 4, 5]); + final diff = getDiff([3, 4, 5], [1, 2, 3, 4, 5]); expect(diff.onlyInB, [1, 2]); expect(diff.onlyInA, []); } @@ -37,7 +37,7 @@ void _diffExtraBBegin() { /// b: [1, 2, 3, 4, 5] /// Expect: [4, 5], [] void _diffExtraBEnd() { - final diff = list_util.diff([1, 2, 3], [1, 2, 3, 4, 5]); + final diff = getDiff([1, 2, 3], [1, 2, 3, 4, 5]); expect(diff.onlyInB, [4, 5]); expect(diff.onlyInA, []); } @@ -48,7 +48,7 @@ void _diffExtraBEnd() { /// b: [1, 2, 3, 4, 5] /// Expect: [3, 4], [] void _diffExtraBMid() { - final diff = list_util.diff([1, 2, 5], [1, 2, 3, 4, 5]); + final diff = getDiff([1, 2, 5], [1, 2, 3, 4, 5]); expect(diff.onlyInB, [3, 4]); expect(diff.onlyInA, []); } @@ -59,7 +59,7 @@ void _diffExtraBMid() { /// b: [1, 2, 3] /// Expect: [1, 2, 3], [] void _diffAEmpty() { - final diff = list_util.diff([], [1, 2, 3]); + final diff = getDiff([], [1, 2, 3]); expect(diff.onlyInB, [1, 2, 3]); expect(diff.onlyInA, []); } @@ -70,7 +70,7 @@ void _diffAEmpty() { /// b: [3, 4, 5] /// Expect: [], [1, 2] void _diffExtraABegin() { - final diff = list_util.diff([1, 2, 3, 4, 5], [3, 4, 5]); + final diff = getDiff([1, 2, 3, 4, 5], [3, 4, 5]); expect(diff.onlyInB, []); expect(diff.onlyInA, [1, 2]); } @@ -81,7 +81,7 @@ void _diffExtraABegin() { /// b: [1, 2, 3] /// Expect: [], [4, 5] void _diffExtraAEnd() { - final diff = list_util.diff([1, 2, 3, 4, 5], [1, 2, 3]); + final diff = getDiff([1, 2, 3, 4, 5], [1, 2, 3]); expect(diff.onlyInB, []); expect(diff.onlyInA, [4, 5]); } @@ -92,7 +92,7 @@ void _diffExtraAEnd() { /// b: [1, 2, 5] /// Expect: [], [3, 4] void _diffExtraAMid() { - final diff = list_util.diff([1, 2, 3, 4, 5], [1, 2, 5]); + final diff = getDiff([1, 2, 3, 4, 5], [1, 2, 5]); expect(diff.onlyInB, []); expect(diff.onlyInA, [3, 4]); } @@ -103,7 +103,7 @@ void _diffExtraAMid() { /// b: [] /// Expect: [], [1, 2, 3] void _diffBEmpty() { - final diff = list_util.diff([1, 2, 3], []); + final diff = getDiff([1, 2, 3], []); expect(diff.onlyInB, []); expect(diff.onlyInA, [1, 2, 3]); } @@ -114,7 +114,7 @@ void _diffBEmpty() { /// b: [2, 4] /// Expect: [2, 4], [1, 3, 5] void _diffNoMatches() { - final diff = list_util.diff([1, 3, 5], [2, 4]); + final diff = getDiff([1, 3, 5], [2, 4]); expect(diff.onlyInB, [2, 4]); expect(diff.onlyInA, [1, 3, 5]); } @@ -125,7 +125,7 @@ void _diffNoMatches() { /// b: [1, 2, 2, 3] /// Expect: [2], [] void _diffRepeatedElements() { - final diff = list_util.diff([1, 2, 3], [1, 2, 2, 3]); + final diff = getDiff([1, 2, 3], [1, 2, 2, 3]); expect(diff.onlyInB, [2]); expect(diff.onlyInA, []); } @@ -136,7 +136,7 @@ void _diffRepeatedElements() { /// b: [1, 2, 2, 3, 5] /// Expect: [2, 2], [4, 4] void _diffRepeatedElements2() { - final diff = list_util.diff([1, 3, 4, 4, 5], [1, 2, 2, 3, 5]); + final diff = getDiff([1, 3, 4, 4, 5], [1, 2, 2, 3, 5]); expect(diff.onlyInB, [2, 2]); expect(diff.onlyInA, [4, 4]); } @@ -147,7 +147,7 @@ void _diffRepeatedElements2() { /// b: [1, 3, 4, 8, 13, 14] /// Expect: [1, 4, 8, 13, 14], [2, 7, 10, 11, 12] void _diffMix() { - final diff = list_util.diff([2, 3, 7, 10, 11, 12], [1, 3, 4, 8, 13, 14]); + final diff = getDiff([2, 3, 7, 10, 11, 12], [1, 3, 4, 8, 13, 14]); expect(diff.onlyInB, [1, 4, 8, 13, 14]); expect(diff.onlyInA, [2, 7, 10, 11, 12]); }