veloce / dart_result

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Result

Features

Result is a type that represents either Success or Failure.

Requirements

  • Dart: 2.17.3+

Example

final okResult = await fetchFromServer();
final username = okResult.fold(
  onSuccess: (user) => user.username,
  onFailure: (failure) => 'ERROR: $failure',
);
print(username); // john

print(okResult.failure); // null
print(okResult.getOrNull?.username); // john

final helloUser = await fetchFromServer(withError: false)
    .then((resp) => resp.map((r) => 'hello ${r.username}'));
print(helloUser); // Success: hello john

About

License:MIT License


Languages

Language:Dart 100.0%