pastel 0.5.1 pastel: ^0.5.1 copied to clipboard
A library for convinient code writing.
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))));