profelis / dhx.try

Scala inspired Try operator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Scala inspired Try operator

Build Status

Haxelib: http://lib.haxe.org/p/dhx.try/

Scala API: http://www.scala-lang.org/api/current/scala/util/Try.html

Posts: http://danielwestheide.com/blog/2012/12/26/the-neophytes-guide-to-scala-part-6-error-handling-with-try.html

Usage:

import dhx.Try;
import dhx.Try.Macro.Try;   // macro magic
using dhx.Tries;        // useful extensions
...
var tried:Try<Int> = Try(someUnsafeOperation(foo, bar));
tried.LogFailure(); // trace exception or set define `debug_try`
var value = tried.getOrElse(function () return 0);

Global Import

import.hx

import dhx.Try;
import dhx.Try.Macro.Try;
using dhx.Tries;

Void

Try<Void> is not supported, instead of Void use thx.Nil type from thx.core haxe library.

var tried = Try(voidMethod()); // Try.Success(thx.Nil.nil);

Debug

  • define debug_try - turn on exceptions log

About

Scala inspired Try operator

License:MIT License


Languages

Language:Haxe 98.7%Language:Shell 1.3%