Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterable's whereType method behaviour

Tags:

flutter

dart

I am having problem with understanding how iterable's whereType works.

I have following example and I have no idea why it is behaving this way. Having this code:

List<dynamic> list = ["SomeString", 12];
print(list);
print(list.whereType<String>());
print(list.where((item) => item is String));

The output is:

[SomeString, 12]
(SomeString, 12)
(SomeString)

I would expect only String in second print. Could someone explain to me why I am wrong?

like image 549
Marcin Szałek Avatar asked Oct 16 '22 21:10

Marcin Szałek


1 Answers

I think this is an inconsistency because whereType is designed for Dart2 but Dart2 is not complete.

There is an open issue that looks similar

  • https://github.com/dart-lang/sdk/issues/32423
dart --reify-generic-functions my_script.dart

should make it work

like image 114
Günter Zöchbauer Avatar answered Oct 21 '22 07:10

Günter Zöchbauer