deep_equal 0.2.0

Recursive comparison-by-value helper

Released 2016-11-06.

To install, run:

haxelib install deep_equal 0.2.0

See using Haxelib in Haxelib documentation for more information.

Current version0.2.0
StatisticsInstalled 119 times
Tags compare, deep equal

Deep Equal Build Status

Every programmer needs to compare values.

Basic Usage

var expected = // any value, array, objects, etc
var actual = // some other value

switch, actual) {
  case Success(_): // they are value-identical
  case Failure(f): trace(f.message,; // they are different!

Advanced Usage

By default, string, bool, Int, float, date, bytes, int64, array, objects, class instances, enum values, class/enum objects (Class<T>/Enum<T>) are recursively compared by value. In case more advanced comparison (such as partial equals, regex checks, etc) is needed, one can implement the CustomCompare interface and put it as the expected value.

The following shows an example on checking if an array contains some required elements, while not necessarily the same length as the required elements.

var a = [1,2,3,4];
var e = new ArrayContains([1,2,3]);
compare(e, a); // success, because the actual value contains all the required values 1, 2 and 3.

var a = [1,2,3,4];
var e = new ArrayContains([3,5]);
compare(e, a); // fail, because the actual value does not contain the required value 5.

class ArrayContains implements deepequal.CustomCompare {
	var items:Array<Dynamic>;
	public function new(items) {
		this.items = items;
	public function check(other:Dynamic, compare:Dynamic->Dynamic->Outcome<Noise, Error>) {
		if(!, Array)) return Failure(new Error('Expected array but got $other'));
		for(i in items) {
			var matched = false;
			for(o in (other:Array<Dynamic>)) switch compare(i, o) {
				case Success(_): matched = true; break;
				case Failure(_):
			if(!matched) return Failure(new Error('Cannot find $i in $other'));
		return Success(Noise);