kt_dart
This project is a port of kotlin-stdlib for Dart/Flutter projects. It includes collections (KtList, KtMap, KtSet) with 150+ methods as well as other useful packages.
1.1.0
6.7K downloads/mo
#3467 most downloaded on pub.dev
passsy/kt.dart
What this package is like to depend on
Last release 3 years ago
no release in 18 months
Ships fairly regularly
a new release about every 4 months
Nearly every release is documented
notes for 12 of 12 stable releases
Nothing withdrawn
no release was ever pulled
8 years old
18 releases · first in 2019
0 releases in the last 12 months
see the full history below
Release timeline
18 releases · Jan 2019 to Mar 2023Releases
latest 18-
1.1.020 Mar 2023Release notes
Open source →- #190
KtMutableMapEntry.setValue()is now implemented (thx @hugobrancowb) - #188 Added
KtIterable.firstNotNullOf()KtIterable.firstNotNullOfOrNull()(thx @hugobrancowb) - #196 Methods, returning mutated copies are now marked with
@useReslt(thx @nohli) - #197
mapNotNull,mapNotNullTo,mapIndexedNotNull,mapIndexedNotNullTo,filterNotNullTowork now correctly for non-nullable types
Release notes
Open source →- #190
KtMutableMapEntry.setValue()is now implemented (thx @hugobrancowb) - #188 Added
KtIterable.firstNotNullOf()KtIterable.firstNotNullOfOrNull()(thx @hugobrancowb) - #196 Methods, returning mutated copies are now marked with
@useReslt(thx @nohli) - #197
mapNotNull,mapNotNullTo,mapIndexedNotNull,mapIndexedNotNullTo,filterNotNullTowork now correctly for non-nullable types
- #190
-
1.0.027 Sep 2022Release notes
Open source →- #183 New:
KtIterable.sumOfthx @nohli - Update dependencies and guarantee compatibility with Dart 2.12-2.18
Full Changelog: v0.10.0...v1.0.0
Release notes
Open source →- #183 New:
KtIterable.sumOfthx @nohli - Update dependencies and guarantee compatibility with Dart 2.12-2.18
- #183 New:
-
0.10.031 Oct 2021Release notes
Open source →Some nullsafety improvements, type fixes and a lot of new Kotlin 1.4 extensions
-
#141 Fix:
requireNoNulls()now convertsT?toT -
1df6e1a Fix:
.dartand.iteronIterable<T>now work for all types not only ifT implements Comparable -
f43cbc5 Fix:
*NotNullmethods now return non-nullable types -
b727893 Fix: The hashcode of all collections doesn't get cached anymore. That caused problems when mutable items in a
KtListchanged. TheequalsandhashCodemethods now always change together. -
#141 Improve:
KtIterable.onEachcan now be chained -
#141 New:
KtIterable.cast()to manually cast values -
#141 New:
KtIterable.onEachIndexed -
#163 New:
KtIterable.shuffled() -
#166 New:
KtIterable.reduceOrNull() -
#169 New:
KtMutableList.removeFirst()KtMutableList.removeLast() -
#173 New:
KtMutableList.removeFirstOrNull()KtMutableList.removeLastOrNull() -
#171 New:
KtIterable.minOf() -
#165 New:
String.replaceFirstChar() -
#170 New:
KtIterable.minOrNull(),KtIterable.maxOrNull(), deprecatesKtIterable.min(),KtIterable.max(), -
#174 New:
KtIterable.runningReduce() -
#177 New:
KtCollection.randomOrNull() -
#178 New:
KtIterable.flatMapIndexed,KtIterable.flatMapIndexedTo
Thanks to the #hacktoberfest contributors @Anas35, @robiness, @MatthaiosSait, @Dev-dfm, @marciokuroki, @Rishabh-Negi
Release notes
Open source →Some nullsafety improvements, type fixes and a lot of new Kotlin 1.4 extensions
-
#141 Fix:
requireNoNulls()now convertsT?toT -
1df6e1a Fix:
.dartand.iteronIterable<T>now work for all types not only ifT implements Comparable -
f43cbc5 Fix:
*NotNullmethods now return non-nullable types -
b727893 Fix: The hashcode of all collections doesn't get cached anymore. That caused problems when mutable items in a
KtListchanged. TheequalsandhashCodemethods now always change together. -
#142 Improve:
KtIterable.onEachcan now be chained -
#141 New:
KtIterable.cast()to manually cast values -
#142 New:
KtIterable.onEachIndexed -
#163 New:
KtIterable.shuffled() -
#166 New:
KtIterable.reduceOrNull() -
#169 New:
KtMutableList.removeFirst()KtMutableList.removeLast() -
#173 New:
KtMutableList.removeFirstOrNull()KtMutableList.removeLastOrNull() -
#171 New:
KtIterable.minOf() -
#165 New:
String.replaceFirstChar() -
#170 New:
KtIterable.minOrNull(),KtIterable.maxOrNull(), deprecatesKtIterable.min(),KtIterable.max(), -
#174 New:
KtIterable.runningReduce() -
#177 New:
KtCollection.randomOrNull() -
#178 New:
KtIterable.flatMapIndexed,KtIterable.flatMapIndexedTo
Thanks to the #hacktoberfest contributors @Anas35, @robiness, @MatthaiosSait, @Dev-dfm, @marciokuroki, @Rishabh-Negi
-
-
0.9.122 May 2021Release notes
Open source →- #138 Deprecate
KtIterable<T>.sumByDoublein favor ofKtIterable<T>.sumBywhich now works forintanddouble - #140
KtMap.getOrDefaultnow returnsVinstead ofV? - #140 Fix
KtMap.groupByreturningKtMap<K, KtMutableList<T>>instead ofKtMap<K, KtList<T>>causing generic type problems in further processing
Release notes
Open source →- #138 Deprecate
KtIterable<T>.sumByDoublein favor ofKtIterable<T>.sumBywhich now works forintanddouble - #140
KtMap.getOrDefaultnow returnsVinstead ofV? - #140 Fix
KtMap.groupByreturningKtMap<K, KtMutableList<T>>instead ofKtMap<K, KtList<T>>causing generic type problems in further processing
- #138 Deprecate
-
0.9.014 Mar 2021 -
0.9.0-nullsafety.019 Nov 2020 pre-releaseRelease notes
Open source →- Migrate to Dart 2.12 with [null-safety(https://dart.dev/null-safety) support
Release notes
Open source →- Migrate to Dart 2.12 with [null-safety(https://dart.dev/null-safety) support
-
0.8.001 Oct 2020Release notes
Open source →New
package:kt_dart/standard.dartlibrary containing Kotlins loved standard extensions- #120 Standard extensions
let,also,takeIfandtakeUnless - #120
TODO([String message])top-level function which throwsNotImplementedException - #120
repeat(int times, void Function(int) action)top-level function
More cool updates
- #124
KtList.ofandKtSet.ofnow allownullas parameters. Same forlistOfandsetOf - #131 Chain Comparators with the new
thenByandthenByDescendingfunctions. - #126 Allow const
.empty()constructors forKtList,KtMapandKtSet(Thanks @TimWhiting) - #127
plus,minusoperator overrides forKtSet, returningKtSetand notKtListas theKtIterableoperators do
Release notes
Open source →New
package:kt_dart/standard.dartlibrary containing Kotlins loved standard extensions- #120 Standard extensions
let,also,takeIfandtakeUnless - #120
TODO([String message])top-level function which throwsNotImplementedException - #120
repeat(int times, void Function(int) action)top-level function
More cool updates
- #124
KtList.ofandKtSet.ofnow allownullas parameters. Same forlistOfandsetOf - #131 Chain Comparators with the new
thenByandthenByDescendingfunctions. - #126 Allow const
.empty()constructors forKtList,KtMapandKtSet(Thanks @TimWhiting) - #127
plus,minusoperator overrides forKtSet, returningKtSetand notKtListas theKtIterableoperators do
- #120 Standard extensions
-
0.8.0-dev.127 Apr 2020 pre-releaseRelease notes
Open source →- #124
KtList.ofandKtSet.ofnow allownullas parameters. Same forlistOfandsetOf - #120 Standard extensions
let,also,takeIfandtakeUnless - #120
TODO([String message])top-level function which throwsNotImplementedException - #120
repeat(int times, void Function(int) action)top-level function - #126 Allow const
.empty()constructors forKtList,KtMapandKtSet(Thanks @TimWhiting) - #127
plus,minusoperator overrides forKtSet, returningKtSetand notKtListas theKtIterableoperators do
Release notes
Open source →- #124
KtList.ofandKtSet.ofnow allownullas parameters. Same forlistOfandsetOf - #120 Standard extensions
let,also,takeIfandtakeUnless - #120
TODO([String message])top-level function which throwsNotImplementedException - #120
repeat(int times, void Function(int) action)top-level function - #126 Allow const
.empty()constructors forKtList,KtMapandKtSet(Thanks @TimWhiting) - #127
plus,minusoperator overrides forKtSet, returningKtSetand notKtListas theKtIterableoperators do
- #124
-
0.7.001 Mar 2020Release notes
Open source →The library has be upgrade to use
Static Extension Methods.Interop
This update also includes extensions for Dart collections which allow easy interoperability between dart and kt.dart collections using the
.ktand.dartgetters.// New: Converting dart collections to KtDart collections (mutable views) final KtMutableList<String> ktList = ["hey"].kt; final KtMutableSet<String> ktSet = {"hey"}.kt; final KtMutableMap<String, int> ktMap = {"hey": 1}.kt; // Converting KtDart collections to dart collections final List<String> dartList = KtList.of("hey").dart; final Set<String> dartSet = KtSet.of("hey").dart; final Map<String, int> dartMap = KtMap.from({"hey": 1}).dart;
Note:
["Hello", "World"].ktreturns aKtMutableList<String>and mutations are reflected on the original dart list. It is not a copy! Because it doesn't copy it is very cheap and only syntax sugar.To convert dart collections to their immutable kt.dart counterparts use:
.toImmutableList(),.toImmutableSet(),.toImmutableMap()// New: Make dart collections immutable final KtList<String> list = ["hey"].toImmutableList(); final KtSet<String> set = {"hey"}.toImmutableSet(); final KtMap<String, int> map = {"hey": 1}.toImmutableMap();
Possible breaking changes
- Relax
sortBy/sortByDescending,maxBy/minBytyping to work better with ints and doubles #116
// Was: int doesn't not implement Comparable<int> but Comparable<num> // minBy therefore required some help to figure out the correct type (<num>) users.minBy<num>((it) => it.age); // Now: minBy doesn't require the Comparable (num) to have the same same as the value (int). users.minBy((it) => it.age);
- Remove unnecessary generic
RfromKtIterable.zipWithNext#118
New Extensions
KtPairandKtTriplenow have a newtoList()function to convert the values to aKtListKtList?.orEmpty()returns an empty list when the list isnullKtSet?.orEmpty()returns an empty set when the set isnullKtMap?.orEmpty()returns an empty map when the map isnullKtMap.ifEmpty(() -> defaultValue)returns the default value when the map is emptyKtIterable<KtIterable<T>>.flatten()flattens the nested collections toKtIterable<T>KtIterable<KtPair<T, U>>.unzip(): KtPair<KtList<T>, KtList<U>>unzips list of pairs to list of their first and second valuesKtIterable<Comparable<T>>.min()returns the smallest element of any comparable iterableKtIterable<Comparable<T>>.max()returns the largest element of any comparable iterable
Release notes
Open source →The library has be upgrade to use
Static Extension Methods.Interop
This update also includes extensions for Dart collections which allow easy interoperability between dart and kt.dart collections using the
.ktand.dartgetters.// New: Converting dart collections to KtDart collections (mutable views) final KtMutableList<String> ktList = ["hey"].kt; final KtMutableSet<String> ktSet = {"hey"}.kt; final KtMutableMap<String, int> ktMap = {"hey": 1}.kt; // Converting KtDart collections to dart collections final List<String> dartList = KtList.of("hey").dart; final Set<String> dartSet = KtSet.of("hey").dart; final Map<String, int> dartMap = KtMap.from({"hey": 1}).dart;Note:
["Hello", "World"].ktreturns aKtMutableList<String>and mutations are reflected on the original dart list. It is not a copy! Because it doesn't copy it is very cheap and only syntax sugar.To convert dart collections to their immutable kt.dart counterparts use:
.toImmutableList(),.toImmutableSet(),.toImmutableMap()// New: Make dart collections immutable final KtList<String> list = ["hey"].toImmutableList(); final KtSet<String> set = {"hey"}.toImmutableSet(); final KtMap<String, int> map = {"hey": 1}.toImmutableMap();Possible breaking changes
- Relax
sortBy/sortByDescending,maxBy/minBytyping to work better with ints and doubles #116
// Was: int doesn't not implement Comparable<int> but Comparable<num> // minBy therefore required some help to figure out the correct type (<num>) users.minBy<num>((it) => it.age); // Now: minBy doesn't require the Comparable (num) to have the same same as the value (int). users.minBy((it) => it.age);- Remove unnecessary generic
RfromKtIterable.zipWithNext#118
New Extensions
KtPairandKtTriplenow have a newtoList()function to convert the values to aKtListKtList?.orEmpty()returns an empty list when the list isnullKtSet?.orEmpty()returns an empty set when the set isnullKtMap?.orEmpty()returns an empty map when the map isnullKtMap.ifEmpty(() -> defaultValue)returns the default value when the map is emptyKtIterable<KtIterable<T>>.flatten()flattens the nested collections toKtIterable<T>KtIterable<KtPair<T, U>>.unzip(): KtPair<KtList<T>, KtList<U>>unzips list of pairs to list of their first and second valuesKtIterable<Comparable<T>>.min()returns the smallest element of any comparable iterableKtIterable<Comparable<T>>.max()returns the largest element of any comparable iterable
- Relax
-
0.7.0+101 Mar 2020 -
0.7.0-dev.429 Dec 2019 pre-releaseRelease notes
Open source →- New extension
Iterable.toImmutableList(): KtList - New extension
Iterable.toImmutableSet(): KtSet - New extension
KtIterable<num>.average(): double - Relax
sortBy/sortByDescending,maxBy/minBytyping to work better with ints and doubles
// Was: int doesn't not implement Comparable<int> but Comparable<num> // minBy therefore required some help to figure out the correct type (<num>) users.minBy<num>((it) => it.age); // Now: minBy doesn't require the Comparable (num) to have the same same as the value (int). users.minBy((it) => it.age);
Release notes
Open source →- New extension
Iterable.toImmutableList(): KtList - New extension
Iterable.toImmutableSet(): KtSet - New extension
KtIterable<num>.average(): double - Relax
sortBy/sortByDescending,maxBy/minBytyping to work better with ints and doubles
// Was: int doesn't not implement Comparable<int> but Comparable<num> // minBy therefore required some help to figure out the correct type (<num>) users.minBy<num>((it) => it.age); // Now: minBy doesn't require the Comparable (num) to have the same same as the value (int). users.minBy((it) => it.age); - New extension
-
0.7.0-dev.322 Dec 2019 pre-releaseRelease notes
Open source →- Rename
(List|Set|Map).immutable()extension to.toImmutableList()to match Dart SDK naming schema. - Remove
int.rangeTo(X)extension. Please use thedartxas replacement which offers the same extension - Remove
T.to(X)extension to create aKtPair. It's too general and should be offered by the dart SDK not a 3rd party package
- Rename
-
0.7.0-dev.221 Oct 2019 pre-releaseRelease notes
Open source →New
.dartextensions to convert KtDart collections back to dart collections.// New: Converting dart collections to KtDart collections (mutable views) final KtMutableList<String> ktList = ["hey"].kt; final KtMutableSet<String> ktSet = {"hey"}.kt; final KtMutableMap<String, int> ktMap = {"hey": 1}.kt; // Converting KtDart collections to dart collections final List<String> dartList = KtList.of("hey").dart; final Set<String> dartSet = KtSet.of("hey").dart; final Map<String, int> dartMap = KtMap.from({"hey": 1}).dart; -
0.7.0-dev.121 Oct 2019 pre-releaseRelease notes
Open source →KtDart makes full use of darts static extension methods, introduced with Dart 2.6.
The public API stays unchanged and is backwards compatible.
Improved interopt with dart collections
It is now easier then ever to convert dart to ktdart collections and vice versa. Use the
.ktproperty to convert dart collections to KtDart collections. (Note:.ktcreate a view, which allows you to mutate the original dart collection).// New: Make dart collections immutable final KtList<String> list = ["hey"].immutable(); final KtSet<String> set = {"hey"}.immutable(); final KtMap<String, int> map = {"hey": 1}.immutable(); // New: Converting dart collections to KtDart collections (mutable views) final KtMutableList<String> ktList = ["hey"].kt; final KtMutableSet<String> ktSet = {"hey"}.kt; final KtMutableMap<String, int> ktMap = {"hey": 1}.kt; // Converting KtDart collections to dart collections final List<String> dartList = KtList.of("hey").asList(); final Set<String> dartSet = KtSet.of("hey").asSet(); final Map<String, int> dartMap = KtMap.from({"hey": 1}).asMap();Tuple improvements
KtPairs can now created with theT0.to(T1)extension.final KtPair<String, int> pair = "foo".to(42);Also,
KtPairandKtTriplenow have a newtoList()function to convert the values to aKtList.New Extensions
KtList?.orEmpty()returns an empty list when the list isnullKtSet?.orEmpty()returns an empty set when the set isnullKtMap?.orEmpty()returns an empty map when the map isnullKtMap.ifEmpty(() -> defaultValue)returns the default value when the map is emptyKtIterable<KtIterable<T>>.flatten()flattens the nested collections toKtIterable<T>KtIterable<KtPair<T, U>>.unzip(): KtPair<KtList<T>, KtList<U>>unzips list of pairs to list of their first and second valuesKtIterable<Comparable<T>>.min()returns the smallest element of any comparable iterableKtIterable<Comparable<T>>.max()returns the largest element of any comparable iterable
-
0.6.224 Apr 2019 -
0.6.127 Mar 2019 -
0.6.027 Mar 2019Release notes
Open source →This major update of kt.dart add 10+ extension methods for
KtMapand makes working with maps even easier.Behavior Changes
The properties
KtList.list: List,KtSet.set: Setare now deprecated andKtMap.map: Mapwas removed. Those properties where used to convert kt.dart collections to dart collections. Instead use the newKtList.asList(): List,KtSet.asSet(): Set,KtMa.asMap(): Mapmethods. The old properties returned copies of the collections. The newas-methods return views of the original collections and reflect changes of the original data.This breaking change was necessary because the property
KtMap.map: Map<K, V>was conflicting withKtMap.map(MapEntry<K, V> -> R) : KtList<R>to map the entries to items of aKtList. Read about further details here.If you have used properties to iterate over the collections using a for-loop you should now always use
iterwhich is available for all kt.dart collections.for (final element in listOf("a", "b", "c").iter) { print(element); } for (final element in setOf("a", "b", "c").iter) { print(element); } for (final p in mapFrom({1: "Bulbasaur", 2: "Ivysaur"}).iter) { print("${p.key} -> ${p.value}"); }Additions
- #86 New:
KtMap.mapReturns a list containing the results of applying the giventransformfunction to each entry in the original map. - #86 New:
KtMap.iterAccess to aIterableto be used in for-loops - #87 New:
KtMap.countReturns the number of entries matching the given [predicate] or the number of entries whenpredicate = null. - #89 New:
KtMap.minByReturns the first entry yielding the smallest value of the given function ornullif there are no entries. - #89 New:
KtMap.minWithReturns the first entry having the smallest value according to the providedcomparatorornullif there are no entries. - #89 New:
KtMap.maxByReturns the first entry yielding the largest value of the given function ornullif there are no entries. - #89 New:
KtMap.maxWithReturns the first entry having the largest value according to the providedcomparatorornullif there are no entries. - #90 New:
KtMap.toListReturns aKtListcontaining all key-value pairs. - #78 New:
KtMap.forEachPerforms givenactionon each key/value pair from this map. thanks @acherkashyn - #80 New:
KtMap.noneReturnstrueif there is no entries in the map that match the givenpredicate. thanks @acherkashyn - #80 New:
KtMap.allReturns true if all entries match the givenpredicate. thanks @acherkashyn - #80 New:
KtMap.anyReturns true if there is at least one entry that matches the givenpredicate. thanks @acherkashyn - #84 New:
KtMap.filterKeysReturns a map containing all key-value pairs with keys matching the givenpredicate. - #84 New:
KtMap.filterValuesReturns a map containing all key-value pairs with values matching the givenpredicate. - #79 New:
KtMap.asMapReturns a read-only dart:coreMap - #79 New:
KtMutableMap.asMapCreates aMapinstance that wraps the originalKtMap. It acts as a view.
- #75 New:
KtIterable.takeWhileReturns a list containing first elements satisfying the givenpredicate. - #76 New:
KtIterable.takeLastWhileReturns a list containing last elements satisfying the givenpredicate.
- #73 New:
KtList.takeLast, Returns a list containing lastnelements. - #79 New:
KtList.asListReturns a read-only dart:coreList - #79 New:
KtMutableList.asListCreates aListinstance that wraps the originalKtList. It acts as a view.
- #79, #91 New:
KtSet.asSetReturns a read-only dart:coreSet - #79 New:
KtMutableSet.asSetCreates aSetinstance that wraps the originalKtSet. It acts as a view.
Bugfixes
Documentation
Misc.
- #86 New:
-
0.5.011 Jan 2019Release notes
Open source →Project has been renamed to
kt.dart. If you're using a previous version upgrade like this:pubspec.yamldependencies: - dart_kollection: ^0.3.0 - kotlin_dart: ^0.4.0 + kt_dart: ^0.5.0your_source.dart- import 'package:dart_kollection/dart_kollection.dart'; - import 'package:kotlin_dart/kotlin.dart'; + import 'package:kt_dart/kt.dart';