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

Allow null as KtList.of() argument #124

Merged
merged 5 commits into from
Apr 26, 2020
Merged

Conversation

passsy
Copy link
Owner

@passsy passsy commented Apr 10, 2020

Allow null as valid argument for listOf and setOf functions and KtList.of and KtSet.of constructors.

The hack, I first saw in freezed by @rrousselGit, splits definition and implementation of a function, allowing the detection of null values.

The definition uses typesafe T arguments and forwards to the implementation which flexes the type to Object with an internal known defaultArgument.

// definition
KtList<T> Function<T>([T arg0,T arg1]) listOf = _listOf;

// implementation with default values to detect `null`
KtList<T> _listOf<T>([Object arg0 = defaultArgument, Object arg1 = defaultArgument]) {
  return KtList.from([
    if (arg0 != defaultArgument) arg0 as T,
    if (arg1 != defaultArgument) arg1 as T,
  ]);
}

It is typeSafe from the outside, nobody is able to call the private _listOf function.

@codecov
Copy link

codecov bot commented Apr 10, 2020

Codecov Report

Merging #124 into master will decrease coverage by 0.02%.
The diff coverage is 99.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #124      +/-   ##
==========================================
- Coverage   99.64%   99.61%   -0.03%     
==========================================
  Files          38       38              
  Lines        1972     2080     +108     
==========================================
+ Hits         1965     2072     +107     
- Misses          7        8       +1     
Flag Coverage Δ
#unittests 99.61% <99.33%> (-0.03%) ⬇️
Impacted Files Coverage Δ
lib/src/util/arguments.dart 0.00% <0.00%> (-100.00%) ⬇️
lib/src/collection/collections.dart 100.00% <100.00%> (ø)
lib/src/collection/kt_list.dart 100.00% <100.00%> (ø)
lib/src/collection/kt_list_mutable.dart 100.00% <100.00%> (ø)
lib/src/collection/kt_set.dart 100.00% <100.00%> (ø)
lib/src/collection/kt_set_hash.dart 100.00% <100.00%> (ø)
lib/src/collection/kt_set_linked.dart 100.00% <100.00%> (ø)
lib/src/collection/kt_set_mutable.dart 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cd1f4d9...1fb8132. Read the comment docs.

@passsy passsy merged commit 34519d7 into master Apr 26, 2020
@passsy passsy deleted the feature/listOf-allows-null branch April 26, 2020 12:31
@passsy passsy mentioned this pull request Oct 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant