simple_result 0.1.1 copy "simple_result: ^0.1.1" to clipboard
simple_result: ^0.1.1 copied to clipboard

outdated

A simple posibility to return a Result with eiter success or failure.

Simple Result for Dart #

Introduction #

I needed a simple Result like Swift's Result.

I have seen people using dartz with the Either type. But for me, thats not really clear and readable.

Other solutions like result and super_enum did not fit my needs neither. So here is my suggestion.

Installation #

Add the following to you pubspec.yaml and replace [version] with the latest version:

dependencies:
  simple_result: ^[version]

Example #


abstract class Failure {}

class SomeFailure extends Failure {}

void main() async {
	final result = await fetchUser();
	final resultAsString = result.when(
		success:(user) => user.username, 
		failure:(failre) => failire.toString());
	print(resultAsString);
}
Future<Result<User,Failure>>fetchUser() async {
	if (ok){
		return Result.success(user);
	}
	return Result.failure(SomeFailure());
} 

see more in example/main.dart

7
likes
0
pub points
78%
popularity

Publisher

unverified uploader

A simple posibility to return a Result with eiter success or failure.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

meta

More

Packages that depend on simple_result