A port of kotlin-stdlib for Dart/Flutter including immutable collections (KtList, KtMap, KtSet) and other packages
APACHE-2.0 License
Bot releases are hidden (Show)
Published by passsy almost 6 years ago
Improve Readme to render correctly on pub.
Published by passsy almost 6 years ago
The kollection
project was migrated to kotlin.dart
where kollection
becomes the collection
module.
pubspec.yaml
dependencies:
- dart_kollection: ^0.3.0
+ kotlin_dart: ^0.4.0
your_source.dart
- import 'package:dart_kollection/dart_kollection.dart';
+ import 'package:kotlin_dart/kotlin.dart';
K
to Kt
(KList
-> KtList
)listOf
now accepts up to 10 non-null arguments instead of an Iterable
. Use listFrom
to create KtList
s from an dart Iterable
sKtList.of(1, 2 ,3)
. Both APIs, factory constructor and function based one, are equally supported. It only depends on your personal taste.Here is a list of all collection creation APIs.
/// List
// Create immutable lists
emptyList<int>();
listOf(1, 2, 3, 4, 5);
listFrom([1, 2, 3, 4, 5]);
// Create mutable lists
mutableListOf(1, 2, 3, 4, 5);
mutableListFrom([1, 2, 3, 4, 5]);
/// Set
// Create immutable sets
emptySet<int>();
setOf(1, 2, 3, 4, 5);
setFrom([1, 2, 3, 4, 5]);
// Create a mutable set which keeps the order of the items
linkedSetOf(1, 2, 3, 4, 5);
linkedSetFrom([1, 2, 3, 4, 5]);
// Create mutable, unordered hash-table based set
hashSetOf(1, 2, 3, 4, 5);
hashSetFrom([1, 2, 3, 4, 5]);
/// Map
// Create immutable maps
emptyMap<int, String>();
mapFrom({1: "a", 2: "b"});
// Create mutable maps
mutableMapFrom({1: "a", 2: "b"});
// Create mutable maps without specified order when iterating over items
hashMapFrom({1: "a", 2: "b"});
// Create mutable maps which keep the order of the items
linkedMapFrom({1: "a", 2: "b"});
/// List
// Create immutable lists
KList<int>.empty();
KList.of(1, 2, 3, 4, 5);
KList.from([1, 2, 3, 4, 5]);
// Create mutable lists
KMutableList<int>.empty();
KMutableList.of(1, 2, 3, 4, 5);
KMutableList.from([1, 2, 3, 4, 5]);
/// Set
// Create immutable sets
KSet<int>.empty();
KSet.of(1, 2, 3, 4, 5);
KSet.from([1, 2, 3, 4, 5]);
// Create a mutable set which keeps the order of the items
KMutableSet<int>.empty();
KMutableSet.of(1, 2, 3, 4, 5);
KMutableSet.from([1, 2, 3, 4, 5]);
// Create mutable, unordered hash-table based set
KHashSet<int>.empty();
KHashSet.of(1, 2, 3, 4, 5);
KHashSet.from([1, 2, 3, 4, 5]);
// Create a mutable set which keeps the order of the items
KLinkedSet<int>.empty();
KLinkedSet.of(1, 2, 3, 4, 5);
KLinkedSet.from([1, 2, 3, 4, 5]);
/// Map
// Create mutable maps
KMutableMap<int, String>.empty();
KMutableMap.from({1: "a", 2: "b"});
// Create mutable maps without specified order when iterating over items
KHashMap<int, String>.empty();
KHashMap.from({1: "a", 2: "b"});
// Create mutable maps which keep the order of the items
KLinkedMap<int, String>.empty();
KLinkedMap.from({1: "a", 2: "b"});
Published by passsy almost 6 years ago
Deprecate all APIs and advise users to upgrade to kotlin.dart
Published by passsy almost 6 years ago
This release of Kollection fully covers the project with unit tests, from 52% to 99% 🎉.
By doing that bugs where discovered and fixed.
Because Dart doesn't support non-nullable types yet, this update manually checks all method arguments at runtime.
Passing null
in any method will throw ArgumentError
unless documented otherwise.
ArgumentError
(when asserts are enabled)KIterable<T>.associateWithTo
, Kiterable<T>.filterTo
, KIterable<T>.filterIndexedTo
, KIterable<T>.filterNotTo
, KIterable<T>.filterNotNullTo
, KIterable<T>.groupByTo
,KMap<T>.mapKeysTo
,KMap<T>.mapValuesTo
, KIterable.toCollection
did not compile when called directly due to dart-lang/sdk/issues/35518. The type of destination
of those methods has been changed to a dynamic type (i.e. KMutableList<T>
-> KMutableList<dynamic>
). Those methods will now be checked at runtime. This has one advantage: It allows to pass in contravariant types.final KIterable<int> iterable = listOf([4, 25, -12, 10]);
final result = mutableListOf<num>(); // covariant!
final filtered = iterable.filterIndexedTo(result, (i, it) => it < 10);
expect(identical(result, filtered), isTrue);
expect(result, listOf([4, -12]));
KMutableEntry.setValue
now throws UnimplementedError
because of bug #55. It anyways never worked.KSet
doesn't allow mutation of its elements with via set
getter. It is now really immutable.#38 Breaking: Removed hashMapFrom(KIterable<KPair>)
because, unlike Kotlin, it feels unnatural in Dart. Instead use hashMapOf
to construct a KMutableMap
#17 Breaking: KMap.associateBy
now takes only a single parameter (K Function(T) keySelector
). If you used valueTransform
use KMap.associateByTransform
as replacement
#23 New KMutableList.[]=
operator. Example: list[4] = "Hello"
#47 New KMap
methods filter
, filterTo
, filterNot
, filterNotTo
,
#37 KCollection.random
now optionally accepts a Random
as argument which can be seeded
#39 KMutableList.removeAt
now throws IndexOutOfBoundsException
when index
exceeds length or is negative
#18 KMutableCollection
: addAll
, removeAll
and retainAll
now receive KIterable
as parameter, was KCollection
KList.first
stackoverflowKlist.single
stackoverflowKList.last
which returned first
KIterable.firstOrNull
which threw NoSuchElementException
for empty lists, now returns null
KIterable.mapIndexedTo
, KIterable.mapIndexedNotNullTo
couldn't be called due to a generic compilation errorKList.containsAll
returned false when all elements ar in listKListIterator.nextIndex
was off by one, now returns the index of the element which will be returned by next()
KMutableList.sortBy
and sortByDescending
not sorting the KMutableList
but a copyKIterable.none
always returned true
(Was always working for KCollection
)KSet.==()
returns false for setOf<int>([1, 2, 3]) == setOf<num>([1, 2, 3])
hashSetOf
and linkedSetOf
KIterable.any
document return value when called without predicate
KIterable<T>.associateWithTo
, Kiterable<T>.filterTo
, KIterable<T>.filterIndexedTo
, KIterable<T>.filterNotTo
, KIterable<T>.filterNotNullTo
, KIterable<T>.groupByTo
,KMap<T>.mapKeysTo
,KMap<T>.mapValuesTo
, KIterable.toCollection
KMutableIterator.remove
now throws UnimplementedError
because of bug #5Set<T> get set
returning the internal dart setMap<K, V> get map
returning the intenral dart setKMap.toMap
and KMap.toMutableMap
KMap.isNotEmpty
KMap.toString()
Map.plus
, Map.minus
and operator +(KMap<K, V> map)
, operator -(K key)
compareBy
and compareByDescending
KMutableList.fill
KPair
, KTriple
naturalOrder()
, reverseOrder()
reverse(Comparator)
util functionPublished by passsy almost 6 years ago
Initial release for
KList
/KMutableList
KSet
/KMutableSet
KMap
/KMutableMap
with tons of extensions waiting for you to use them!