maybeWhereType<B> method

B? maybeWhereType<B>()

Filters value based on type B and returns either value itself or null.

Same as you can filter the list with whereType method to remove undesired types (and probably get an empty list), you can use maybeWhereType to "filter" by type. As a result you will get either the value itself, or null if its type is not B:

final int b = 1;
b.maybeWhereType<int>(); // 1
b.maybeWhereType<String>(); // null

Implementation

B? maybeWhereType<B>() => this?.let((it) => it is B ? it as B : null);