Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KMap.isNotEmpty #8

Merged
merged 1 commit into from
Dec 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/src/extension/map_extensions_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ abstract class KMapExtensionsMixin<K, V> implements KMapExtension<K, V>, KMap<K,
return value;
}

@override
KIterator<KMapEntry<K, V>> iterator() => entries.iterator();

@override
bool isNotEmpty() => !isEmpty();

@override
KMap<R, V> mapKeys<R>(R Function(KMapEntry<K, V>) transform) {
var mapped = mapKeysTo(linkedMapOf<R, V>(), transform);
Expand Down
8 changes: 5 additions & 3 deletions lib/src/k_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ abstract class KMapExtension<K, V> {
@nonNull
V getValue(K key);

// TODO isNotEmpty
// TODO isNullOrEmpty
// TODO
// TODO filter
// TODO filterTo
// TODO filterNot
Expand All @@ -119,6 +116,11 @@ abstract class KMapExtension<K, V> {
*/
KIterator<KMapEntry<K, V>> iterator();

/**
* Returns `true` if this map is not empty.
*/
bool isNotEmpty();

// TODO plus
// TODO minus

Expand Down
20 changes: 20 additions & 0 deletions test/collection/map_extensions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ void main() {
});
});

group("isEmpty", () {
test("is empty", () {
expect(mutableMapOf({}).isEmpty(), true);
expect(emptyMap().isEmpty(), true);
});
test("is not empty", () {
expect(mutableMapOf({1: "a"}).isEmpty(), false);
});
});

group("isNotEmpty", () {
test("is empty", () {
expect(mutableMapOf({}).isNotEmpty(), false);
expect(emptyMap().isNotEmpty(), false);
});
test("is not empty", () {
expect(mutableMapOf({1: "a"}).isNotEmpty(), true);
});
});

group("iterator", () {
test("iterate", () {
var iterator = pokemon.iterator();
Expand Down