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

A Dart package providing utility classes including Result for error handling.

example/kib_utils_example.dart

import 'package:kib_utils/kib_utils.dart';

Future<void> main() async {
  // Success example
  final successResult = success<String, Exception>('Operation completed');
  print(successResult);  // Output: Success(Operation completed)
  
  // Failure example
  final failureResult = failure<String, Exception>(Exception('Something went wrong'));
  print(failureResult);  // Output: Failure(Exception: Something went wrong)

  // Using tryResult
  final computation = tryResult<int, Exception>(
    () => 42,
    (error) => Exception('Computation failed: $error'),
  );
  print('Computation result: ${computation.getOrElse(0)}');  // Output: Computation result: 42
  
  // Using tryResultAsync
  final asyncResult = await tryResultAsync<String, Exception>(
    () async {
      await Future.delayed(const Duration(milliseconds: 100));
      return 'Async operation completed';
    },
    (error) => Exception('Async operation failed: $error'),
  );
  
  // Using fold to handle both success and failure
  final message = asyncResult.fold(
    (value) => 'Success: $value',
    (error) => 'Error: ${error.toString()}',
  );
  print(message);  // Output: Success: Async operation completed
}
1
likes
160
points
32
downloads

Publisher

unverified uploader

Weekly Downloads

A Dart package providing utility classes including Result for error handling.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

equatable

More

Packages that depend on kib_utils