result_kt 1.1.0 copy "result_kt: ^1.1.0" to clipboard
result_kt: ^1.1.0 copied to clipboard

Encapsulate a value as a success or an error as a failure using Result, execute a function using runCatching that returns a Result, and transform the Stream value into a Result.

example/main.dart

// ignore_for_file: avoid_print
import 'dart:io';

import 'package:result_kt/result_kt.dart';

void main() {
  stdout.writeln('Type an email:');
  final email = stdin.readLineSync()!;
  final result = runCatching(() => validadeEmailAddress(email));
  result
      .onSuccess(action: print)
      .onFailure(action: (value) => print(value.error.toString()));
}

String validadeEmailAddress(String email) {
  const emailRegex =
      r"""^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+""";
  if (RegExp(emailRegex).hasMatch(email)) {
    return '$email is a valid email address';
  } else {
    throw FormatException('$email is not a valid email address');
  }
}
6
likes
160
points
134
downloads

Publisher

verified publisherkmartins.dev

Weekly Downloads

Encapsulate a value as a success or an error as a failure using Result, execute a function using runCatching that returns a Result, and transform the Stream value into a Result.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

More

Packages that depend on result_kt