scope_function 1.0.3 copy "scope_function: ^1.0.3" to clipboard
scope_function: ^1.0.3 copied to clipboard

A Dart implementation similar to Kotlin scope functions, enable you for powerful chained programming style.

example/scope_function_example.dart

import 'package:scope_function/scope_function.dart';

final List<String> sensitiveWords = [
  'sensitiveWords1',
  'sensitiveWords2',
  'Hello',
];

void main() {
  final String content = 'Hello World';

  content.also((it) => print(it)).also((it) => print(it.length));

  content.let((it) => it.length).also(print);

  content
      .takeIf((it) => it.isNotEmpty)
      ?.also((it) => print('content not empty'));

  content.takeUnless(containsSensitiveWords).also((it) => print(it));

  content.run((it) => it.length).also(print);

  withThe<String, int>(content, (it) => it.length).also(print);
}

bool containsSensitiveWords(String content) {
  bool containSensitiveWords = false;
  for (var element in sensitiveWords) {
    if (content.contains(element)) {
      containSensitiveWords = true;
      break;
    }
  }
  return containSensitiveWords;
}
3
likes
160
points
101
downloads

Publisher

unverified uploader

Weekly Downloads

A Dart implementation similar to Kotlin scope functions, enable you for powerful chained programming style.

Repository (GitHub)
View/report issues

Topics

#kotlin #chained #scope #function #utility

Documentation

API reference

License

BSD-3-Clause (license)

More

Packages that depend on scope_function