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

outdated

A Dart implementation similar to Kotlin scope functions.

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
0
points
101
downloads

Publisher

unverified uploader

Weekly Downloads

A Dart implementation similar to Kotlin scope functions.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on scope_function