Scope Function
A Dart implementation similar to Kotlin scope functions.
Used for chained programming style.
Getting started
import 'package:scope_function/scope_function.dart';
Usage
netWorkResponse.run(parseResponse)
.let((it) => it.name)
.also((name) => print("name: $name"))
?.takeif((it) => it.isNotEmpty);
Additional information
- Since Dart not support Context receiver as what Kotlin does,
withThe,runimplemented using it as argument. - Since
withis keyword in dart, use namewithTheinstead. - Recommend use
..operator in replace ofapplywhich is usually used as configure object. - Recommend define a function(named/unnamed), and use
function.callin replace ofrun without receiver. - We usually choose function based on semantic distinction if both functions can be competent for the job.
- please refer to Kotlin scope functions for details.