kotlin_scope_function

Last updated:

0 purchases

kotlin_scope_function Image
kotlin_scope_function Images
Add to Cart

Description:

kotlin scope function

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';`
copied to clipboard
.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);
copied to clipboard
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);
copied to clipboard
.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);
copied to clipboard
.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);
copied to clipboard
.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);
copied to clipboard
Sample Usage #
Run example to see usage shown above and modify the code to try your requirement.
Unit Test #
$ dart pub upgrade test
$ dart test test/kotlin_scope_function_test.dart
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.