Equal

ceramic.Equal (Class)

Deep equality comparison utilities for various data types.

Equal provides comprehensive equality checking that goes beyond simple reference comparison. It supports deep comparison of arrays, maps, and anonymous objects, making it useful for data validation, testing, and change detection.

Supported Types

  • Arrays: Element-by-element comparison (shallow)
  • StringMap: Key-value comparison
  • IntMap: Key-value comparison
  • Anonymous Objects: Field-by-field comparison (recursive)
  • Primitives: Standard equality

Usage Examples

// Array comparison
var a1 = [1, 2, 3];
var a2 = [1, 2, 3];
Equal.equal(a1, a2); // true

// Object comparison
var o1 = {x: 10, y: 20, data: [1, 2]};
var o2 = {x: 10, y: 20, data: [1, 2]};
Equal.equal(o1, o2); // true

// Map comparison
var m1 = new StringMap<Int>();
m1.set("a", 1);
var m2 = new StringMap<Int>();
m2.set("a", 1);
Equal.equal(m1, m2); // true

Limitations

  • Class instances are compared by reference only
  • Circular references will cause infinite recursion
See: ceramic.Extensions For array utility methods

Static Members

equal(a: Dynamic, b: Dynamic, ?deepEquality: Bool = false): Bool

Performs equality comparison between two values.

Compares values based on their type:

  • Same reference: true
  • Arrays: Element-by-element comparison
  • Maps: Key-value comparison
  • Anonymous objects: Field comparison (recursive when deepEquality=true)
  • Other: Reference equality
Name Type Default Description
a Dynamic First value to compare
b Dynamic Second value to compare
deepEquality Bool false If true, recursively compare nested objects/arrays (default: false)
Returns Description
Bool True if values are equal, false otherwise * haxe // Simple values Equal.equal(5, 5); // true Equal.equal("hello", "hello"); // true * // Arrays (shallow by default) Equal.equal([{x: 1}], [{x: 1}]); // false (shallow comparison) Equal.equal([{x: 1}], [{x: 1}], true); // true (deep comparison) * // Objects Equal.equal( {name: "John", age: 30}, {name: "John", age: 30} ); // true

objectFieldsEqual(a: Any, b: Any, ?deepEquality: Bool = false): Bool

Compares two anonymous objects by their fields.

Performs comparison of all fields in both objects. Objects are considered equal if they have the same fields with equal values (using the equal() function).

Name Type Default Description
a Any First object to compare
b Any Second object to compare
deepEquality Bool false If true, recursively compare nested objects/arrays (default: false)
Returns Description
Bool True if all fields match, false otherwise * haxe var obj1 = {x: 10, y: {z: 20}}; var obj2 = {x: 10, y: {z: 20}}; Equal.objectFieldsEqual(obj1, obj2, true); // true (deep comparison) * var obj3 = {x: 10, y: 20, extra: true}; Equal.objectFieldsEqual(obj1, obj3); // false (different fields)

arrayEqual(a: Array<Any>, b: Array<Any>, ?deepEquality: Bool = false): Bool

Compares two arrays element by element.

Arrays are equal if they have the same length and all corresponding elements are equal.

Name Type Default Description
a Array<Any> First array
b Array<Any> Second array
deepEquality Bool false If true, recursively compare nested objects/arrays (default: false)
Returns Description
Bool True if arrays are equal

stringMapEqual(a: haxe.ds.StringMap<Any>, b: haxe.ds.StringMap<Any>, ?deepEquality: Bool = false): Bool

Compares two StringMaps by their key-value pairs.

Maps are equal if they have the same keys and all values for corresponding keys are equal.

Name Type Default Description
a haxe.ds.StringMap<Any> First StringMap
b haxe.ds.StringMap<Any> Second StringMap
deepEquality Bool false If true, recursively compare nested objects/arrays (default: false)
Returns Description
Bool True if maps have identical key-value pairs * haxe var map1 = new StringMap<Int>(); map1.set("a", 1); map1.set("b", 2); * var map2 = new StringMap<Int>(); map2.set("b", 2); map2.set("a", 1); * Equal.stringMapEqual(map1, map2); // true (order doesn't matter)

intMapEqual(a: haxe.ds.IntMap<Any>, b: haxe.ds.IntMap<Any>, ?deepEquality: Bool = false): Bool

Compares two IntMaps by their key-value pairs.

Maps are equal if they have the same keys and all values for corresponding keys are equal.

Name Type Default Description
a haxe.ds.IntMap<Any> First IntMap
b haxe.ds.IntMap<Any> Second IntMap
deepEquality Bool false If true, recursively compare nested objects/arrays (default: false)
Returns Description
Bool True if maps have identical key-value pairs * haxe var map1 = new IntMap<String>(); map1.set(1, "one"); map1.set(2, "two"); * var map2 = new IntMap<String>(); map2.set(2, "two"); map2.set(1, "one"); * Equal.intMapEqual(map1, map2); // true