bind<R> method

  1. @useResult
R? bind<R>(
  1. R? function(
    1. T value
    )
)

Returns R? produced by function if this is not null. Otherwise returns null.

This function is similar to map except that it returns R? instead of R.

String? foo = 'value';

foo.bind((v) => 'other value'); // 'other value';

foo.bind((v) => null); // null;


String? bar = null;

bar.bind((v) => 'other value'); // null

Implementation

@useResult R? bind<R>(R? Function(T value) function) => this == null ? null : function(this!);