Skip to content

satri-tech/rsl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages