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

A simple Result type implementation for Dart with standalone Right/Left constructors similar to dartz.

RSL - Result Simple Library #

pub package License: MIT

A minimal, zero-dependency Result type implementation for Dart with standalone Right/Left constructors similar to dartz.

Features #

  • ๐Ÿš€ Simple API with Right() and Left() constructors
  • ๐Ÿ›ก๏ธ Type-safe error handling
  • ๐Ÿ”„ Functional operations (map, flatMap, fold)
  • ๐Ÿ“ฆ Zero dependencies
  • ๐Ÿงช Full test coverage
  • ๐Ÿ’ฏ Null safety

Installation #

Add to your pubspec.yaml:

dependencies:
  rsl: ^1.0.0

Usage #

Basic Example #

import 'package:rsl/rsl.dart';

Result<String, int> parseNumber(String input) {
  try {
    return Right(int.parse(input));
  } catch (e) {
    return Left('Invalid number: $input');
  }
}

void main() {
  final result = parseNumber('42');
  
  // Pattern matching
  result.fold(
    (error) => print('Error: $error'),
    (number) => print('Success: $number'),
  );
  
  // Get value with fallback
  final value = result.getOrElse(() => 0);
  print(value); // 42
}

API Reference #

Constructors

  • Right(value) - Success result
  • Left(error) - Failure result

Methods

  • isRight/isLeft - Check result type
  • right/left - Get value (throws if wrong type)
  • fold(ifLeft, ifRight) - Pattern matching
  • map(f) - Transform success value
  • mapLeft(f) - Transform failure value
  • flatMap(f) - Chain operations

Extensions

  • getOrElse(orElse) - Get value or fallback
  • getOrNull() - Get value or null
  • getOrThrow() - Get value or throw error
  • swap() - Swap success/failure values

Comparison with dartz #

RSL provides a simpler alternative to dartz's Either type when you just need basic Result-type functionality:

// With dartz
Either<String, int> result = Right(42);

// With rsl
Result<String, int> result = Right(42);

License #

MIT - See LICENSE for details.

0
likes
160
points
9
downloads

Documentation

API reference

Publisher

verified publishersatritech.com

Weekly Downloads

A simple Result type implementation for Dart with standalone Right/Left constructors similar to dartz.

Homepage
Repository (GitHub)
View/report issues

License

MIT (license)

More

Packages that depend on rsl