dart_kollection 0.3.2 dart_kollection: ^0.3.2 copied to clipboard
Brings Kotlins colletions (List, Set, Map) to Dart. Unlike Darts collections kollections are immutable by default but offer special `Mutable` types.
0.4.0 (unreleased) #
0.3.0 #
Summary #
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.
Behavior changes #
- #36 All method arguments are now validated for nullability. If a argument isn't documented as "nullable" the method will throw
ArgumentError
(when asserts are enabled) - #51, #46
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 ofdestination
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]));
- #56
KMutableEntry.setValue
now throwsUnimplementedError
because of bug #55. It anyways never worked. - #58
KSet
doesn't allow mutation of its elements with viaset
getter. It is now really immutable.
API changes #
-
#38 Breaking: Removed
hashMapFrom(KIterable<KPair>)
because, unlike Kotlin, it feels unnatural in Dart. Instead usehashMapOf
to construct aKMutableMap
-
#17 Breaking:
KMap.associateBy
now takes only a single parameter (K Function(T) keySelector
). If you usedvalueTransform
useKMap.associateByTransform
as replacement -
#23 New
KMutableList.[]=
operator. Example:list[4] = "Hello"
-
#47 New
KMap
methodsfilter
,filterTo
,filterNot
,filterNotTo
, -
#37
KCollection.random
now optionally accepts aRandom
as argument which can be seeded -
#39
KMutableList.removeAt
now throwsIndexOutOfBoundsException
whenindex
exceeds length or is negative -
#18
KMutableCollection
:addAll
,removeAll
andretainAll
now receiveKIterable
as parameter, wasKCollection
Bug fixes #
- #18 Fixed
KList.first
stackoverflow - #44 Fixed
Klist.single
stackoverflow - #24 Fixed
KList.last
which returnedfirst
- #20 Fixed
KIterable.firstOrNull
which threwNoSuchElementException
for empty lists, now returnsnull
- #22 Fixed
KIterable.mapIndexedTo
,KIterable.mapIndexedNotNullTo
couldn't be called due to a generic compilation error - #26 Fixed
KList.containsAll
returned false when all elements ar in list - #28 Fixed
KListIterator.nextIndex
was off by one, now returns the index of the element which will be returned bynext()
- #30 Fixed
KMutableList.sortBy
andsortByDescending
not sorting theKMutableList
but a copy - #31 Fixed
KIterable.none
always returnedtrue
(Was always working forKCollection
) - #51 Fixed
KSet.==()
returns false forsetOf<int>([1, 2, 3]) == setOf<num>([1, 2, 3])
Documentation changes #
- #57 Document
hashSetOf
andlinkedSetOf
- #19
KIterable.any
document return value when called withoutpredicate
- #51 Document expected type of now dynamically typed
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
Other changes #
0.2.0 #
Behavior change #
API changes #
- #1 Add
Set<T> get set
returning the internal dart set - #1 Add
Map<K, V> get map
returning the intenral dart set - #7 Add
KMap.toMap
andKMap.toMutableMap
- #8 Add
KMap.isNotEmpty
- 3e3228e Add
KMap.toString()
- #9 Add
Map.plus
,Map.minus
andoperator +(KMap<K, V> map)
,operator -(K key)
- #12 Remove const constructors from collection interfaces
- #13 Remove default implementations from collection interfaces
Documentation changes #
- #15 Add documentation for
compareBy
andcompareByDescending
Other changes #
0.1.0 #
Initial release for
KList
/KMutableList
KSet
/KMutableSet
KMap
/KMutableMap
with tons of extensions waiting for you to use them!