kotlin_scope_function 1.0.2 icon indicating copy to clipboard operation
kotlin_scope_function: ^1.0.2 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 #

$ dart pub upgrade test
$ dart test test/kotlin_scope_function_test.dart
2
likes
140
pub points
54%
popularity

Publisher

verified publisher iconzyzdev.dev

This is an utility package that providing Kotlin scope function implement by Dart.

Repository (GitHub)

Documentation

API reference

License

Icon for licenses.BSD-3-Clause (LICENSE)

More

Packages that depend on kotlin_scope_function