result-tools
Description
Package adds extra-functionality to result.Result.
Requirements
Package tested for Haxe >= 4.0. The functionality or it missing of the package for lesser versions has not been tested.
Depends by
result
Example of usage
package test;
import resut.Result;
using ResultTools;
function someFunctionality(): Int {
function addTwo(a: Int) return a + 2;
var a = Ok(12);
return a.map(addTwo).getWithDefault(13); //will return 12
}
API
/**
Checks that Result is Ok
**/
public static inline function isOk<T, E>(
t: Result<T, E>
): Bool {...}
/**
Try to get value of Result or throws Exception
**/
public static inline function getVal<T, E>(
t: Result<T, E>
): T {...}
/**
Try to get value of Result or get default value
**/
public static inline function getWithDefault<T, E>(
t: Result<T, E>,
a: T
): T {...}
/**
Apply Resultable function to Result value or continue Error
**/
public static inline function andThen<T, B, E>(
t: Result<T, E>,
fn: (a: T) -> Result<B, E>
): Result<B, E> {...}
/**
Apply function to Result value or continue Error
**/
public static inline function map<T, B, E>(
t: Result<T, E>,
fn: (a: T) -> B
): Result<B, E> {...}
/**
Apply filtering function to value of Result or continue Error
**/
public static inline function filter<T, E>(
t: Result<T, E>,
fn: (a: T) -> Bool,
errVal: E
): Result<T, E> {...}
Author
Anatoly Starodubtsev Tostar74@mail.ru