Skip to content

Conversation

jacob314
Copy link
Contributor

No description provided.

@jacob314 jacob314 force-pushed the extension_method_polish branch from 87fdcc0 to 0f1630f Compare February 20, 2020 18:03
@jacob314
Copy link
Contributor Author

Fyi filed
dart-lang/sdk#40713
to track the crasher bug in the CFE that the bug in utils_test.dart bug triggered.

}

extension SafeAccess<T> on Iterable<T> {
T get safeFirst {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:
T get safeFirst => isNotEmpty ? first : null;
T get safeLast => isNotEmpty ? last : null;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. also made safeGet a one liner.

final list = [];
expect(list.safeFirst(), isNull);
final list = <int>[];
final Iterable<int> iterable = list;
Copy link
Contributor

@terrylucas terrylucas Feb 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Do we need the Iterable on lvalue with list = [] inference e.g.,
Iterable iterable = list; ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the cast to I do want to test on Iterable to make sure the extension methods are applying to Iterable as well as List. Maybe that doesn't need to be tested but i think it is a reasonable sort of thing to verify given that extension method behavior does vary depending on the type of the target.

Copy link
Contributor

@terrylucas terrylucas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few nits - lgtm

@jacob314 jacob314 merged commit 2ecf4bb into flutter:master Feb 24, 2020
@jacob314 jacob314 deleted the extension_method_polish branch February 24, 2020 16:03
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.

3 participants