option-tools
Description
Package adds extra-functionality to haxe.ds.Option.
Requirements
Package tested for Haxe >= 4.0. The functionality or it missing of the package for lesser versions has not been tested.
Example of usage
package test;
import haxe.ds.Option;
using OptionTools;
function someFunctionality(): Int {
function addTwo(a: Int) return a + 2;
var a = Some(12);
return a.map(addTwo).getWithDefault(13);
}
API
/**
Checks that Option is Some
**/
public static inline function isSome<T>(
t: Option<T>
): Bool {...}
/**
Try to get value of Option or throws Exception
**/
public static inline function getVal<T>(
t: Option<T>
): T {...}
/**
Try to get value of Option or get default value
**/
public static inline function getWithDefault<T>(
t: Option<T>,
a: T
): T {...}
/**
Apply Optional function to Option value or continue None
**/
public static inline function andThen<T>(
t: Option<T>,
fn: (a: T) -> Option<T>
): Option<T> {...}
/**
Apply function to Option value or continue None
**/
public static inline function map<A, B>(
t: Option<A>,
fn: (a: A) -> B
): Option<B> {...}
/**
Apply filtering function to value of Option or continue None
**/
public static inline function filter<T>(
t: Option<T>,
fn: (a: T) -> Bool
): Option<T> {...}
Author
Anatoly Starodubtsev Tostar74@mail.ru