pastel 0.6.0 copy "pastel: ^0.6.0" to clipboard
pastel: ^0.6.0 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() => Scope((filename: "pubspec.yaml"))
    .let((p) => Ok(File(p.filename)).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));
          }
        }).map((content) => Ok(print(content))));
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