From 69a115c3846cf3f0ac9c81bfd8ed20d00c8364ef Mon Sep 17 00:00:00 2001 From: Marcelo Glasberg <13332110+marcglasberg@users.noreply.github.com> Date: Fri, 10 Nov 2023 18:01:15 -0300 Subject: [PATCH] UseResult annotation to signal that a method should return a copy of the collection, instead of mutating it. --- CHANGELOG.md | 5 + example/benchmark/benchmark_app/lib/main.dart | 6 -- .../lib/screens/code_screen.dart | 4 - .../lib/screens/graph_screen.dart | 20 +--- .../benchmark_app/lib/utils/benchmarks.dart | 8 -- .../lib/utils/benchmarks_code.dart | 8 -- .../benchmark_app/lib/widgets/bar_chart.dart | 4 - .../lib/widgets/bench_widget.dart | 10 +- .../lib/widgets/collection_button.dart | 4 - .../lib/widgets/release_mode_warning.dart | 4 - example/benchmark/lib/src/cases/list/add.dart | 34 ++---- .../benchmark/lib/src/cases/list/add_all.dart | 29 ++--- .../lib/src/cases/list/contains.dart | 30 ++---- .../benchmark/lib/src/cases/list/empty.dart | 30 ++---- .../benchmark/lib/src/cases/list/insert.dart | 29 ++--- .../benchmark/lib/src/cases/list/read.dart | 29 ++--- .../benchmark/lib/src/cases/list/remove.dart | 30 ++---- example/benchmark/lib/src/cases/map/add.dart | 34 ++---- .../benchmark/lib/src/cases/map/add_all.dart | 29 ++--- .../lib/src/cases/map/contains_value.dart | 30 ++---- .../benchmark/lib/src/cases/map/empty.dart | 29 ++--- example/benchmark/lib/src/cases/map/read.dart | 28 ++--- .../benchmark/lib/src/cases/map/remove.dart | 29 ++--- example/benchmark/lib/src/cases/set/add.dart | 33 ++---- .../benchmark/lib/src/cases/set/add_all.dart | 29 ++--- .../benchmark/lib/src/cases/set/contains.dart | 30 ++---- .../benchmark/lib/src/cases/set/empty.dart | 29 ++--- .../benchmark/lib/src/cases/set/remove.dart | 31 ++---- .../src/utils/collection_benchmark_base.dart | 34 +++--- example/benchmark/lib/src/utils/records.dart | 12 --- .../lib/src/utils/table_score_emitter.dart | 4 - lib/src/base/immutable_collection.dart | 3 - lib/src/base/iterable_extension.dart | 2 +- lib/src/ilist/ilist.dart | 100 +++++++++--------- lib/src/imap/imap.dart | 42 ++++---- lib/src/imap_of_sets/imap_of_sets.dart | 56 +++++----- lib/src/iset/iset.dart | 38 +++---- pubspec.yaml | 2 +- test/base/equality_type_checking_test.dart | 2 +- 39 files changed, 260 insertions(+), 650 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb0b2983..14bcd0db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## [9.2.0] - 2023/11/10 + +* @useResult annotation to signal that a method should return a copy of the collection, instead of + mutating it. + ## [9.1.6] - 2023/10/08 * Small docs improvement. diff --git a/example/benchmark/benchmark_app/lib/main.dart b/example/benchmark/benchmark_app/lib/main.dart index 59c22946..8b19152f 100644 --- a/example/benchmark/benchmark_app/lib/main.dart +++ b/example/benchmark/benchmark_app/lib/main.dart @@ -2,12 +2,8 @@ import "package:benchmark_app/screens/collection_choice_screen.dart"; import "package:benchmark_app/widgets/release_mode_warning.dart"; import "package:flutter/material.dart"; - - void main() => runApp(const BenchmarkApp()); - - class BenchmarkApp extends StatelessWidget { const BenchmarkApp(); @@ -29,5 +25,3 @@ class BenchmarkApp extends StatelessWidget { ); } } - - diff --git a/example/benchmark/benchmark_app/lib/screens/code_screen.dart b/example/benchmark/benchmark_app/lib/screens/code_screen.dart index 90f688e5..12bb5def 100644 --- a/example/benchmark/benchmark_app/lib/screens/code_screen.dart +++ b/example/benchmark/benchmark_app/lib/screens/code_screen.dart @@ -3,8 +3,6 @@ import "dart:io"; import "package:benchmark_app/widgets/collection_button.dart"; import "package:flutter/material.dart"; - - class CodeScreen extends StatelessWidget { final String description; final Map code; @@ -108,5 +106,3 @@ class _CodeBlock extends StatelessWidget { ); } } - - diff --git a/example/benchmark/benchmark_app/lib/screens/graph_screen.dart b/example/benchmark/benchmark_app/lib/screens/graph_screen.dart index 096a05eb..7f21e04e 100644 --- a/example/benchmark/benchmark_app/lib/screens/graph_screen.dart +++ b/example/benchmark/benchmark_app/lib/screens/graph_screen.dart @@ -2,8 +2,6 @@ import "package:benchmark_app/widgets/bar_chart.dart"; import "package:fast_immutable_collections_benchmarks/fast_immutable_collections_benchmarks.dart"; import "package:flutter/material.dart"; - - class GraphScreen extends StatefulWidget { final String title; final List? tables; @@ -17,8 +15,6 @@ class GraphScreen extends StatefulWidget { _GraphScreenState createState() => _GraphScreenState(); } - - class _GraphScreenState extends State { static final BoxDecoration bottomDecoration = BoxDecoration( color: Colors.blue, @@ -144,8 +140,6 @@ class _GraphScreenState extends State { } } - - class _DropdownButton extends StatelessWidget { // final VoidCallback onTap; @@ -159,13 +153,13 @@ class _DropdownButton extends StatelessWidget { onTap: onTap, child: Container( margin: const EdgeInsets.only(top: 8, bottom: 16, left: 8, right: 8), - child: ColoredBox( - color: const Color(0x22000000), + child: const ColoredBox( + color: Color(0x22000000), child: Padding( - padding: const EdgeInsets.symmetric(vertical: 12.0), + padding: EdgeInsets.symmetric(vertical: 12.0), child: Row( mainAxisAlignment: MainAxisAlignment.center, - children: const [ + children: [ Text("Filters", style: TextStyle(fontSize: 20)), Icon(Icons.arrow_drop_down), ], @@ -178,8 +172,6 @@ class _DropdownButton extends StatelessWidget { } } - - class _FilterDialog extends StatefulWidget { // final Map filters; @@ -191,8 +183,6 @@ class _FilterDialog extends StatefulWidget { _FilterDialogState createState() => _FilterDialogState(); } - - class _FilterDialogState extends State<_FilterDialog> { // Map get filters => widget.filters; @@ -252,5 +242,3 @@ class _FilterDialogState extends State<_FilterDialog> { ); } } - - diff --git a/example/benchmark/benchmark_app/lib/utils/benchmarks.dart b/example/benchmark/benchmark_app/lib/utils/benchmarks.dart index 8268d22f..740e1699 100644 --- a/example/benchmark/benchmark_app/lib/utils/benchmarks.dart +++ b/example/benchmark/benchmark_app/lib/utils/benchmarks.dart @@ -6,8 +6,6 @@ import "package:flutter/material.dart"; /// Be careful with the parameters. If they are too big, you might encounter a difficult-to-debug /// error, probably due to insufficient memory. - - final List listBenchmarks = [ BenchWidget( title: "List.add", @@ -113,8 +111,6 @@ final List listBenchmarks = [ ), ]; - - final List setBenchmarks = [ BenchWidget( title: "Set.add", @@ -220,8 +216,6 @@ final List setBenchmarks = [ ), ]; - - final List mapBenchmarks = [ BenchWidget( title: "Map.add", @@ -308,5 +302,3 @@ final List mapBenchmarks = [ ], ), ]; - - diff --git a/example/benchmark/benchmark_app/lib/utils/benchmarks_code.dart b/example/benchmark/benchmark_app/lib/utils/benchmarks_code.dart index 4eb74c24..06f807d8 100644 --- a/example/benchmark/benchmark_app/lib/utils/benchmarks_code.dart +++ b/example/benchmark/benchmark_app/lib/utils/benchmarks_code.dart @@ -1,5 +1,3 @@ - - abstract class ListCode { static const Map add = { "List (Mutable)": "for (int i = 0; i < innerRuns; i++)\n" " _list.add(i);", @@ -67,8 +65,6 @@ abstract class ListCode { }; } - - abstract class SetCode { static const Map add = { "Set (Mutable)": "_set = Set.of(_fixedSet);\n" @@ -121,8 +117,6 @@ abstract class SetCode { }; } - - abstract class MapCode { static const Map add = { "Map (Mutable)": "for (int i = 0; i < initialLength + innerRuns(); i++)\n" @@ -178,5 +172,3 @@ abstract class MapCode { " => mapBuilder.remove((config.size ~/ 2).toString()));", }; } - - diff --git a/example/benchmark/benchmark_app/lib/widgets/bar_chart.dart b/example/benchmark/benchmark_app/lib/widgets/bar_chart.dart index 6084dfa9..41937073 100644 --- a/example/benchmark/benchmark_app/lib/widgets/bar_chart.dart +++ b/example/benchmark/benchmark_app/lib/widgets/bar_chart.dart @@ -2,8 +2,6 @@ import "package:charts_flutter/flutter.dart" as charts; import "package:fast_immutable_collections_benchmarks/fast_immutable_collections_benchmarks.dart"; import "package:flutter/material.dart"; - - class BarChart extends StatelessWidget { final RecordsTable recordsTable; @@ -56,5 +54,3 @@ class BarChart extends StatelessWidget { ); } } - - diff --git a/example/benchmark/benchmark_app/lib/widgets/bench_widget.dart b/example/benchmark/benchmark_app/lib/widgets/bench_widget.dart index 84f94bcc..b1713eee 100644 --- a/example/benchmark/benchmark_app/lib/widgets/bench_widget.dart +++ b/example/benchmark/benchmark_app/lib/widgets/bench_widget.dart @@ -4,8 +4,6 @@ import "package:benchmark_app/widgets/collection_button.dart"; import "package:fast_immutable_collections_benchmarks/fast_immutable_collections_benchmarks.dart"; import "package:flutter/material.dart"; - - class BenchWidget extends StatefulWidget { final String title; final Map code; @@ -24,8 +22,6 @@ class BenchWidget extends StatefulWidget { _BenchWidgetState createState() => _BenchWidgetState(); } - - class _BenchWidgetState extends State { bool _isRunning = false; List? _results; @@ -126,10 +122,8 @@ class _BenchWidgetState extends State { } } - - class _PleaseWait extends StatelessWidget { - const _PleaseWait({Key? key}) : super(key: key); + const _PleaseWait({super.key}); @override Widget build(_) { @@ -156,5 +150,3 @@ class _PleaseWait extends StatelessWidget { ); } } - - diff --git a/example/benchmark/benchmark_app/lib/widgets/collection_button.dart b/example/benchmark/benchmark_app/lib/widgets/collection_button.dart index 0d4a8d5d..66abef3f 100644 --- a/example/benchmark/benchmark_app/lib/widgets/collection_button.dart +++ b/example/benchmark/benchmark_app/lib/widgets/collection_button.dart @@ -1,7 +1,5 @@ import "package:flutter/material.dart"; - - class CollectionButton extends StatelessWidget { final String label; final VoidCallback? onPressed; @@ -22,5 +20,3 @@ class CollectionButton extends StatelessWidget { ); } } - - diff --git a/example/benchmark/benchmark_app/lib/widgets/release_mode_warning.dart b/example/benchmark/benchmark_app/lib/widgets/release_mode_warning.dart index 488215a6..7e142646 100644 --- a/example/benchmark/benchmark_app/lib/widgets/release_mode_warning.dart +++ b/example/benchmark/benchmark_app/lib/widgets/release_mode_warning.dart @@ -1,8 +1,6 @@ import "package:flutter/foundation.dart"; import "package:flutter/material.dart"; - - class ReleaseModeWarning extends StatelessWidget { const ReleaseModeWarning(); @@ -28,5 +26,3 @@ class ReleaseModeWarning extends StatelessWidget { ); } } - - diff --git a/example/benchmark/lib/src/cases/list/add.dart b/example/benchmark/lib/src/cases/list/add.dart index 0077fd18..dbbf8286 100644 --- a/example/benchmark/lib/src/cases/list/add.dart +++ b/example/benchmark/lib/src/cases/list/add.dart @@ -6,28 +6,22 @@ import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:fast_immutable_collections_benchmarks/fast_immutable_collections_benchmarks.dart"; import "package:kt_dart/kt.dart"; - - class ListAddBenchmark extends MultiBenchmarkReporter { @override final List benchmarks; - ListAddBenchmark({required TableScoreEmitter emitter}) + ListAddBenchmark({required super.emitter}) : benchmarks = [ MutableListAddBenchmark(emitter: emitter), IListAddBenchmark(emitter: emitter), KtListAddBenchmark(emitter: emitter), BuiltListAddWithRebuildBenchmark(emitter: emitter), BuiltListAddWithListBuilderBenchmark(emitter: emitter), - ], - super(emitter: emitter); + ]; } - - class MutableListAddBenchmark extends ListBenchmarkBase { - MutableListAddBenchmark({required TableScoreEmitter emitter}) - : super(name: "List (Mutable)", emitter: emitter); + MutableListAddBenchmark({required super.emitter}) : super(name: "List (Mutable)"); late List list; @@ -65,10 +59,8 @@ class MutableListAddBenchmark extends ListBenchmarkBase { } } - - class IListAddBenchmark extends ListBenchmarkBase { - IListAddBenchmark({required TableScoreEmitter emitter}) : super(name: "IList", emitter: emitter); + IListAddBenchmark({required super.emitter}) : super(name: "IList"); late IList iList; late IList result; @@ -90,11 +82,8 @@ class IListAddBenchmark extends ListBenchmarkBase { } } - - class KtListAddBenchmark extends ListBenchmarkBase { - KtListAddBenchmark({required TableScoreEmitter emitter}) - : super(name: "KtList", emitter: emitter); + KtListAddBenchmark({required super.emitter}) : super(name: "KtList"); late KtList ktList; late KtList result; @@ -114,11 +103,8 @@ class KtListAddBenchmark extends ListBenchmarkBase { } } - - class BuiltListAddWithRebuildBenchmark extends ListBenchmarkBase { - BuiltListAddWithRebuildBenchmark({required TableScoreEmitter emitter}) - : super(name: "BuiltList (Rebuild)", emitter: emitter); + BuiltListAddWithRebuildBenchmark({required super.emitter}) : super(name: "BuiltList (Rebuild)"); late BuiltList builtList; late BuiltList result; @@ -139,11 +125,9 @@ class BuiltListAddWithRebuildBenchmark extends ListBenchmarkBase { } } - - class BuiltListAddWithListBuilderBenchmark extends ListBenchmarkBase { - BuiltListAddWithListBuilderBenchmark({required TableScoreEmitter emitter}) - : super(name: "BuiltList (ListBuilder)", emitter: emitter); + BuiltListAddWithListBuilderBenchmark({required super.emitter}) + : super(name: "BuiltList (ListBuilder)"); late BuiltList builtList; late BuiltList result; @@ -163,5 +147,3 @@ class BuiltListAddWithListBuilderBenchmark extends ListBenchmarkBase { result = listBuilder.build(); } } - - diff --git a/example/benchmark/lib/src/cases/list/add_all.dart b/example/benchmark/lib/src/cases/list/add_all.dart index 5063d6de..803193c9 100644 --- a/example/benchmark/lib/src/cases/list/add_all.dart +++ b/example/benchmark/lib/src/cases/list/add_all.dart @@ -6,27 +6,21 @@ import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:fast_immutable_collections_benchmarks/fast_immutable_collections_benchmarks.dart"; import "package:kt_dart/collection.dart"; - - class ListAddAllBenchmark extends MultiBenchmarkReporter { @override final List benchmarks; - ListAddAllBenchmark({required TableScoreEmitter emitter}) + ListAddAllBenchmark({required super.emitter}) : benchmarks = [ MutableListAddAllBenchmark(emitter: emitter), IListAddAllBenchmark(emitter: emitter), KtListAddAllBenchmark(emitter: emitter), BuiltListAddAllBenchmark(emitter: emitter), - ], - super(emitter: emitter); + ]; } - - class MutableListAddAllBenchmark extends ListBenchmarkBase { - MutableListAddAllBenchmark({required TableScoreEmitter emitter}) - : super(name: "List (Mutable)", emitter: emitter); + MutableListAddAllBenchmark({required super.emitter}) : super(name: "List (Mutable)"); late List list; @@ -63,11 +57,8 @@ class MutableListAddAllBenchmark extends ListBenchmarkBase { } } - - class IListAddAllBenchmark extends ListBenchmarkBase { - IListAddAllBenchmark({required TableScoreEmitter emitter}) - : super(name: "IList", emitter: emitter); + IListAddAllBenchmark({required super.emitter}) : super(name: "IList"); late IList iList; late IList result; @@ -83,11 +74,8 @@ class IListAddAllBenchmark extends ListBenchmarkBase { result = iList.addAll(ListBenchmarkBase.getDummyGeneratedList(size: config.size ~/ 10)); } - - class KtListAddAllBenchmark extends ListBenchmarkBase { - KtListAddAllBenchmark({required TableScoreEmitter emitter}) - : super(name: "KtList", emitter: emitter); + KtListAddAllBenchmark({required super.emitter}) : super(name: "KtList"); late KtList ktList; late KtList result; @@ -105,11 +93,8 @@ class KtListAddAllBenchmark extends ListBenchmarkBase { .plus(KtList.from(ListBenchmarkBase.getDummyGeneratedList(size: config.size ~/ 10))); } - - class BuiltListAddAllBenchmark extends ListBenchmarkBase { - BuiltListAddAllBenchmark({required TableScoreEmitter emitter}) - : super(name: "BuiltList", emitter: emitter); + BuiltListAddAllBenchmark({required super.emitter}) : super(name: "BuiltList"); late BuiltList builtList; late BuiltList result; @@ -125,5 +110,3 @@ class BuiltListAddAllBenchmark extends ListBenchmarkBase { void run() => result = builtList.rebuild((ListBuilder listBuilder) => listBuilder.addAll(ListBenchmarkBase.getDummyGeneratedList(size: config.size ~/ 10))); } - - diff --git a/example/benchmark/lib/src/cases/list/contains.dart b/example/benchmark/lib/src/cases/list/contains.dart index 67ab161f..9c7086ab 100644 --- a/example/benchmark/lib/src/cases/list/contains.dart +++ b/example/benchmark/lib/src/cases/list/contains.dart @@ -4,30 +4,23 @@ import "dart:math"; import "package:built_collection/built_collection.dart"; import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:fast_immutable_collections_benchmarks/src/utils/collection_benchmark_base.dart"; -import "package:fast_immutable_collections_benchmarks/src/utils/table_score_emitter.dart"; import "package:kt_dart/kt.dart"; - - class ListContainsBenchmark extends MultiBenchmarkReporter { @override final List benchmarks; - ListContainsBenchmark({required TableScoreEmitter emitter}) + ListContainsBenchmark({required super.emitter}) : benchmarks = [ MutableListContainsBenchmark(emitter: emitter), IListContainsBenchmark(emitter: emitter), KtListContainsBenchmark(emitter: emitter), BuiltListContainsBenchmark(emitter: emitter), - ], - super(emitter: emitter); + ]; } - - class MutableListContainsBenchmark extends ListBenchmarkBase { - MutableListContainsBenchmark({required TableScoreEmitter emitter}) - : super(name: "List (Mutable)", emitter: emitter); + MutableListContainsBenchmark({required super.emitter}) : super(name: "List (Mutable)"); late List list; late bool contains; @@ -65,11 +58,8 @@ class MutableListContainsBenchmark extends ListBenchmarkBase { } } - - class IListContainsBenchmark extends ListBenchmarkBase { - IListContainsBenchmark({required TableScoreEmitter emitter}) - : super(name: "IList", emitter: emitter); + IListContainsBenchmark({required super.emitter}) : super(name: "IList"); late IList _iList; late bool contains; @@ -86,11 +76,8 @@ class IListContainsBenchmark extends ListBenchmarkBase { } } - - class KtListContainsBenchmark extends ListBenchmarkBase { - KtListContainsBenchmark({required TableScoreEmitter emitter}) - : super(name: "KtList", emitter: emitter); + KtListContainsBenchmark({required super.emitter}) : super(name: "KtList"); late KtList _ktList; late bool contains; @@ -107,11 +94,8 @@ class KtListContainsBenchmark extends ListBenchmarkBase { } } - - class BuiltListContainsBenchmark extends ListBenchmarkBase { - BuiltListContainsBenchmark({required TableScoreEmitter emitter}) - : super(name: "BuiltList", emitter: emitter); + BuiltListContainsBenchmark({required super.emitter}) : super(name: "BuiltList"); late BuiltList _builtList; late bool contains; @@ -128,5 +112,3 @@ class BuiltListContainsBenchmark extends ListBenchmarkBase { for (int i = 0; i < _builtList.length + 1; i++) contains = _builtList.contains(i); } } - - diff --git a/example/benchmark/lib/src/cases/list/empty.dart b/example/benchmark/lib/src/cases/list/empty.dart index 94af7595..e0f1872f 100644 --- a/example/benchmark/lib/src/cases/list/empty.dart +++ b/example/benchmark/lib/src/cases/list/empty.dart @@ -2,30 +2,23 @@ import "package:built_collection/built_collection.dart"; import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:fast_immutable_collections_benchmarks/src/utils/collection_benchmark_base.dart"; -import "package:fast_immutable_collections_benchmarks/src/utils/table_score_emitter.dart"; import "package:kt_dart/collection.dart"; - - class ListEmptyBenchmark extends MultiBenchmarkReporter { @override final List benchmarks; - ListEmptyBenchmark({required TableScoreEmitter emitter}) + ListEmptyBenchmark({required super.emitter}) : benchmarks = [ MutableListEmptyBenchmark(emitter: emitter), IListEmptyBenchmark(emitter: emitter), KtListEmptyBenchmark(emitter: emitter), BuiltListEmptyBenchmark(emitter: emitter), - ], - super(emitter: emitter); + ]; } - - class MutableListEmptyBenchmark extends ListBenchmarkBase { - MutableListEmptyBenchmark({required TableScoreEmitter emitter}) - : super(name: "List (Mutable)", emitter: emitter); + MutableListEmptyBenchmark({required super.emitter}) : super(name: "List (Mutable)"); late List list; @@ -36,11 +29,8 @@ class MutableListEmptyBenchmark extends ListBenchmarkBase { void run() => list = []; } - - class IListEmptyBenchmark extends ListBenchmarkBase { - IListEmptyBenchmark({required TableScoreEmitter emitter}) - : super(name: "IList", emitter: emitter); + IListEmptyBenchmark({required super.emitter}) : super(name: "IList"); late IList iList; @@ -51,11 +41,8 @@ class IListEmptyBenchmark extends ListBenchmarkBase { void run() => iList = IList(); } - - class KtListEmptyBenchmark extends ListBenchmarkBase { - KtListEmptyBenchmark({required TableScoreEmitter emitter}) - : super(name: "KtList", emitter: emitter); + KtListEmptyBenchmark({required super.emitter}) : super(name: "KtList"); late KtList ktList; @@ -66,11 +53,8 @@ class KtListEmptyBenchmark extends ListBenchmarkBase { void run() => ktList = const KtList.empty(); } - - class BuiltListEmptyBenchmark extends ListBenchmarkBase { - BuiltListEmptyBenchmark({required TableScoreEmitter emitter}) - : super(name: "BuiltList", emitter: emitter); + BuiltListEmptyBenchmark({required super.emitter}) : super(name: "BuiltList"); late BuiltList builtList; @@ -80,5 +64,3 @@ class BuiltListEmptyBenchmark extends ListBenchmarkBase { @override void run() => builtList = BuiltList(); } - - diff --git a/example/benchmark/lib/src/cases/list/insert.dart b/example/benchmark/lib/src/cases/list/insert.dart index ba42c9a7..76e16b40 100644 --- a/example/benchmark/lib/src/cases/list/insert.dart +++ b/example/benchmark/lib/src/cases/list/insert.dart @@ -6,29 +6,23 @@ import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:fast_immutable_collections_benchmarks/fast_immutable_collections_benchmarks.dart"; import "package:kt_dart/kt.dart"; - - class ListInsertBenchmark extends MultiBenchmarkReporter { @override final List benchmarks; - ListInsertBenchmark({required TableScoreEmitter emitter, int? seed}) + ListInsertBenchmark({required super.emitter, int? seed}) : benchmarks = [ MutableListInsertBenchmark(emitter: emitter, seed: seed), IListInsertBenchmark(emitter: emitter, seed: seed), KtListInsertBenchmark(emitter: emitter, seed: seed), BuiltListInsertBenchmark(emitter: emitter, seed: seed), - ], - super(emitter: emitter); + ]; } - - class MutableListInsertBenchmark extends ListBenchmarkBase { final int? seed; - MutableListInsertBenchmark({required TableScoreEmitter emitter, this.seed}) - : super(name: "List (Mutable)", emitter: emitter); + MutableListInsertBenchmark({required super.emitter, this.seed}) : super(name: "List (Mutable)"); late List list; @@ -66,13 +60,10 @@ class MutableListInsertBenchmark extends ListBenchmarkBase { } } - - class IListInsertBenchmark extends ListBenchmarkBase { final int? seed; - IListInsertBenchmark({required TableScoreEmitter emitter, this.seed}) - : super(name: "IList", emitter: emitter); + IListInsertBenchmark({required super.emitter, this.seed}) : super(name: "IList"); late IList iList; late IList result; @@ -92,13 +83,10 @@ class IListInsertBenchmark extends ListBenchmarkBase { } } - - class KtListInsertBenchmark extends ListBenchmarkBase { final int? seed; - KtListInsertBenchmark({required TableScoreEmitter emitter, this.seed}) - : super(name: "KtList", emitter: emitter); + KtListInsertBenchmark({required super.emitter, this.seed}) : super(name: "KtList"); late KtList ktList; late KtList result; @@ -120,13 +108,10 @@ class KtListInsertBenchmark extends ListBenchmarkBase { } } - - class BuiltListInsertBenchmark extends ListBenchmarkBase { final int? seed; - BuiltListInsertBenchmark({required TableScoreEmitter emitter, this.seed}) - : super(name: "BuiltList", emitter: emitter); + BuiltListInsertBenchmark({required super.emitter, this.seed}) : super(name: "BuiltList"); late BuiltList builtList; late BuiltList result; @@ -146,5 +131,3 @@ class BuiltListInsertBenchmark extends ListBenchmarkBase { result = listBuilder.build(); } } - - diff --git a/example/benchmark/lib/src/cases/list/read.dart b/example/benchmark/lib/src/cases/list/read.dart index e60ea0a0..d9025e2e 100644 --- a/example/benchmark/lib/src/cases/list/read.dart +++ b/example/benchmark/lib/src/cases/list/read.dart @@ -2,30 +2,23 @@ import "package:built_collection/built_collection.dart"; import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:fast_immutable_collections_benchmarks/src/utils/collection_benchmark_base.dart"; -import "package:fast_immutable_collections_benchmarks/src/utils/table_score_emitter.dart"; import "package:kt_dart/kt.dart"; - - class ListReadBenchmark extends MultiBenchmarkReporter { @override final List benchmarks; - ListReadBenchmark({required TableScoreEmitter emitter}) + ListReadBenchmark({required super.emitter}) : benchmarks = [ MutableListReadBenchmark(emitter: emitter), IListReadBenchmark(emitter: emitter), KtListReadBenchmark(emitter: emitter), BuiltListReadBenchmark(emitter: emitter), - ], - super(emitter: emitter); + ]; } - - class MutableListReadBenchmark extends ListBenchmarkBase { - MutableListReadBenchmark({required TableScoreEmitter emitter}) - : super(name: "List (Mutable)", emitter: emitter); + MutableListReadBenchmark({required super.emitter}) : super(name: "List (Mutable)"); late List list; late int newVar; @@ -40,10 +33,8 @@ class MutableListReadBenchmark extends ListBenchmarkBase { void run() => newVar = list[config.size ~/ 2]; } - - class IListReadBenchmark extends ListBenchmarkBase { - IListReadBenchmark({required TableScoreEmitter emitter}) : super(name: "IList", emitter: emitter); + IListReadBenchmark({required super.emitter}) : super(name: "IList"); late IList iList; late int newVar; @@ -58,11 +49,8 @@ class IListReadBenchmark extends ListBenchmarkBase { void run() => newVar = iList[config.size ~/ 2]; } - - class KtListReadBenchmark extends ListBenchmarkBase { - KtListReadBenchmark({required TableScoreEmitter emitter}) - : super(name: "KtList", emitter: emitter); + KtListReadBenchmark({required super.emitter}) : super(name: "KtList"); late KtList ktList; late int newVar; @@ -78,11 +66,8 @@ class KtListReadBenchmark extends ListBenchmarkBase { void run() => newVar = ktList[config.size ~/ 2]; } - - class BuiltListReadBenchmark extends ListBenchmarkBase { - BuiltListReadBenchmark({required TableScoreEmitter emitter}) - : super(name: "BuiltList", emitter: emitter); + BuiltListReadBenchmark({required super.emitter}) : super(name: "BuiltList"); late BuiltList builtList; late int newVar; @@ -97,5 +82,3 @@ class BuiltListReadBenchmark extends ListBenchmarkBase { @override void run() => newVar = builtList[config.size ~/ 2]; } - - diff --git a/example/benchmark/lib/src/cases/list/remove.dart b/example/benchmark/lib/src/cases/list/remove.dart index b8cd597f..9890df82 100644 --- a/example/benchmark/lib/src/cases/list/remove.dart +++ b/example/benchmark/lib/src/cases/list/remove.dart @@ -4,30 +4,23 @@ import "dart:math"; import "package:built_collection/built_collection.dart"; import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:fast_immutable_collections_benchmarks/src/utils/collection_benchmark_base.dart"; -import "package:fast_immutable_collections_benchmarks/src/utils/table_score_emitter.dart"; import "package:kt_dart/collection.dart"; - - class ListRemoveBenchmark extends MultiBenchmarkReporter { @override final List benchmarks; - ListRemoveBenchmark({required TableScoreEmitter emitter}) + ListRemoveBenchmark({required super.emitter}) : benchmarks = [ MutableListRemoveBenchmark(emitter: emitter), IListRemoveBenchmark(emitter: emitter), KtListRemoveBenchmark(emitter: emitter), BuiltListRemoveBenchmark(emitter: emitter), - ], - super(emitter: emitter); + ]; } - - class MutableListRemoveBenchmark extends ListBenchmarkBase { - MutableListRemoveBenchmark({required TableScoreEmitter emitter}) - : super(name: "List (Mutable)", emitter: emitter); + MutableListRemoveBenchmark({required super.emitter}) : super(name: "List (Mutable)"); late List list; @@ -64,11 +57,8 @@ class MutableListRemoveBenchmark extends ListBenchmarkBase { } } - - class IListRemoveBenchmark extends ListBenchmarkBase { - IListRemoveBenchmark({required TableScoreEmitter emitter}) - : super(name: "IList", emitter: emitter); + IListRemoveBenchmark({required super.emitter}) : super(name: "IList"); late IList iList; @@ -82,11 +72,8 @@ class IListRemoveBenchmark extends ListBenchmarkBase { void run() => iList = iList.remove(config.size ~/ 2); } - - class KtListRemoveBenchmark extends ListBenchmarkBase { - KtListRemoveBenchmark({required TableScoreEmitter emitter}) - : super(name: "KtList", emitter: emitter); + KtListRemoveBenchmark({required super.emitter}) : super(name: "KtList"); late KtList ktList; @@ -101,11 +88,8 @@ class KtListRemoveBenchmark extends ListBenchmarkBase { void run() => ktList = ktList.minusElement(config.size ~/ 2); } - - class BuiltListRemoveBenchmark extends ListBenchmarkBase { - BuiltListRemoveBenchmark({required TableScoreEmitter emitter}) - : super(name: "BuiltList", emitter: emitter); + BuiltListRemoveBenchmark({required super.emitter}) : super(name: "BuiltList"); late BuiltList builtList; @@ -120,5 +104,3 @@ class BuiltListRemoveBenchmark extends ListBenchmarkBase { void run() => builtList = builtList.rebuild((ListBuilder listBuilder) => listBuilder.remove(config.size ~/ 2)); } - - diff --git a/example/benchmark/lib/src/cases/map/add.dart b/example/benchmark/lib/src/cases/map/add.dart index fd878f89..030890d1 100644 --- a/example/benchmark/lib/src/cases/map/add.dart +++ b/example/benchmark/lib/src/cases/map/add.dart @@ -4,31 +4,24 @@ import "dart:math"; import "package:built_collection/built_collection.dart"; import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:fast_immutable_collections_benchmarks/src/utils/collection_benchmark_base.dart"; -import "package:fast_immutable_collections_benchmarks/src/utils/table_score_emitter.dart"; import "package:kt_dart/kt.dart"; - - class MapAddBenchmark extends MultiBenchmarkReporter { @override final List benchmarks; - MapAddBenchmark({required TableScoreEmitter emitter}) + MapAddBenchmark({required super.emitter}) : benchmarks = [ MutableMapAddBenchmark(emitter: emitter), IMapAddBenchmark(emitter: emitter), KtMapAddBenchmark(emitter: emitter), BuiltMapAddWithRebuildBenchmark(emitter: emitter), BuiltMapAddWithListBuilderBenchmark(emitter: emitter), - ], - super(emitter: emitter); + ]; } - - class MutableMapAddBenchmark extends MapBenchmarkBase { - MutableMapAddBenchmark({required TableScoreEmitter emitter}) - : super(name: "Map (Mutable)", emitter: emitter); + MutableMapAddBenchmark({required super.emitter}) : super(name: "Map (Mutable)"); late Map map; @@ -64,10 +57,8 @@ class MutableMapAddBenchmark extends MapBenchmarkBase { } } - - class IMapAddBenchmark extends MapBenchmarkBase { - IMapAddBenchmark({required TableScoreEmitter emitter}) : super(name: "IMap", emitter: emitter); + IMapAddBenchmark({required super.emitter}) : super(name: "IMap"); late IMap iMap; late IMap result; @@ -90,10 +81,8 @@ class IMapAddBenchmark extends MapBenchmarkBase { } } - - class KtMapAddBenchmark extends MapBenchmarkBase { - KtMapAddBenchmark({required TableScoreEmitter emitter}) : super(name: "KtMap", emitter: emitter); + KtMapAddBenchmark({required super.emitter}) : super(name: "KtMap"); late KtMap ktMap; late KtMap result; @@ -113,11 +102,8 @@ class KtMapAddBenchmark extends MapBenchmarkBase { } } - - class BuiltMapAddWithRebuildBenchmark extends MapBenchmarkBase { - BuiltMapAddWithRebuildBenchmark({required TableScoreEmitter emitter}) - : super(name: "BuiltMap (Rebuild)", emitter: emitter); + BuiltMapAddWithRebuildBenchmark({required super.emitter}) : super(name: "BuiltMap (Rebuild)"); late BuiltMap builtMap; late BuiltMap result; @@ -139,11 +125,9 @@ class BuiltMapAddWithRebuildBenchmark extends MapBenchmarkBase { } } - - class BuiltMapAddWithListBuilderBenchmark extends MapBenchmarkBase { - BuiltMapAddWithListBuilderBenchmark({required TableScoreEmitter emitter}) - : super(name: "BuiltMap (ListBuilder)", emitter: emitter); + BuiltMapAddWithListBuilderBenchmark({required super.emitter}) + : super(name: "BuiltMap (ListBuilder)"); late BuiltMap builtMap; late BuiltMap result; @@ -164,5 +148,3 @@ class BuiltMapAddWithListBuilderBenchmark extends MapBenchmarkBase { result = mapBuilder.build(); } } - - diff --git a/example/benchmark/lib/src/cases/map/add_all.dart b/example/benchmark/lib/src/cases/map/add_all.dart index 082496f5..97417b43 100644 --- a/example/benchmark/lib/src/cases/map/add_all.dart +++ b/example/benchmark/lib/src/cases/map/add_all.dart @@ -4,30 +4,23 @@ import "dart:math"; import "package:built_collection/built_collection.dart"; import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:fast_immutable_collections_benchmarks/src/utils/collection_benchmark_base.dart"; -import "package:fast_immutable_collections_benchmarks/src/utils/table_score_emitter.dart"; import "package:kt_dart/kt.dart"; - - class MapAddAllBenchmark extends MultiBenchmarkReporter { @override final List benchmarks; - MapAddAllBenchmark({required TableScoreEmitter emitter}) + MapAddAllBenchmark({required super.emitter}) : benchmarks = [ MutableMapAddAllBenchmark(emitter: emitter), IMapAddAllBenchmark(emitter: emitter), KtMapAddAllBenchmark(emitter: emitter), BuiltMapAddAllBenchmark(emitter: emitter), - ], - super(emitter: emitter); + ]; } - - class MutableMapAddAllBenchmark extends MapBenchmarkBase { - MutableMapAddAllBenchmark({required TableScoreEmitter emitter}) - : super(name: "Map (Mutable)", emitter: emitter); + MutableMapAddAllBenchmark({required super.emitter}) : super(name: "Map (Mutable)"); late Map map; late Map toBeAdded; @@ -64,10 +57,8 @@ class MutableMapAddAllBenchmark extends MapBenchmarkBase { } } - - class IMapAddAllBenchmark extends MapBenchmarkBase { - IMapAddAllBenchmark({required TableScoreEmitter emitter}) : super(name: "IMap", emitter: emitter); + IMapAddAllBenchmark({required super.emitter}) : super(name: "IMap"); late IMap iMap; late IMap result; @@ -86,11 +77,8 @@ class IMapAddAllBenchmark extends MapBenchmarkBase { void run() => result = iMap.addAll(toBeAdded); } - - class KtMapAddAllBenchmark extends MapBenchmarkBase { - KtMapAddAllBenchmark({required TableScoreEmitter emitter}) - : super(name: "KtMap", emitter: emitter); + KtMapAddAllBenchmark({required super.emitter}) : super(name: "KtMap"); late KtMap ktMap; late KtMap result; @@ -110,11 +98,8 @@ class KtMapAddAllBenchmark extends MapBenchmarkBase { void run() => result = ktMap.plus(toBeAdded); } - - class BuiltMapAddAllBenchmark extends MapBenchmarkBase { - BuiltMapAddAllBenchmark({required TableScoreEmitter emitter}) - : super(name: "BuiltMap", emitter: emitter); + BuiltMapAddAllBenchmark({required super.emitter}) : super(name: "BuiltMap"); late BuiltMap builtMap; late BuiltMap result; @@ -134,5 +119,3 @@ class BuiltMapAddAllBenchmark extends MapBenchmarkBase { void run() => result = builtMap .rebuild((MapBuilder mapBuilder) => mapBuilder.addAll(toBeAdded.asMap())); } - - diff --git a/example/benchmark/lib/src/cases/map/contains_value.dart b/example/benchmark/lib/src/cases/map/contains_value.dart index 61e01d1c..2bb1ba59 100644 --- a/example/benchmark/lib/src/cases/map/contains_value.dart +++ b/example/benchmark/lib/src/cases/map/contains_value.dart @@ -2,30 +2,23 @@ import "package:built_collection/built_collection.dart"; import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:fast_immutable_collections_benchmarks/src/utils/collection_benchmark_base.dart"; -import "package:fast_immutable_collections_benchmarks/src/utils/table_score_emitter.dart"; import "package:kt_dart/kt.dart"; - - class MapContainsValueBenchmark extends MultiBenchmarkReporter { @override final List benchmarks; - MapContainsValueBenchmark({required TableScoreEmitter emitter}) + MapContainsValueBenchmark({required super.emitter}) : benchmarks = [ MutableMapContainsValueBenchmark(emitter: emitter), IMapContainsValueBenchmark(emitter: emitter), KtMapContainsValueBenchmark(emitter: emitter), BuiltMapContainsValueBenchmark(emitter: emitter), - ], - super(emitter: emitter); + ]; } - - class MutableMapContainsValueBenchmark extends MapBenchmarkBase { - MutableMapContainsValueBenchmark({required TableScoreEmitter emitter}) - : super(name: "Map (Mutable)", emitter: emitter); + MutableMapContainsValueBenchmark({required super.emitter}) : super(name: "Map (Mutable)"); late Map map; late bool contains; @@ -42,11 +35,8 @@ class MutableMapContainsValueBenchmark extends MapBenchmarkBase { } } - - class IMapContainsValueBenchmark extends MapBenchmarkBase { - IMapContainsValueBenchmark({required TableScoreEmitter emitter}) - : super(name: "IMap", emitter: emitter); + IMapContainsValueBenchmark({required super.emitter}) : super(name: "IMap"); late IMap iMap; late bool contains; @@ -64,11 +54,8 @@ class IMapContainsValueBenchmark extends MapBenchmarkBase { } } - - class KtMapContainsValueBenchmark extends MapBenchmarkBase { - KtMapContainsValueBenchmark({required TableScoreEmitter emitter}) - : super(name: "KtMap", emitter: emitter); + KtMapContainsValueBenchmark({required super.emitter}) : super(name: "KtMap"); late KtMap ktMap; late bool contains; @@ -85,11 +72,8 @@ class KtMapContainsValueBenchmark extends MapBenchmarkBase { } } - - class BuiltMapContainsValueBenchmark extends MapBenchmarkBase { - BuiltMapContainsValueBenchmark({required TableScoreEmitter emitter}) - : super(name: "BuiltMap", emitter: emitter); + BuiltMapContainsValueBenchmark({required super.emitter}) : super(name: "BuiltMap"); late BuiltMap builtMap; late bool contains; @@ -106,5 +90,3 @@ class BuiltMapContainsValueBenchmark extends MapBenchmarkBase { for (int i = 0; i < builtMap.length + 1; i++) contains = builtMap.containsValue(i); } } - - diff --git a/example/benchmark/lib/src/cases/map/empty.dart b/example/benchmark/lib/src/cases/map/empty.dart index c814c153..77134f06 100644 --- a/example/benchmark/lib/src/cases/map/empty.dart +++ b/example/benchmark/lib/src/cases/map/empty.dart @@ -2,30 +2,23 @@ import "package:built_collection/built_collection.dart"; import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:fast_immutable_collections_benchmarks/src/utils/collection_benchmark_base.dart"; -import "package:fast_immutable_collections_benchmarks/src/utils/table_score_emitter.dart"; import "package:kt_dart/collection.dart"; - - class MapEmptyBenchmark extends MultiBenchmarkReporter { @override final List benchmarks; - MapEmptyBenchmark({required TableScoreEmitter emitter}) + MapEmptyBenchmark({required super.emitter}) : benchmarks = [ MutableMapEmptyBenchmark(emitter: emitter), IMapEmptyBenchmark(emitter: emitter), KtMapEmptyBenchmark(emitter: emitter), BuiltMapEmptyBenchmark(emitter: emitter), - ], - super(emitter: emitter); + ]; } - - class MutableMapEmptyBenchmark extends MapBenchmarkBase { - MutableMapEmptyBenchmark({required TableScoreEmitter emitter}) - : super(name: "Map (Mutable)", emitter: emitter); + MutableMapEmptyBenchmark({required super.emitter}) : super(name: "Map (Mutable)"); late Map map; @@ -36,10 +29,8 @@ class MutableMapEmptyBenchmark extends MapBenchmarkBase { void run() => map = {}; } - - class IMapEmptyBenchmark extends MapBenchmarkBase { - IMapEmptyBenchmark({required TableScoreEmitter emitter}) : super(name: "IMap", emitter: emitter); + IMapEmptyBenchmark({required super.emitter}) : super(name: "IMap"); late IMap iMap; @@ -50,11 +41,8 @@ class IMapEmptyBenchmark extends MapBenchmarkBase { void run() => iMap = IMap(); } - - class KtMapEmptyBenchmark extends MapBenchmarkBase { - KtMapEmptyBenchmark({required TableScoreEmitter emitter}) - : super(name: "KtMap", emitter: emitter); + KtMapEmptyBenchmark({required super.emitter}) : super(name: "KtMap"); late KtMap ktMap; @@ -65,11 +53,8 @@ class KtMapEmptyBenchmark extends MapBenchmarkBase { void run() => ktMap = const KtMap.empty(); } - - class BuiltMapEmptyBenchmark extends MapBenchmarkBase { - BuiltMapEmptyBenchmark({required TableScoreEmitter emitter}) - : super(name: "BuiltMap", emitter: emitter); + BuiltMapEmptyBenchmark({required super.emitter}) : super(name: "BuiltMap"); late BuiltMap builtMap; @@ -79,5 +64,3 @@ class BuiltMapEmptyBenchmark extends MapBenchmarkBase { @override void run() => builtMap = BuiltMap(); } - - diff --git a/example/benchmark/lib/src/cases/map/read.dart b/example/benchmark/lib/src/cases/map/read.dart index 0a727b3e..dda5eb12 100644 --- a/example/benchmark/lib/src/cases/map/read.dart +++ b/example/benchmark/lib/src/cases/map/read.dart @@ -2,30 +2,23 @@ import "package:built_collection/built_collection.dart"; import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:fast_immutable_collections_benchmarks/src/utils/collection_benchmark_base.dart"; -import "package:fast_immutable_collections_benchmarks/src/utils/table_score_emitter.dart"; import "package:kt_dart/kt.dart"; - - class MapReadBenchmark extends MultiBenchmarkReporter { @override final List benchmarks; - MapReadBenchmark({required TableScoreEmitter emitter}) + MapReadBenchmark({required super.emitter}) : benchmarks = [ MutableMapReadBenchmark(emitter: emitter), IMapReadBenchmark(emitter: emitter), KtMapReadBenchmark(emitter: emitter), BuiltMapReadBenchmark(emitter: emitter), - ], - super(emitter: emitter); + ]; } - - class MutableMapReadBenchmark extends MapBenchmarkBase { - MutableMapReadBenchmark({required TableScoreEmitter emitter}) - : super(name: "Map (Mutable)", emitter: emitter); + MutableMapReadBenchmark({required super.emitter}) : super(name: "Map (Mutable)"); late Map _map; late int newVar; @@ -40,10 +33,8 @@ class MutableMapReadBenchmark extends MapBenchmarkBase { void run() => newVar = _map[(config.size ~/ 2).toString()]!; } - - class IMapReadBenchmark extends MapBenchmarkBase { - IMapReadBenchmark({required TableScoreEmitter emitter}) : super(name: "IMap", emitter: emitter); + IMapReadBenchmark({required super.emitter}) : super(name: "IMap"); late IMap iMap; late int newVar; @@ -58,10 +49,8 @@ class IMapReadBenchmark extends MapBenchmarkBase { void run() => newVar = iMap[(config.size ~/ 2).toString()]!; } - - class KtMapReadBenchmark extends MapBenchmarkBase { - KtMapReadBenchmark({required TableScoreEmitter emitter}) : super(name: "KtMap", emitter: emitter); + KtMapReadBenchmark({required super.emitter}) : super(name: "KtMap"); late KtMap ktMap; late int newVar; @@ -77,11 +66,8 @@ class KtMapReadBenchmark extends MapBenchmarkBase { void run() => newVar = ktMap[(config.size ~/ 2).toString()]!; } - - class BuiltMapReadBenchmark extends MapBenchmarkBase { - BuiltMapReadBenchmark({required TableScoreEmitter emitter}) - : super(name: "BuiltMap", emitter: emitter); + BuiltMapReadBenchmark({required super.emitter}) : super(name: "BuiltMap"); late BuiltMap builtMap; late int newVar; @@ -96,5 +82,3 @@ class BuiltMapReadBenchmark extends MapBenchmarkBase { @override void run() => newVar = builtMap[(config.size ~/ 2).toString()]!; } - - diff --git a/example/benchmark/lib/src/cases/map/remove.dart b/example/benchmark/lib/src/cases/map/remove.dart index 28a97c8e..acfbaef1 100644 --- a/example/benchmark/lib/src/cases/map/remove.dart +++ b/example/benchmark/lib/src/cases/map/remove.dart @@ -6,29 +6,22 @@ import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:kt_dart/collection.dart"; import "../../utils/collection_benchmark_base.dart"; -import "../../utils/table_score_emitter.dart"; - - class MapRemoveBenchmark extends MultiBenchmarkReporter { @override final List benchmarks; - MapRemoveBenchmark({required TableScoreEmitter emitter}) + MapRemoveBenchmark({required super.emitter}) : benchmarks = [ MutableMapRemoveBenchmark(emitter: emitter), IMapRemoveBenchmark(emitter: emitter), KtMapRemoveBenchmark(emitter: emitter), BuiltMapMapRemoveBenchmark(emitter: emitter), - ], - super(emitter: emitter); + ]; } - - class MutableMapRemoveBenchmark extends MapBenchmarkBase { - MutableMapRemoveBenchmark({required TableScoreEmitter emitter}) - : super(name: "Map (Mutable)", emitter: emitter); + MutableMapRemoveBenchmark({required super.emitter}) : super(name: "Map (Mutable)"); late Map map; @@ -63,10 +56,8 @@ class MutableMapRemoveBenchmark extends MapBenchmarkBase { } } - - class IMapRemoveBenchmark extends MapBenchmarkBase { - IMapRemoveBenchmark({required TableScoreEmitter emitter}) : super(name: "IMap", emitter: emitter); + IMapRemoveBenchmark({required super.emitter}) : super(name: "IMap"); late IMap iMap; @@ -81,11 +72,8 @@ class IMapRemoveBenchmark extends MapBenchmarkBase { void run() => iMap = iMap.remove((config.size ~/ 2).toString()); } - - class KtMapRemoveBenchmark extends MapBenchmarkBase { - KtMapRemoveBenchmark({required TableScoreEmitter emitter}) - : super(name: "KtMap", emitter: emitter); + KtMapRemoveBenchmark({required super.emitter}) : super(name: "KtMap"); late KtMap ktMap; @@ -100,11 +88,8 @@ class KtMapRemoveBenchmark extends MapBenchmarkBase { void run() => ktMap = ktMap.minus((config.size ~/ 2).toString()); } - - class BuiltMapMapRemoveBenchmark extends MapBenchmarkBase { - BuiltMapMapRemoveBenchmark({required TableScoreEmitter emitter}) - : super(name: "BuiltMap", emitter: emitter); + BuiltMapMapRemoveBenchmark({required super.emitter}) : super(name: "BuiltMap"); late BuiltMap builtMap; @@ -119,5 +104,3 @@ class BuiltMapMapRemoveBenchmark extends MapBenchmarkBase { void run() => builtMap = builtMap.rebuild( (MapBuilder mapBuilder) => mapBuilder.remove((config.size ~/ 2).toString())); } - - diff --git a/example/benchmark/lib/src/cases/set/add.dart b/example/benchmark/lib/src/cases/set/add.dart index c6fb4b37..2a6dcf5c 100644 --- a/example/benchmark/lib/src/cases/set/add.dart +++ b/example/benchmark/lib/src/cases/set/add.dart @@ -6,28 +6,22 @@ import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:fast_immutable_collections_benchmarks/fast_immutable_collections_benchmarks.dart"; import "package:kt_dart/kt.dart"; - - class SetAddBenchmark extends MultiBenchmarkReporter { @override final List benchmarks; - SetAddBenchmark({required TableScoreEmitter emitter}) + SetAddBenchmark({required super.emitter}) : benchmarks = [ MutableSetAddBenchmark(emitter: emitter), ISetAddBenchmark(emitter: emitter), KtSetAddBenchmark(emitter: emitter), BuiltSetAddWithRebuildBenchmark(emitter: emitter), BuiltSetAddWithSetBuilderBenchmark(emitter: emitter), - ], - super(emitter: emitter); + ]; } - - class MutableSetAddBenchmark extends SetBenchmarkBase { - MutableSetAddBenchmark({required TableScoreEmitter emitter}) - : super(name: "Set (Mutable)", emitter: emitter); + MutableSetAddBenchmark({required super.emitter}) : super(name: "Set (Mutable)"); late Set set; @@ -65,10 +59,8 @@ class MutableSetAddBenchmark extends SetBenchmarkBase { } } - - class ISetAddBenchmark extends SetBenchmarkBase { - ISetAddBenchmark({required TableScoreEmitter emitter}) : super(name: "ISet", emitter: emitter); + ISetAddBenchmark({required super.emitter}) : super(name: "ISet"); late ISet iSet; late ISet result; @@ -90,10 +82,8 @@ class ISetAddBenchmark extends SetBenchmarkBase { } } - - class KtSetAddBenchmark extends SetBenchmarkBase { - KtSetAddBenchmark({required TableScoreEmitter emitter}) : super(name: "KtSet", emitter: emitter); + KtSetAddBenchmark({required super.emitter}) : super(name: "KtSet"); late KtSet ktSet; late KtSet result; @@ -115,11 +105,8 @@ class KtSetAddBenchmark extends SetBenchmarkBase { } } - - class BuiltSetAddWithRebuildBenchmark extends SetBenchmarkBase { - BuiltSetAddWithRebuildBenchmark({required TableScoreEmitter emitter}) - : super(name: "BuiltSet (Rebuild)", emitter: emitter); + BuiltSetAddWithRebuildBenchmark({required super.emitter}) : super(name: "BuiltSet (Rebuild)"); late BuiltSet builtSet; late BuiltSet result; @@ -142,11 +129,9 @@ class BuiltSetAddWithRebuildBenchmark extends SetBenchmarkBase { } } - - class BuiltSetAddWithSetBuilderBenchmark extends SetBenchmarkBase { - BuiltSetAddWithSetBuilderBenchmark({required TableScoreEmitter emitter}) - : super(name: "BuiltSet (ListBuilder)", emitter: emitter); + BuiltSetAddWithSetBuilderBenchmark({required super.emitter}) + : super(name: "BuiltSet (ListBuilder)"); late BuiltSet builtSet; late BuiltSet result; @@ -168,5 +153,3 @@ class BuiltSetAddWithSetBuilderBenchmark extends SetBenchmarkBase { result = setBuilder.build(); } } - - diff --git a/example/benchmark/lib/src/cases/set/add_all.dart b/example/benchmark/lib/src/cases/set/add_all.dart index 529467fa..e24ca0b4 100644 --- a/example/benchmark/lib/src/cases/set/add_all.dart +++ b/example/benchmark/lib/src/cases/set/add_all.dart @@ -4,30 +4,23 @@ import "dart:math"; import "package:built_collection/built_collection.dart"; import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:fast_immutable_collections_benchmarks/src/utils/collection_benchmark_base.dart"; -import "package:fast_immutable_collections_benchmarks/src/utils/table_score_emitter.dart"; import "package:kt_dart/collection.dart"; - - class SetAddAllBenchmark extends MultiBenchmarkReporter { @override final List benchmarks; - SetAddAllBenchmark({required TableScoreEmitter emitter}) + SetAddAllBenchmark({required super.emitter}) : benchmarks = [ MutableSetAddAllBenchmark(emitter: emitter), ISetAddAllBenchmark(emitter: emitter), KtSetAddAllBenchmark(emitter: emitter), BuiltSetAddAllBenchmark(emitter: emitter), - ], - super(emitter: emitter); + ]; } - - class MutableSetAddAllBenchmark extends SetBenchmarkBase { - MutableSetAddAllBenchmark({required TableScoreEmitter emitter}) - : super(name: "Set (Mutable)", emitter: emitter); + MutableSetAddAllBenchmark({required super.emitter}) : super(name: "Set (Mutable)"); late Set set; late Set toBeAdded; @@ -61,10 +54,8 @@ class MutableSetAddAllBenchmark extends SetBenchmarkBase { } } - - class ISetAddAllBenchmark extends SetBenchmarkBase { - ISetAddAllBenchmark({required TableScoreEmitter emitter}) : super(name: "ISet", emitter: emitter); + ISetAddAllBenchmark({required super.emitter}) : super(name: "ISet"); late ISet iSet; late ISet toBeAdded; @@ -86,11 +77,8 @@ class ISetAddAllBenchmark extends SetBenchmarkBase { } } - - class KtSetAddAllBenchmark extends SetBenchmarkBase { - KtSetAddAllBenchmark({required TableScoreEmitter emitter}) - : super(name: "KtSet", emitter: emitter); + KtSetAddAllBenchmark({required super.emitter}) : super(name: "KtSet"); late KtSet ktSet; late KtSet toBeAdded; @@ -113,11 +101,8 @@ class KtSetAddAllBenchmark extends SetBenchmarkBase { } } - - class BuiltSetAddAllBenchmark extends SetBenchmarkBase { - BuiltSetAddAllBenchmark({required TableScoreEmitter emitter}) - : super(name: "BuiltSet", emitter: emitter); + BuiltSetAddAllBenchmark({required super.emitter}) : super(name: "BuiltSet"); late BuiltSet builtSet; late BuiltSet toBeAdded; @@ -138,5 +123,3 @@ class BuiltSetAddAllBenchmark extends SetBenchmarkBase { builtSet = fixedISet.rebuild((SetBuilder setBuilder) => setBuilder.addAll(toBeAdded)); } } - - diff --git a/example/benchmark/lib/src/cases/set/contains.dart b/example/benchmark/lib/src/cases/set/contains.dart index 13d13758..4861a25f 100644 --- a/example/benchmark/lib/src/cases/set/contains.dart +++ b/example/benchmark/lib/src/cases/set/contains.dart @@ -2,30 +2,23 @@ import "package:built_collection/built_collection.dart"; import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:fast_immutable_collections_benchmarks/src/utils/collection_benchmark_base.dart"; -import "package:fast_immutable_collections_benchmarks/src/utils/table_score_emitter.dart"; import "package:kt_dart/collection.dart"; - - class SetContainsBenchmark extends MultiBenchmarkReporter { @override final List benchmarks; - SetContainsBenchmark({required TableScoreEmitter emitter}) + SetContainsBenchmark({required super.emitter}) : benchmarks = [ MutableSetContainsBenchmark(emitter: emitter), ISetContainsBenchmark(emitter: emitter), KtSetContainsBenchmark(emitter: emitter), BuiltSetContainsBenchmark(emitter: emitter), - ], - super(emitter: emitter); + ]; } - - class MutableSetContainsBenchmark extends SetBenchmarkBase { - MutableSetContainsBenchmark({required TableScoreEmitter emitter}) - : super(name: "Set (Mutable)", emitter: emitter); + MutableSetContainsBenchmark({required super.emitter}) : super(name: "Set (Mutable)"); late Set set; late bool contains; @@ -42,11 +35,8 @@ class MutableSetContainsBenchmark extends SetBenchmarkBase { } } - - class ISetContainsBenchmark extends SetBenchmarkBase { - ISetContainsBenchmark({required TableScoreEmitter emitter}) - : super(name: "ISet", emitter: emitter); + ISetContainsBenchmark({required super.emitter}) : super(name: "ISet"); late ISet iSet; late bool contains; @@ -63,11 +53,8 @@ class ISetContainsBenchmark extends SetBenchmarkBase { } } - - class KtSetContainsBenchmark extends SetBenchmarkBase { - KtSetContainsBenchmark({required TableScoreEmitter emitter}) - : super(name: "KtSet", emitter: emitter); + KtSetContainsBenchmark({required super.emitter}) : super(name: "KtSet"); late KtSet ktSet; late bool contains; @@ -84,11 +71,8 @@ class KtSetContainsBenchmark extends SetBenchmarkBase { } } - - class BuiltSetContainsBenchmark extends SetBenchmarkBase { - BuiltSetContainsBenchmark({required TableScoreEmitter emitter}) - : super(name: "BuiltSet", emitter: emitter); + BuiltSetContainsBenchmark({required super.emitter}) : super(name: "BuiltSet"); late BuiltSet builtSet; late bool contains; @@ -105,5 +89,3 @@ class BuiltSetContainsBenchmark extends SetBenchmarkBase { for (int i = 0; i < builtSet.length + 1; i++) contains = builtSet.contains(i); } } - - diff --git a/example/benchmark/lib/src/cases/set/empty.dart b/example/benchmark/lib/src/cases/set/empty.dart index b051d6c5..167cd837 100644 --- a/example/benchmark/lib/src/cases/set/empty.dart +++ b/example/benchmark/lib/src/cases/set/empty.dart @@ -2,30 +2,23 @@ import "package:built_collection/built_collection.dart"; import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:fast_immutable_collections_benchmarks/src/utils/collection_benchmark_base.dart"; -import "package:fast_immutable_collections_benchmarks/src/utils/table_score_emitter.dart"; import "package:kt_dart/collection.dart"; - - class SetEmptyBenchmark extends MultiBenchmarkReporter { @override final List benchmarks; - SetEmptyBenchmark({required TableScoreEmitter emitter}) + SetEmptyBenchmark({required super.emitter}) : benchmarks = [ MutableSetEmptyBenchmark(emitter: emitter), ISetEmptyBenchmark(emitter: emitter), KtSetEmptyBenchmark(emitter: emitter), BuiltSetEmptyBenchmark(emitter: emitter), - ], - super(emitter: emitter); + ]; } - - class MutableSetEmptyBenchmark extends SetBenchmarkBase { - MutableSetEmptyBenchmark({required TableScoreEmitter emitter}) - : super(name: "Set (Mutable)", emitter: emitter); + MutableSetEmptyBenchmark({required super.emitter}) : super(name: "Set (Mutable)"); late Set set; @@ -36,10 +29,8 @@ class MutableSetEmptyBenchmark extends SetBenchmarkBase { void run() => set = {}; } - - class ISetEmptyBenchmark extends SetBenchmarkBase { - ISetEmptyBenchmark({required TableScoreEmitter emitter}) : super(name: "ISet", emitter: emitter); + ISetEmptyBenchmark({required super.emitter}) : super(name: "ISet"); late ISet iSet; @@ -50,11 +41,8 @@ class ISetEmptyBenchmark extends SetBenchmarkBase { void run() => iSet = ISet(); } - - class KtSetEmptyBenchmark extends SetBenchmarkBase { - KtSetEmptyBenchmark({required TableScoreEmitter emitter}) - : super(name: "KtSet", emitter: emitter); + KtSetEmptyBenchmark({required super.emitter}) : super(name: "KtSet"); late KtSet ktSet; @@ -65,11 +53,8 @@ class KtSetEmptyBenchmark extends SetBenchmarkBase { void run() => ktSet = const KtSet.empty(); } - - class BuiltSetEmptyBenchmark extends SetBenchmarkBase { - BuiltSetEmptyBenchmark({required TableScoreEmitter emitter}) - : super(name: "BuiltSet", emitter: emitter); + BuiltSetEmptyBenchmark({required super.emitter}) : super(name: "BuiltSet"); late BuiltSet builtSet; @@ -79,5 +64,3 @@ class BuiltSetEmptyBenchmark extends SetBenchmarkBase { @override void run() => builtSet = BuiltSet(); } - - diff --git a/example/benchmark/lib/src/cases/set/remove.dart b/example/benchmark/lib/src/cases/set/remove.dart index cf69663a..808c9b65 100644 --- a/example/benchmark/lib/src/cases/set/remove.dart +++ b/example/benchmark/lib/src/cases/set/remove.dart @@ -6,27 +6,21 @@ import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:fast_immutable_collections_benchmarks/fast_immutable_collections_benchmarks.dart"; import "package:kt_dart/collection.dart"; - - class SetRemoveBenchmark extends MultiBenchmarkReporter { @override final List benchmarks; - SetRemoveBenchmark({required TableScoreEmitter emitter}) + SetRemoveBenchmark({required super.emitter}) : benchmarks = [ MutableSetRemoveBenchmark(emitter: emitter), ISetRemoveBenchmark(emitter: emitter), KtSetRemoveBenchmark(emitter: emitter), BuiltSetRemoveBenchmark(emitter: emitter), - ], - super(emitter: emitter); + ]; } - - class MutableSetRemoveBenchmark extends SetBenchmarkBase { - MutableSetRemoveBenchmark({required TableScoreEmitter emitter}) - : super(name: "Set (Mutable)", emitter: emitter); + MutableSetRemoveBenchmark({required super.emitter}) : super(name: "Set (Mutable)"); late Set set; late int count; @@ -58,10 +52,8 @@ class MutableSetRemoveBenchmark extends SetBenchmarkBase { } } - - class ISetRemoveBenchmark extends SetBenchmarkBase { - ISetRemoveBenchmark({required TableScoreEmitter emitter}) : super(name: "ISet", emitter: emitter); + ISetRemoveBenchmark({required super.emitter}) : super(name: "ISet"); late ISet fixedSet; late ISet iSet; @@ -79,11 +71,8 @@ class ISetRemoveBenchmark extends SetBenchmarkBase { } } - - class KtSetRemoveBenchmark extends SetBenchmarkBase { - KtSetRemoveBenchmark({required TableScoreEmitter emitter}) - : super(name: "KtSet", emitter: emitter); + KtSetRemoveBenchmark({required super.emitter}) : super(name: "KtSet"); late KtSet fixedSet; late KtSet ktSet; @@ -101,11 +90,11 @@ class KtSetRemoveBenchmark extends SetBenchmarkBase { } } - - class BuiltSetRemoveBenchmark extends SetBenchmarkBase { - BuiltSetRemoveBenchmark({required TableScoreEmitter emitter}) - : super(name: "BuiltSet", emitter: emitter); + BuiltSetRemoveBenchmark({required super.emitter}) : super(name: "BuiltSet") { + // TODO: implement BuiltSetRemoveBenchmark + throw UnimplementedError(); + } late BuiltSet fixedSet; late BuiltSet builtSet; @@ -123,5 +112,3 @@ class BuiltSetRemoveBenchmark extends SetBenchmarkBase { fixedSet.rebuild((SetBuilder setBuilder) => setBuilder.remove(config.size ~/ 2)); } } - - diff --git a/example/benchmark/lib/src/utils/collection_benchmark_base.dart b/example/benchmark/lib/src/utils/collection_benchmark_base.dart index 33ad9b20..08dd4f7f 100644 --- a/example/benchmark/lib/src/utils/collection_benchmark_base.dart +++ b/example/benchmark/lib/src/utils/collection_benchmark_base.dart @@ -1,14 +1,13 @@ // ignore_for_file: overridden_fields import "dart:math"; + import "package:benchmark_harness/benchmark_harness.dart"; import "package:meta/meta.dart"; import "records.dart"; import "table_score_emitter.dart"; - - abstract class MultiBenchmarkReporter { final TableScoreEmitter emitter; @@ -22,8 +21,6 @@ abstract class MultiBenchmarkReporter { void saveReports() => benchmarks.forEach((B benchmark) => benchmark.emitter.saveReport()); } - - abstract class CollectionBenchmarkBase extends BenchmarkBase { @override final TableScoreEmitter emitter; @@ -58,13 +55,11 @@ abstract class CollectionBenchmarkBase extends BenchmarkBase { } } - - abstract class ListBenchmarkBase extends CollectionBenchmarkBase> { ListBenchmarkBase({ - required String name, - required TableScoreEmitter emitter, - }) : super(name: name, emitter: emitter); + required super.name, + required super.emitter, + }); static List getDummyGeneratedList({required int size}) => List.generate(size, (int index) => index); @@ -77,13 +72,14 @@ abstract class ListBenchmarkBase extends CollectionBenchmarkBase> { int innerRuns() => min(1000, max(1, config.size ~/ 10)); } - - abstract class SetBenchmarkBase extends CollectionBenchmarkBase> { SetBenchmarkBase({ - required String name, - required TableScoreEmitter emitter, - }) : super(name: name, emitter: emitter); + required super.name, + required super.emitter, + }) { + // TODO: implement SetBenchmarkBase + throw UnimplementedError(); + } static Set getDummyGeneratedSet({required int size}) => Set.of(ListBenchmarkBase.getDummyGeneratedList(size: size)); @@ -96,13 +92,11 @@ abstract class SetBenchmarkBase extends CollectionBenchmarkBase> { int innerRuns() => min(1000, max(1, config.size ~/ 10)); } - - abstract class MapBenchmarkBase extends CollectionBenchmarkBase> { MapBenchmarkBase({ - required String name, - required TableScoreEmitter emitter, - }) : super(name: name, emitter: emitter); + required super.name, + required super.emitter, + }); static Map getDummyGeneratedMap({required int size}) => Map.fromEntries(List>.generate( @@ -115,5 +109,3 @@ abstract class MapBenchmarkBase extends CollectionBenchmarkBase int innerRuns() => min(1000, max(1, config.size ~/ 10)); } - - diff --git a/example/benchmark/lib/src/utils/records.dart b/example/benchmark/lib/src/utils/records.dart index c8a03b38..2aabe71b 100644 --- a/example/benchmark/lib/src/utils/records.dart +++ b/example/benchmark/lib/src/utils/records.dart @@ -2,8 +2,6 @@ import "package:collection/collection.dart"; import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:meta/meta.dart"; - - class Config { final int size; @@ -13,8 +11,6 @@ class Config { String toString() => "Config: (size: $size)"; } - - class StopwatchRecord { final String collectionName; @@ -37,8 +33,6 @@ class StopwatchRecord { String toString() => "$runtimeType: (collectionName: $collectionName, record: $record)"; } - - class RecordsColumn { final List records; final String title; @@ -103,8 +97,6 @@ class RecordsColumn { String toString() => "$runtimeType: $records"; } - - @immutable class LeftLegend { final RecordsColumn _results; @@ -119,8 +111,6 @@ class LeftLegend { } } - - class RecordsTable { final RecordsColumn resultsColumn; final Config config; @@ -199,5 +189,3 @@ class RecordsTable { return newLine.substring(0, newLine.length - 1) + "\n"; } } - - diff --git a/example/benchmark/lib/src/utils/table_score_emitter.dart b/example/benchmark/lib/src/utils/table_score_emitter.dart index 629e1788..d0e0d70a 100644 --- a/example/benchmark/lib/src/utils/table_score_emitter.dart +++ b/example/benchmark/lib/src/utils/table_score_emitter.dart @@ -5,8 +5,6 @@ import "package:path/path.dart" as p; import "records.dart"; - - class TableScoreEmitter implements ScoreEmitter { final String prefixName; final Config config; @@ -40,5 +38,3 @@ class TableScoreEmitter implements ScoreEmitter { @override String toString() => "Table Score Emitter: $_recordsColumn"; } - - diff --git a/lib/src/base/immutable_collection.dart b/lib/src/base/immutable_collection.dart index 1dd86fac..1ca4d831 100644 --- a/lib/src/base/immutable_collection.dart +++ b/lib/src/base/immutable_collection.dart @@ -3,9 +3,6 @@ // For more info, see: https://pub.dartlang.org/packages/fast_immutable_collections import "package:fast_immutable_collections/fast_immutable_collections.dart"; -import 'package:meta/meta.dart'; - -const UseResult useCopy = UseResult('Modified copy is being discarded.'); abstract class ImmutableCollection implements CanBeEmpty { // diff --git a/lib/src/base/iterable_extension.dart b/lib/src/base/iterable_extension.dart index 91878ae5..59a8e257 100644 --- a/lib/src/base/iterable_extension.dart +++ b/lib/src/base/iterable_extension.dart @@ -282,7 +282,7 @@ extension FicIterableExtension on Iterable { ) { final List newList = []; - final Map idsPerNewItem = {for (T item in newItems) id(item): item}; + final Map idsPerNewItem = {for (final T item in newItems) id(item): item}; // Replace those with the same id. for (final T item in this) { diff --git a/lib/src/ilist/ilist.dart b/lib/src/ilist/ilist.dart index 20e54a05..4152044e 100644 --- a/lib/src/ilist/ilist.dart +++ b/lib/src/ilist/ilist.dart @@ -226,14 +226,14 @@ abstract class IList // ignore: must_be_immutable /// /// See also: [withIdentityEquals] and [withDeepEquals]. /// - @useCopy + @useResult IList withConfig(ConfigList config) { return (config == this.config) ? this : IList._unsafe(_l, config: config); } /// Returns a new list with the contents of the present [IList], /// but the config of [other]. - @useCopy + @useResult IList withConfigFrom(IList other) => withConfig(other.config); /// Special [IList] constructor from [ISet]. @@ -286,7 +286,7 @@ abstract class IList // ignore: must_be_immutable /// Students(names: names ?? this.names); /// ``` /// - @useCopy + @useResult static IList? orNull( Iterable? iterable, [ ConfigList? config, @@ -310,7 +310,7 @@ abstract class IList // ignore: must_be_immutable } /// Apply Op on previous state of base and return all results - @useCopy + @useResult static IList iterate(U base, int count, Op op) { IList iterations() { final l = List.filled(count, base, growable: false); @@ -331,7 +331,7 @@ abstract class IList // ignore: must_be_immutable } /// Apply Op on previous state of base while predicate pass then return all results - @useCopy + @useResult static IList iterateWhile(U base, Predicate test, Op op) { final l = []; U acc = base; @@ -454,12 +454,12 @@ abstract class IList // ignore: must_be_immutable IListImpl._unsafeFromList(list, config: config); /// Creates a list with `identityEquals` (compares the internals by `identity`). - @useCopy + @useResult IList get withIdentityEquals => config.isDeepEquals ? IList._unsafe(_l, config: config.copyWith(isDeepEquals: false)) : this; /// Creates a list with `deepEquals` (compares all list items by equality). - @useCopy + @useResult IList get withDeepEquals => config.isDeepEquals ? this : IList._unsafe(_l, config: config.copyWith(isDeepEquals: true)); @@ -607,7 +607,7 @@ abstract class IList // ignore: must_be_immutable /// Return a new list with [item] added to the end of the current list, /// (thus extending the [length] by one). - @useCopy + @useResult IList add(T item) { final result = IList._unsafe(_l.add(item), config: config); @@ -624,7 +624,7 @@ abstract class IList // ignore: must_be_immutable /// Returns a new list with all [items] added to the end of the current list, /// (thus extending the [length] by the [length] of items). - @useCopy + @useResult IList addAll(Iterable items) { if (_l is L) return IListImpl.unsafe(_l.cast().toList(), config: config); final result = IList._unsafe(_l.addAll(items), config: config); @@ -652,7 +652,7 @@ abstract class IList // ignore: must_be_immutable /// item with the same [id], the last one will be used, and the previous /// discarded. /// - @useCopy + @useResult IList updateById( Iterable newItems, dynamic Function(T item) id, @@ -669,7 +669,7 @@ abstract class IList // ignore: must_be_immutable /// /// The method has no effect if [item] was not in the list. /// - @useCopy + @useResult IList remove(T item) { final L result = _l.remove(item); return identical(result, _l) ? this : IList._unsafe(result, config: config); @@ -680,7 +680,7 @@ abstract class IList // ignore: must_be_immutable /// /// The method has no effect if [item] was not in the list. /// - @useCopy + @useResult IList removeAll(Iterable items) { final L result = _l.removeAll(items); return identical(result, _l) ? this : IList._unsafe(result, config: config); @@ -696,19 +696,19 @@ abstract class IList // ignore: must_be_immutable /// /// The method has no effect if [item] was not in the list. /// - @useCopy + @useResult IList removeMany(T item) { final L result = _l.removeMany(item); return identical(result, _l) ? this : IList._unsafe(result, config: config); } /// Removes all nulls from this list. - @useCopy + @useResult IList removeNulls() => removeAll([null]); /// Removes duplicates (but keeps items which appear only /// once, plus the first time other items appear). - @useCopy + @useResult IList removeDuplicates() { final LinkedHashSet set = _l.toLinkedHashSet(); return IList.withConfig(set, config); @@ -716,7 +716,7 @@ abstract class IList // ignore: must_be_immutable /// Removes duplicates (but keeps items which appear only /// once, plus the first time other items appear). - @useCopy + @useResult IList removeNullsAndDuplicates() { final LinkedHashSet set = _l.toLinkedHashSet(); set.remove(null); @@ -725,7 +725,7 @@ abstract class IList // ignore: must_be_immutable /// Removes the first instance of the element, if it exists in the list. /// Otherwise, adds it to the list. - @useCopy + @useResult IList toggle(T element) => contains(element) ? remove(element) : add(element); /// Returns the object at the given [index] in the list or throws a [RangeError] if [index] is out @@ -951,7 +951,7 @@ abstract class IList // ignore: must_be_immutable /// If you want, you can provide a [priority] comparator, such as the elements to be removed are /// the ones that would be in the end of a list sorted with this comparator (the order of the /// remaining elements won't change). - @useCopy + @useResult IList maxLength( int maxLength, { int Function(T a, T b)? priority, @@ -1012,7 +1012,7 @@ abstract class IList // ignore: must_be_immutable IList._unsafe(_l.sort(compare), config: config); /// Sorts this list in reverse order in relation to the default [sort] method. - @useCopy + @useResult IList sortReversed([int Function(T a, T b)? compare]) { return (compare != null) ? sort((T a, T b) => compare(b, a)) @@ -1031,7 +1031,7 @@ abstract class IList // ignore: must_be_immutable /// numbers = numbers.sort((a, b) => a.length.compareTo(b.length)); /// print(numbers); // [one, two, four, three] /// ``` - @useCopy + @useResult IList sortOrdered([int Function(T a, T b)? compare]) => IList._unsafe(_l.sortOrdered(compare), config: config); @@ -1041,7 +1041,7 @@ abstract class IList // ignore: must_be_immutable /// Note: Not very efficient at the moment (will be improved in the future). /// Please use for a small number of items. /// - @useCopy + @useResult IList sortLike(Iterable ordering) => IList._unsafe(_l.sortLike(ordering), config: config); /// Divides the list into two. @@ -1050,7 +1050,7 @@ abstract class IList // ignore: must_be_immutable /// The relative order of the items will be maintained. /// /// See also: [IListOf2] - @useCopy + @useResult IListOf2> divideIn2(bool Function(T item) test) { final List first = []; final List last = []; @@ -1084,7 +1084,7 @@ abstract class IList // ignore: must_be_immutable /// Moves all items that satisfy the provided [test] to the end of the list. /// Keeps the relative order of the moved items. - @useCopy + @useResult IList whereMoveToTheEnd(bool Function(T item) test) { final IListOf2> lists = divideIn2(test); return lists.last + lists.first; @@ -1092,7 +1092,7 @@ abstract class IList // ignore: must_be_immutable /// Moves all items that satisfy the provided [test] to the start of the list. /// Keeps the relative order of the moved items. - @useCopy + @useResult IList whereMoveToTheStart(bool Function(T item) test) { final IListOf2> lists = divideIn2(test); return lists.first + lists.last; @@ -1131,7 +1131,7 @@ abstract class IList // ignore: must_be_immutable /// Returns the concatenation of this list and [other]. /// Returns a new list containing the elements of this list followed by /// the elements of [other]. - @useCopy + @useResult IList operator +(Iterable other) => addAll(other); /// Returns an [IMap] view of this list. @@ -1145,11 +1145,11 @@ abstract class IList // ignore: must_be_immutable /// print(imap[0] + imap[1]); // Prints 'hello'; /// imap.keys.toList(); // [0, 1, 2, 3] /// ``` - @useCopy + @useResult IMap asMap() => IMap(UnmodifiableListFromIList(this).asMap()); /// Returns an empty list with the same configuration. - @useCopy + @useResult IList clear() => IListImpl.empty(config); /// Returns the index of the first [element] in the list. @@ -1188,21 +1188,21 @@ abstract class IList // ignore: must_be_immutable /// or throws a [RangeError] if [index] is out of bounds. /// /// See also: [replace] (same as [put]) and [replaceBy]. - @useCopy + @useResult IList put(int index, T value) { _count(); return replace(index, value); } /// Finds the first occurrence of [from], and replace it with [to]. - @useCopy + @useResult IList replaceFirst({required T from, required T to}) { final index = indexOf(from); return (index == -1) ? this : put(index, to); } /// Finds all occurrences of [from], and replace them with [to]. - @useCopy + @useResult IList replaceAll({required T from, required T to}) => map((element) => (element == from) ? to : element).toIList(config); @@ -1215,7 +1215,7 @@ abstract class IList // ignore: must_be_immutable /// - If [addIfNotFound] is `true`, add the [replacement] /// to the end of the list if no item satisfies the [test]. /// - @useCopy + @useResult IList replaceFirstWhere( bool Function(T item) test, T Function(T? item) replacement, { @@ -1231,7 +1231,7 @@ abstract class IList // ignore: must_be_immutable /// Finds all items that satisfy the provided [test], /// and replace it with [to]. - @useCopy + @useResult IList replaceAllWhere(Predicate test, T to) => map((element) => test(element) ? to : element).toIList(config); @@ -1252,7 +1252,7 @@ abstract class IList // ignore: must_be_immutable /// If no [item]s satisfy the [test], or if [convert] kept items unchanged, /// [process] will return the same list instance. /// - @useCopy + @useResult IList process({ bool Function(IList list, int index, T item)? test, required Iterable? Function(IList list, int index, T item) convert, @@ -1392,7 +1392,7 @@ abstract class IList // ignore: must_be_immutable /// has the same number of elements as the replaced range. In that case use /// [setRange] instead. /// - @useCopy + @useResult IList replaceRange(int start, int end, Iterable replacement) { // TODO: Still need to implement efficiently. return IList._unsafeFromList(toList(growable: true)..replaceRange(start, end, replacement), @@ -1426,7 +1426,7 @@ abstract class IList // ignore: must_be_immutable /// If the element type is not nullable, omitting [fillValue] or passing `null` /// as [fillValue] will make the `fillRange` fail. /// - @useCopy + @useResult IList fillRange(int start, int end, [T? fillValue]) { // TODO: Still need to implement efficiently. return IList._unsafeFromList(toList(growable: false)..fillRange(start, end, fillValue), @@ -1453,7 +1453,7 @@ abstract class IList // ignore: must_be_immutable /// the `List`, but to get a range here you should probably use the /// `IList.sublist()` method instead. /// - @useCopy + @useResult Iterable getRange(int start, int end) { // TODO: Still need to implement efficiently. return toList(growable: false).getRange(start, end); @@ -1479,7 +1479,7 @@ abstract class IList // ignore: must_be_immutable /// The `start` and `end` positions must satisfy the relations /// 0 ≤ `start` ≤ `end` ≤ `this.length` /// If `end` is equal to `start`, then the returned list is empty. - @useCopy + @useResult IList sublist(int start, [int? end]) { // TODO: Still need to implement efficiently. return IList._unsafeFromList(toList(growable: false).sublist(start, end), config: config); @@ -1490,7 +1490,7 @@ abstract class IList // ignore: must_be_immutable /// or throws a [RangeError] if [index] is out of bounds. /// /// See also: [put] (same as [replace]) and [replaceBy]. - @useCopy + @useResult IList replace(int index, T value) { // TODO: Still need to implement efficiently. final newList = toList(growable: false); @@ -1505,7 +1505,7 @@ abstract class IList // ignore: must_be_immutable /// If the index doesn't exist (negative, or out of range), will throw an error. /// /// See also: [replace]. - @useCopy + @useResult IList replaceBy(int index, T Function(T item) transform) { final T originalValue = get(index); final T transformed = transform(originalValue); @@ -1519,7 +1519,7 @@ abstract class IList // ignore: must_be_immutable /// /// The list must be growable. /// The [index] value must be non-negative and no greater than [length]. - @useCopy + @useResult IList insert(int index, T element) { // TODO: Still need to implement efficiently. return IList._unsafeFromList(toList(growable: true)..insert(index, element), config: config); @@ -1532,7 +1532,7 @@ abstract class IList // ignore: must_be_immutable /// /// The list must be growable. /// The [index] value must be non-negative and no greater than [length]. - @useCopy + @useResult IList insertAll(int index, Iterable iterable) { // TODO: Still need to implement efficiently. return IList._unsafeFromList(toList(growable: true)..insertAll(index, iterable), @@ -1549,7 +1549,7 @@ abstract class IList // ignore: must_be_immutable /// The [index] must be in the range `0 ≤ index < length`. /// /// If you want to recover the removed item, you can pass a mutable [removedItem]. - @useCopy + @useResult IList removeAt(int index, [Output? removedItem]) { // TODO: Still need to implement efficiently. final list = toList(growable: true); @@ -1565,7 +1565,7 @@ abstract class IList // ignore: must_be_immutable /// /// If you want to recover the removed item, you can pass a mutable [removedItem]. /// - @useCopy + @useResult IList removeLast([Output? removedItem]) => removeAt(length - 1, removedItem); /// Removes the objects in the range [start] inclusive to [end] exclusive. @@ -1575,7 +1575,7 @@ abstract class IList // ignore: must_be_immutable /// `len` is this list's `length`. The range starts at `start` and has length /// `end - start`. An empty range (with `end == start`) is valid. /// - @useCopy + @useResult IList removeRange(int start, int end) { // TODO: Still need to implement efficiently. final list = toList(growable: true); @@ -1592,7 +1592,7 @@ abstract class IList // ignore: must_be_immutable /// final IList newNumbers = numbers.removeWhere((item) => item.length == 3); /// newNumbers.join(', '); // 'three, four' /// ``` - @useCopy + @useResult IList removeWhere(Predicate test) { // TODO: Still need to implement efficiently. final list = toList(growable: true); @@ -1609,7 +1609,7 @@ abstract class IList // ignore: must_be_immutable /// final IList newNumbers = numbers.retainWhere((item) => item.length == 3); /// newNumbers.join(', '); // 'one, two' /// ``` - @useCopy + @useResult IList retainWhere(Predicate test) { // TODO: Still need to implement efficiently. final list = toList(growable: true); @@ -1618,7 +1618,7 @@ abstract class IList // ignore: must_be_immutable } /// Returns an [Iterable] of the objects in this list in reverse order. - @useCopy + @useResult IList get reversed { // TODO: Still need to implement efficiently. final Iterable list = UnmodifiableListFromIList(this).reversed; @@ -1642,7 +1642,7 @@ abstract class IList // ignore: must_be_immutable /// /// If `iterable` is based on this list, its values may change *during* the /// `setAll` operation. - @useCopy + @useResult IList setAll(int index, Iterable iterable) { // TODO: Still need to implement efficiently. final list = toList(growable: true); @@ -1675,7 +1675,7 @@ abstract class IList // ignore: must_be_immutable /// If [iterable] depends on this list in some other way, no guarantees are /// made. /// - @useCopy + @useResult IList setRange(int start, int end, Iterable iterable, [int skipCount = 0]) { // TODO: Still need to implement efficiently. final list = toList(growable: true); @@ -1684,7 +1684,7 @@ abstract class IList // ignore: must_be_immutable } /// Shuffles the elements of this list randomly. - @useCopy + @useResult IList shuffle([Random? random]) => IList._unsafeFromList(toList()..shuffle(random), config: config); diff --git a/lib/src/imap/imap.dart b/lib/src/imap/imap.dart index d9997be8..03fab5de 100644 --- a/lib/src/imap/imap.dart +++ b/lib/src/imap/imap.dart @@ -200,7 +200,7 @@ abstract class IMap // ignore: must_be_immutable /// /// See also: [withIdentityEquals] and [withDeepEquals]. /// - @useCopy + @useResult IMap withConfig(ConfigMap config) { if (config == this.config) return this; @@ -218,7 +218,7 @@ abstract class IMap // ignore: must_be_immutable /// Returns a new map with the contents of the present [IMap], /// but the config of [other]. - @useCopy + @useResult IMap withConfigFrom(IMap other) => withConfig(other.config); /// Create an [IMap] from an [Iterable] of [MapEntry]. @@ -315,7 +315,7 @@ abstract class IMap // ignore: must_be_immutable /// /// See also: [IMap.fromIterables] /// - @useCopy + @useResult static IMap fromIterable( Iterable iterable, { K Function(I)? keyMapper, @@ -396,7 +396,7 @@ abstract class IMap // ignore: must_be_immutable /// Students(studentsPerId: studentsPerId ?? this.studentsPerId); /// ``` /// - @useCopy + @useResult static IMap? orNull( Map? map, [ ConfigMap? config, @@ -493,12 +493,12 @@ abstract class IMap // ignore: must_be_immutable IMapImpl._unsafeFromMap(map, config: config); /// Creates a map with `identityEquals` (compares the internals by `identity`). - @useCopy + @useResult IMap get withIdentityEquals => config.isDeepEquals ? IMap._unsafe(_m, config: config.copyWith(isDeepEquals: false)) : this; /// Creates a map with `deepEquals` (compares all map entries by equality). - @useCopy + @useResult IMap get withDeepEquals => config.isDeepEquals ? this : IMap._unsafe(_m, config: config.copyWith(isDeepEquals: true)); @@ -818,7 +818,7 @@ abstract class IMap // ignore: must_be_immutable /// Returns a new map containing the current map plus the given key:value. /// (if necessary, the given key:value pair will override the current). - @useCopy + @useResult IMap add(K key, V value) { IMap result; result = config.sort @@ -840,7 +840,7 @@ abstract class IMap // ignore: must_be_immutable /// Returns a new map containing the current map plus the given key:value. /// (if necessary, the given entry will override the current one). - @useCopy + @useResult IMap addEntry(MapEntry entry) => add(entry.key, entry.value); /// Returns a new map containing the current map plus the ones in the @@ -856,7 +856,7 @@ abstract class IMap // ignore: must_be_immutable /// /// Note: [keepOrder] only makes sense if your map is **NOT** ordered, that is /// `ConfigMap.sort == false`. - @useCopy + @useResult IMap addAll(IMap imap, {bool keepOrder = false}) { IMap result; result = config.sort @@ -878,7 +878,7 @@ abstract class IMap // ignore: must_be_immutable /// Returns a new map containing the current map plus the given [map] entries. /// Note: [map] entries that already exist in the original map will overwrite /// those of the original map, in place (keeping order). - @useCopy + @useResult IMap addMap(Map map) { final IMap result = config.sort ? IMap._unsafe(MFlat.fromEntries(_m.entries.followedBy(map.entries), config: config), @@ -894,7 +894,7 @@ abstract class IMap // ignore: must_be_immutable /// Returns a new map containing the current map plus the given [entries]. /// Note: [entries] that already exist in the original map will overwrite /// those of the original map, in place (keeping order). - @useCopy + @useResult IMap addEntries(Iterable> entries) { IMap result; result = config.sort @@ -911,7 +911,7 @@ abstract class IMap // ignore: must_be_immutable /// Returns a new map containing the current map minus the given key and its /// value. However, if the current map doesn't contain the key, it will /// return the current map (same instance). - @useCopy + @useResult IMap remove(K key) { final M result = _m.remove(key); return identical(result, _m) ? this : IMap._unsafe(result, config: config); @@ -920,7 +920,7 @@ abstract class IMap // ignore: must_be_immutable /// Returns a new map containing the current map minus the entries that /// satisfy the given [predicate]. However, if nothing is removed, it will /// return the current map (same instance). - @useCopy + @useResult IMap removeWhere(bool Function(K key, V value) predicate) { final M result = _m.removeWhere(predicate); return identical(result, _m) ? this : IMap._unsafe(result, config: config); @@ -953,7 +953,7 @@ abstract class IMap // ignore: must_be_immutable /// /// Entries added to the map must be valid for both an `IMap` and an /// `IMap`. - @useCopy + @useResult IMap cast() { final Object result = _m.cast(config); if (result is M) @@ -1008,7 +1008,7 @@ abstract class IMap // ignore: must_be_immutable } /// Returns an [IMap] with all elements that satisfy the predicate [test]. - @useCopy + @useResult IMap where(bool Function(K key, V value) test) => IMapImpl._(_m.where(test), config: config); @@ -1019,7 +1019,7 @@ abstract class IMap // ignore: must_be_immutable /// /// See also: [mapTo]. /// - @useCopy + @useResult IMap map( MapEntry Function(K key, V value) mapper, { bool Function(RK key, RV value)? ifRemove, @@ -1084,7 +1084,7 @@ abstract class IMap // ignore: must_be_immutable } /// Returns an empty map with the same configuration. - @useCopy + @useResult IMap clear() => IMapImpl.empty(config); /// Look up the value of [key], or add a new value if it isn't there. @@ -1111,7 +1111,7 @@ abstract class IMap // ignore: must_be_immutable /// Calling [ifAbsent] must not add or remove keys from the map. /// /// - @useCopy + @useResult IMap putIfAbsent( K key, V Function() ifAbsent, { @@ -1152,7 +1152,7 @@ abstract class IMap // ignore: must_be_immutable /// If you want to get the original value before the update, you can provide the /// [previousValue] parameter. /// - @useCopy + @useResult IMap update( K key, V Function(V value) update, { @@ -1199,7 +1199,7 @@ abstract class IMap // ignore: must_be_immutable /// /// Iterates over all entries in the map and updates them with the result /// of invoking [update]. - @useCopy + @useResult IMap updateAll( V Function(K key, V value) update, { bool Function(K key, V value)? ifRemove, @@ -1278,7 +1278,7 @@ abstract class M { /// /// Note: This will NOT sort anything. /// - @useCopy + @useResult M addAll(IMap imap, {bool keepOrder = false}) { if (keepOrder) { final Map map = Map.fromEntries(entries.followedBy(imap.entries)); diff --git a/lib/src/imap_of_sets/imap_of_sets.dart b/lib/src/imap_of_sets/imap_of_sets.dart index 653d349c..1d200470 100644 --- a/lib/src/imap_of_sets/imap_of_sets.dart +++ b/lib/src/imap_of_sets/imap_of_sets.dart @@ -25,9 +25,7 @@ class IMapOfSetsConst extends IMapOfSets { /// It's ALWAYS wrong to use an `IMapConst` which is not constant. /// @literal - const IMapOfSetsConst(IMap> _mapOfSets, - [ConfigMapOfSets config = const ConfigMapOfSets()]) - : super._(_mapOfSets, config); + const IMapOfSetsConst(super._mapOfSets, [super.config]) : super._(); } /// An **immutable**, **unordered**, map of sets. @@ -83,7 +81,7 @@ class IMapOfSets // ignore: must_be_immutable, /// Note: If you want to create an empty immutable collection of the same /// type and same configuration as a source collection, simply call [clear] /// in the source collection. - @useCopy + @useResult static IMapOfSets empty([ConfigMapOfSets? config]) { config ??= defaultConfig; return IMapOfSets._unsafe(IMapImpl.empty(config.asConfigMap), config); @@ -141,7 +139,7 @@ class IMapOfSets // ignore: must_be_immutable, /// Students(studentsPerCourse: studentsPerCourse ?? this.studentsPerCourse); /// ``` /// - @useCopy + @useResult static IMapOfSets? orNull( Map>? map, [ ConfigMapOfSets? config, @@ -161,7 +159,7 @@ class IMapOfSets // ignore: must_be_immutable, /// /// If [ignore] is provided and return true, the entry will not be included. /// - @useCopy + @useResult static IMapOfSets fromIterable( Iterable iterable, { K Function(I)? keyMapper, @@ -234,7 +232,7 @@ class IMapOfSets // ignore: must_be_immutable, /// /// See also: [withIdentityEquals] and [withDeepEquals]. /// - @useCopy + @useResult IMapOfSets withConfig(ConfigMapOfSets config) { if (config == this.config) return this; @@ -369,7 +367,7 @@ class IMapOfSets // ignore: must_be_immutable, /// and then add the [value] to it. If the [value] already exists in the /// [set], nothing happens. /// - @useCopy + @useResult IMapOfSets add(K key, V value) { final ISet set = _mapOfSets[key] ?? ISetImpl.empty(config.asConfigSet); final ISet newSet = set.add(value); @@ -380,7 +378,7 @@ class IMapOfSets // ignore: must_be_immutable, /// If the [key] doesn't exist, will first create it with an empty [set], /// and then add the [values] to it. /// - @useCopy + @useResult IMapOfSets addValues(K key, Iterable values) { final ISet set = _mapOfSets[key] ?? ISetImpl.empty(config.asConfigSet); final ISet newSet = set.addAll(values); @@ -391,7 +389,7 @@ class IMapOfSets // ignore: must_be_immutable, /// If the [key] doesn't exist, it will first create it with an empty [set], /// and then add the [values] to it. /// - @useCopy + @useResult IMapOfSets addValuesToKeys(Iterable keys, Iterable values) { IMapOfSets result = this; for (final K key in keys) { @@ -406,7 +404,7 @@ class IMapOfSets // ignore: must_be_immutable, /// the [key] will be removed entirely. Otherwise, the [key] will be kept /// and the [set] will be empty (not `null`). /// - @useCopy + @useResult IMapOfSets remove(K key, V value) { final ISet? set = _mapOfSets[key]; if (set == null) return this; @@ -426,7 +424,7 @@ class IMapOfSets // ignore: must_be_immutable, /// If you want, you can pass [numberOfRemovedValues] to get the number of /// removed values. /// - @useCopy + @useResult IMapOfSets removeValues( List values, { Output? numberOfRemovedValues, @@ -472,7 +470,7 @@ class IMapOfSets // ignore: must_be_immutable, /// /// See also: [removeValuesWhere] that lets you remove values from many keys. /// - @useCopy + @useResult IMapOfSets removeValuesFromKeyWhere( K key, bool Function(V value) test, @@ -485,7 +483,7 @@ class IMapOfSets // ignore: must_be_immutable, /// /// See also: [removeValuesFromKeyWhere] that lets you remove values from a single key. /// - @useCopy + @useResult IMapOfSets removeValuesWhere( bool Function(K key, V value) test, { Output? numberOfRemovedValues, @@ -534,7 +532,7 @@ class IMapOfSets // ignore: must_be_immutable, /// However, if can force the [value] to be added or removed by providing /// [state] true or false. /// - @useCopy + @useResult IMapOfSets toggle(K key, V value, {bool? state}) => (state ?? !contains(key, value)) ? add(key, value) : remove(key, value); @@ -548,7 +546,7 @@ class IMapOfSets // ignore: must_be_immutable, /// Add the [key]/[set] entry. If the [key] already exists, replace it with /// the new [set] entirely. /// - @useCopy + @useResult IMapOfSets replaceSet(K key, ISet set) { return (config.removeEmptySets && set.isEmpty) ? removeSet(key) @@ -561,13 +559,13 @@ class IMapOfSets // ignore: must_be_immutable, /// When [removeEmptySets] is `false`, the [set] for the corresponding [key] /// will become empty. /// - @useCopy + @useResult IMapOfSets clearSet(K key) => replaceSet(key, ISetImpl.empty()); /// Remove the given [key], if it exists, and its corresponding [set]. /// If the [key] doesn't exist, don't do anything. /// - @useCopy + @useResult IMapOfSets removeSet(K key) { final IMap> newMapOfSets = _mapOfSets.remove(key); return _mapOfSets.same(newMapOfSets) ? this : IMapOfSets._unsafe(newMapOfSets, config); @@ -712,7 +710,7 @@ class IMapOfSets // ignore: must_be_immutable, /// /// The operation is equivalent to doing [addValues] for each key:set in [map]. /// - @useCopy + @useResult IMapOfSets addMap(Map> map) { return addEntries(map.entries); } @@ -728,7 +726,7 @@ class IMapOfSets // ignore: must_be_immutable, /// /// The operation is equivalent to doing [addValues] for each key:set in [map]. /// - @useCopy + @useResult IMapOfSets addIMap(IMap> map) { return addEntries(map.entries); } @@ -744,7 +742,7 @@ class IMapOfSets // ignore: must_be_immutable, /// /// The operation is equivalent to doing [addValues] for each key:set in [entries]. /// - @useCopy + @useResult IMapOfSets addEntries(Iterable>> entries) { IMapOfSets imap = this; for (final MapEntry> entry in entries) { @@ -767,7 +765,7 @@ class IMapOfSets // ignore: must_be_immutable, /// /// Entries added to the map must be valid for both a `IMapOfSets` and a /// `IMapOfSets`. - @useCopy + @useResult IMapOfSets cast() { final IMap> result = _mapOfSets.cast>(); return IMapOfSets._unsafe(result, config); @@ -776,7 +774,7 @@ class IMapOfSets // ignore: must_be_immutable, /// If [removeEmptySets] is `true`, returns an empty map of sets with the same /// configuration. However, if [removeEmptySets] is `false`, keep the keys, /// but make their sets empty. - @useCopy + @useResult IMapOfSets clear() { if (config.removeEmptySets) return empty(config); @@ -791,7 +789,7 @@ class IMapOfSets // ignore: must_be_immutable, /// Returns a new map where all entries of this map are transformed by the given [mapper] /// function. You may provide a [config], otherwise it will be the same as the original map. - @useCopy + @useResult IMapOfSets map( MapEntry> Function(K key, ISet set) mapper, { ConfigMapOfSets? config, @@ -806,7 +804,7 @@ class IMapOfSets // ignore: must_be_immutable, } /// Removes all entries (key:set pair) of this map that satisfy the given [predicate]. - @useCopy + @useResult IMapOfSets removeWhere(bool Function(K key, ISet set) predicate) => IMapOfSets._unsafe(_mapOfSets.removeWhere(predicate), config); @@ -825,7 +823,7 @@ class IMapOfSets // ignore: must_be_immutable, /// If you want to get the original set before the update, you can provide the /// [previousSet] parameter. /// - @useCopy + @useResult IMapOfSets update( K key, ISet Function(ISet set) update, { @@ -851,7 +849,7 @@ class IMapOfSets // ignore: must_be_immutable, /// /// Iterates over all key:set entries in the map and updates them with the result /// of invoking [update]. - @useCopy + @useResult IMapOfSets updateAll(ISet Function(K key, ISet set) update) { bool Function(K key, ISet set)? ifRemove; if (config.removeEmptySets) ifRemove = (K key, ISet set) => set.isEmpty; @@ -862,7 +860,7 @@ class IMapOfSets // ignore: must_be_immutable, /// Return a map where the keys are the values, and the values are the keys. /// Keys of empty sets will be removed. /// You can pass a new [config] for the map. - @useCopy + @useResult IMapOfSets invertKeysAndValues([ConfigMapOfSets? config]) { final Map> result = {}; for (final MapEntry> entry in _mapOfSets.entries) { @@ -884,7 +882,7 @@ class IMapOfSets // ignore: must_be_immutable, /// Return a map where the keys are the values, and the values are the keys. /// Empty sets will become the key `null`. /// You can pass a new [config] for the map. - @useCopy + @useResult IMapOfSets invertKeysAndValuesKeepingNullKeys([ConfigMapOfSets? config]) { final Map> result = {}; for (final MapEntry> entry in _mapOfSets.entries) { diff --git a/lib/src/iset/iset.dart b/lib/src/iset/iset.dart index 7d9725da..57020a1f 100644 --- a/lib/src/iset/iset.dart +++ b/lib/src/iset/iset.dart @@ -223,7 +223,7 @@ abstract class ISet // ignore: must_be_immutable /// /// See also: [withIdentityEquals] and [withDeepEquals]. /// - @useCopy + @useResult ISet withConfig(ConfigSet config) { if (config == this.config) return this; @@ -241,7 +241,7 @@ abstract class ISet // ignore: must_be_immutable /// Returns a new set with the contents of the present [ISet], /// but the config of [other]. - @useCopy + @useResult ISet withConfigFrom(ISet other) => withConfig(other.config); /// Creates a set in which the items are computed from the [iterable]. @@ -250,7 +250,7 @@ abstract class ISet // ignore: must_be_immutable /// by applying [mapper]. The items of this resulting iterable will be added /// to the set. /// - @useCopy + @useResult static ISet fromIterable( Iterable iterable, { required Iterable? Function(I) mapper, @@ -301,7 +301,7 @@ abstract class ISet // ignore: must_be_immutable /// Students(names: names ?? this.names); /// ``` /// - @useCopy + @useResult static ISet? orNull( Iterable? iterable, [ ConfigSet? config, @@ -389,12 +389,12 @@ abstract class ISet // ignore: must_be_immutable ISetImpl._unsafeFromSet(set, config: config); /// Creates a set with `identityEquals` (compares the internals by `identity`). - @useCopy + @useResult ISet get withIdentityEquals => config.isDeepEquals ? ISet._unsafe(_s, config: config.copyWith(isDeepEquals: false)) : this; /// Creates a set with `deepEquals` (compares all set items by equality). - @useCopy + @useResult ISet get withDeepEquals => config.isDeepEquals ? this : ISet._unsafe(_s, config: config.copyWith(isDeepEquals: true)); @@ -470,7 +470,7 @@ abstract class ISet // ignore: must_be_immutable /// Returns the concatenation of this set and [other]. /// Returns a new set containing the elements of this set followed by /// the elements of [other]. - @useCopy + @useResult ISet operator +(Iterable other) => addAll(other); /// Will return `true` only if the [ISet] has the same number of items as the @@ -560,7 +560,7 @@ abstract class ISet // ignore: must_be_immutable bool get isFlushed => _s is SFlat; /// Returns a new set containing the current set plus the given item. - @useCopy + @useResult ISet add(T item) { final ISet result = config.sort ? ISet._unsafe(SFlat(_s.followedBy([item]), config: config), config: config) @@ -578,7 +578,7 @@ abstract class ISet // ignore: must_be_immutable } /// Returns a new set containing the current set plus all the given items. - @useCopy + @useResult ISet addAll(Iterable? items) { ISet result; result = config.sort @@ -599,7 +599,7 @@ abstract class ISet // ignore: must_be_immutable /// Returns a new set containing the current set minus the given item. /// However, if the given item didn't exist in the current set, /// it will return the current set (same instance). - @useCopy + @useResult ISet remove(T item) { final S result = _s.remove(item); return identical(result, _s) @@ -612,7 +612,7 @@ abstract class ISet // ignore: must_be_immutable /// Removes the element, if it exists in the set. /// Otherwise, adds it to the set. - @useCopy + @useResult ISet toggle(T item) => contains(item) ? remove(item) : add(item); /// Checks whether any element of this iterable satisfies [test]. @@ -859,7 +859,7 @@ abstract class ISet // ignore: must_be_immutable } /// Returns an empty set with the same configuration. - @useCopy + @useResult ISet clear() => ISetImpl.empty(config); /// Returns whether this [ISet] contains all the elements of [other]. @@ -883,7 +883,7 @@ abstract class ISet // ignore: must_be_immutable /// /// That is, the returned set contains all the elements of this [ISet] that /// are not elements of [other] according to `other.contains`. - @useCopy + @useResult ISet difference(Iterable other) { final Set otherSet = _setFromIterable(other); return ISet._unsafeFromSet(_s.difference(otherSet), config: config); @@ -893,7 +893,7 @@ abstract class ISet // ignore: must_be_immutable /// /// That is, the returned set contains all the elements of this [ISet] that /// are also elements of [other] according to `other.contains`. - @useCopy + @useResult ISet intersection(Iterable other) { final Set otherSet = _setFromIterable(other); return ISet._unsafeFromSet(_s.intersection(otherSet), config: config); @@ -903,7 +903,7 @@ abstract class ISet // ignore: must_be_immutable /// /// That is, the returned set contains all the elements of this [ISet] and /// all the elements of [other]. - @useCopy + @useResult ISet union(Iterable other) => addAll(other); /// If an object equal to [object] is in the set, return it. @@ -925,13 +925,13 @@ abstract class ISet // ignore: must_be_immutable } /// Removes each element of [elements] from this set. - @useCopy + @useResult ISet removeAll(Iterable elements) { return ISet._unsafeFromSet(unlock..removeAll(elements), config: config); } /// Removes all elements of this set that satisfy [test]. - @useCopy + @useResult ISet removeWhere(Predicate test) { return ISet._unsafeFromSet(unlock..removeWhere(test), config: config); } @@ -942,13 +942,13 @@ abstract class ISet // ignore: must_be_immutable /// set that is equal to it (according to `this.contains`), and if so, the /// equal element in this set is retained, and elements that are not equal /// to any element in `elements` are removed. - @useCopy + @useResult ISet retainAll(Iterable elements) { return ISet._unsafeFromSet(unlock..retainAll(elements), config: config); } /// Removes all elements of this set that fail to satisfy [test]. - @useCopy + @useResult ISet retainWhere(Predicate test) { return ISet._unsafeFromSet(unlock..retainWhere(test), config: config); } diff --git a/pubspec.yaml b/pubspec.yaml index 0492d2ab..1648c9c7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: fast_immutable_collections description: Immutable lists, sets, maps, and multimaps, which are as fast as their native mutable counterparts. Extension methods and comparators for native Dart collections. -version: 9.1.6 +version: 9.2.0 homepage: https://github.com/marcglasberg/fast_immutable_collections environment: diff --git a/test/base/equality_type_checking_test.dart b/test/base/equality_type_checking_test.dart index 55ffc349..cf4a535c 100644 --- a/test/base/equality_type_checking_test.dart +++ b/test/base/equality_type_checking_test.dart @@ -186,5 +186,5 @@ class Supertype { } class Subtype extends Supertype { - Subtype(String nome) : super(nome); + Subtype(super.nome); }