result

Simple return enum for safe function returns with error handling
https://github.com/snsvrno/result-hx

To install, run:

haxelib install result 0.1.1 

See using Haxelib in Haxelib documentation for more information.

README.md

Result.hx

A simple return object based on Rust's Result for easier error handling and making safe code easier.

Usage

Result-hx was created to allow for "safer" returning of functions, and better management of errors. Result<T,E> has two type parameters, T is the main return type while E is the error type.

import result.Result;

function getContent(file : String) : Result<String, String> {
	if (!sys.FileSystem.exists(file)) return Error('file $file does not exist');
	else return Ok(sys.io.File.getContent(file));
}

function main() {
	switch(getContent("afile.txt")) {
		case Error(error): Sys.println('error getting content: $error');
		case Ok(content): Sys.println('file content: $content');
	}
}

Some helper functions are included in result.ResultTools

using result.ResultTools;

function main() {
	var content = getContent("afile.txt");

	trace(content.isOk());

	Sys.println('file content: ${content.unwrap()}');

}
Contributors
snsvrno
Version
0.1.1
Published
3 years ago
License
MIT

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub