chainIf method
Allows conditional method chaining based on a condition.
Returns this object if shouldChain is true, null otherwise.
This is intended to be used with the conditional-member-access operator
(?.).
Example:
var items = Set<int>.of([1, 2, 3]..chainIf(shouldShuffle)?.shuffle());
Implementation
T? chainIf(bool shouldChain) => shouldChain ? this : null;