-
Notifications
You must be signed in to change notification settings - Fork 3
Language
Returns the result of a deep comparison between two values. Incompatible types result in false being returned, not a runtime error, unlike the == operator.
Please note, this function supports comparing arrays, structs, all ds_* types, strings, reals, pointers and resources. Collection types are compared regardless of their underlying types. Object types are compared regardless of their underlying types.
- left var: First value to compare.
- right var: Second value to compare.
- boolean: Returns true if values are equivalent, else false.
// NOTE Shorthand for this example uses map and list to denote the ds_* types
_.isEqual({a:1, b:2}, {b:2, a:1});
// => true
_.isEqual([1,2,3], [1,2,3]);
// => true
_.isEqual({a:{b:[1,2,3]}}, {a:{b:[1,2,3]}});
// => true
_.isEqual({a:{b:[1,2,3]}}, {a:{b:[1,3,2]}});
// => false
_.isEqual([1,2,3], list(1,2,3));
// => true
_.isEqual({a:1,b:2}, map(b:2, a:1));
// => true
_.isEqual([{a:1}], [map(a:1)]);
// => true
_.isEqual(1, 1);
// => true
_.isEqual("foo", "bar");
// => falseReturns the result of calling string(). In the case of value being a collection, the result is that of recursively calling string().
This function will also stringify ds_* types.
- value var: Value to stringify.
- string: Returns string result of value.
// NOTE Shorthand for this example uses map and list to denote the ds_* types
_.toString(1);
// => "1"
_.toString([1,2,3]);
// => "[ 1,2,3 ]"
_.toString({a:1,b:2});
// => "{ a : 1, b : 2 }"
_.toString(list(1,2,[3,4,{a:5}]));
// => "[ 1,2,[ 3,4,{ a : 5 } ]]"Returns the result of converting the provided collection recursively into a new collection comprised of arrays and structs where expected if trackChildren is true, otherwise, function is non-recursive.
Please note, previous ds_* types are not automatically destroyed by this function. You will still need to do that yourself.
- collection collection: Value to convert to a collection.
- trackChildren boolean: If conversion should be recursive or not.
- array: Returns collection as an array.
// NOTE Shorthand for this example uses map and list to denote the ds_* types
_.toArray(list(1,2,3,4));
// => [1,2,3,4]
_.toArray(list(map(a:1), map(b:2)));
// => [{a:1}, {b:2}]
_.toArray(list(map(a:1), map(b:2)), false);
// => [map(a:1), map(b:2)]
_.toArray([1,2,3]);
// => [1,2,3]Returns the result of converting the provided collection recursively into a new collection comprised of listss and mapss where expected if trackChildren is true, otherwise, function is non-recursive.
Please note, previous ds_* types are not automatically destroyed by this function. You will still need to do that yourself.
- collection collection: Value to convert to a collection.
- trackChildren boolean: If conversion should be recursive or not.
- ds_list: Returns collection as an ds_list.
// NOTE Shorthand for this example uses map and list to denote the ds_* types
_.toList([1,2,3,4]);
// => list(1,2,3,4)
_.toList([{a:1}, {b:2}])
// => list(map(a:1), map(b:2))
_.toList([{a:1}, {b:2}], false)
// => list({a:1}, {b:2})Returns the result of converting the provided ds_map recursively into a new struct comprised of arrays and structs where expected if trackChildren is true, otherwise, function is non-recursive.
Please note, previous ds_* types are not automatically destroyed by this function. You will still need to do that yourself.
- map ds_map: Value to convert to a struct.
- trackChildren boolean: If conversion should be recursive or not.
- struct: Returns map as an struct.
// NOTE Shorthand for this example uses map and list to denote the ds_* types
_.toStruct(map(a:1, b:2));
// => {a:1, b:2}
_.toStruct(map(a:list(1,2,3)));
// => {a:[1,2,3]}
_.toStruct(map(a:list(1,2,3)), false);
// => {a: list(1,2,3)}
_.toStruct({a:1,b:2});
// => {a:1, b:2}Returns the result of converting the provided struct recursively into a new ds_map comprised of ds_lists and ds_maps where expected if trackChildren is true, otherwise, function is non-recursive.
Please note, previous ds_* types are not automatically destroyed by this function. You will still need to do that yourself.
- struct struct: Value to convert to a map.
- trackChildren boolean: If conversion should be recursive or not.
- ds_map: Returns struct as an ds_map.
// NOTE Shorthand for this example uses map and list to denote the ds_* types
_.toMap({a:1, b:2});
// => map(a:1, b:2)
_.toMap({a:[1,2,3]});
// => map(a:list(1,2,3))
_.toMap({a: list(1,2,3)}, false);
// => map(a: list(1,2,3))
_.toMap({a:1,b:2});
// => {a:1, b:2}