kotlin_scope_function 0.0.1-dev.1 kotlin_scope_function: ^0.0.1-dev.1 copied to clipboard
This is an utility package that providing Kotlin scope function implement by Dart.
kotlin_scope_function #
This is a utility package that providing Kotlin scope function implement by Dart.
Getting Started #
- import package to dart file
import 'package:kotlin_scope_function/kotlin_scope_function.dart';`
.let #
.let can be used to invoke one or more functions on results of call chains.
final defValue = 10;
var result = defValue.let((it) {
final b = 5;
return it + b + 5;
});
print(result);
run #
run is useful when your lambda contains both the object initialization and the computation of the return value.
final a = 10;
var result = run(() {
final b = 5;
return a + b + 5;
});
print(result);
.also #
also is good for performing some actions that take the context object as an argument.
List result = [];
result.also((it) {
final b = 10;
it.add(b);
it.add(5);
});
print(result);
.takeIf #
takeIf returns object self if it matches the predicate. Otherwise, it returns null.
List ref = ["data"];
var result = ref.takeIf((it) {
return it.isNotEmpty;
});
print(result);
.takeIf #
takeUnless returns object self if it doesn't matches the predicate. Otherwise, it returns null.
List ref = ["data"];
var result = ref.takeUnless((it) {
return it.isEmpty;
});
print(result);
Sample Usage #
Run example
to see usage shown above and modify the code to try your requirement.
Unit Test #
$ flutter test test/kotlin_scope_function_test.dart