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

A library for convinient code writing.

example/example.dart

import 'dart:io';

import 'package:pastel/pastel.dart';

class FileNotExistsError extends PastelError {
  final String path;

  FileNotExistsError(this.path);

  @override
  String toString() => 'File $path does not exist';
}

class FileSystemError extends PastelError {
  final FileSystemException exception;

  FileSystemError(this.exception);

  @override
  String toString() => exception.toString();
}

void main() {
  var result = Ok(File('pubspec.yaml')).map((file) {
    if (file.existsSync()) {
      return Ok(file);
    } else {
      return Err<File>(FileNotExistsError(file.path));
    }
  }).map((file) {
    try {
      return Ok(file.readAsStringSync());
    } on FileSystemException catch (e) {
      return Err<String>(FileSystemError(e));
    }
  });

  switch (result) {
    case Ok<String>():
      print(result.unwrap());
      break;
    case Err<String>():
      print(result.unwrapErr());
      break;
  }
}
3
likes
0
points
56
downloads

Publisher

unverified uploader

Weekly Downloads

A library for convinient code writing.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on pastel