micro_core_result 0.2.2 copy "micro_core_result: ^0.2.2" to clipboard
micro_core_result: ^0.2.2 copied to clipboard

This package is a simple approach to return multiple values, inspired on dartz package.

micro_core_result #

License Package Version Package Points Coverage #

This package is a simple approach to return multiple values, inspired on dartz package. #

Platform Support #

Android iOS MacOS Web Linux Windows

Features #

  • Result, Left and Right classes to return more than 1 value
  • Empty class to not return any data

Usage #

Returning Left or Right #

Future<Result<Exception, List<String>>> getNamesFromAPI() async {
    try {
        return Right(['Johnson', 'Harvey', 'Marshall', 'Denver', 'Noelene', 'Coreen']);
    } on Exception catch (exception) {
        return Left(exception);
    } 
}

void getNames() async {
    final result = await getNamesFromAPI();

    result(
        id,
        (names) => print('Names => $names'); 
    );
}

Returning Left or Empty #

Future<Result<Exception, Empty>> createNameOnDatabase() async {
    try {
        return Right(empty);
    } on Exception catch (exception) {
        return Left(exception);
    } 
}

 Future<Result<Exception, Empty>> createName(String name) async {
    final result = await _repository.createName(name);

    return result(
      (e) {
        print('Exception => ${e.toString()}');
        return Left(e);
      },
      (e) {
        print('Name was created successfully!');
        return Right(e);
      },
    );
  }
4
likes
160
points
54
downloads

Publisher

verified publisherjotapetecnologia.com.br

Weekly Downloads

This package is a simple approach to return multiple values, inspired on dartz package.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

More

Packages that depend on micro_core_result