ofType<TOther> method

Iterable<TOther> ofType<TOther>()

Returns all elements in the iterable that are castable to the specified type.

After applying ofType to an iterable, the resulting iterable will consist of all elements in the source iterable that can be safely cast to TResult, omitting all elements that cannot.

If all elements in the source iterable can be safely cast to TResult, the resulting iterable will be unchanged.

Example:

void main() {
  final list = <num>[0, 1.0, 2, 3.5];
  final result = list.ofType<int>();

  // Result: [0, 2]
}

(This is a convenience method to maintain naming-consistency with its .NET LINQ equivalent. Internally it functions identically to whereType.)

Implementation

Iterable<TOther> ofType<TOther>() {
  return whereType<TOther>();
}