Skip to content

Language

Zach Reedy edited this page Apr 28, 2020 · 1 revision

Language

_.isEqual(left, right)

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.

Parameters

  • left var: First value to compare.
  • right var: Second value to compare.

Returns

  • boolean: Returns true if values are equivalent, else false.

Example

// 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");
// => false

_.toString(value)

Returns 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.

Parameters

  • value var: Value to stringify.

Returns

  • string: Returns string result of value.

Example

// 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 } ]]"

_.toArray(collection, [trackChildren=true])

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.

Parameters

  • collection collection: Value to convert to a collection.
  • trackChildren boolean: If conversion should be recursive or not.

Returns

  • array: Returns collection as an array.

Example

// 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]

_.toList(collection, [trackChildren=true])

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.

Parameters

  • collection collection: Value to convert to a collection.
  • trackChildren boolean: If conversion should be recursive or not.

Returns

  • ds_list: Returns collection as an ds_list.

Example

// 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})

_.toStruct(map, [trackChildren=true])

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.

Parameters

  • map ds_map: Value to convert to a struct.
  • trackChildren boolean: If conversion should be recursive or not.

Returns

  • struct: Returns map as an struct.

Example

// 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}

_.toMap(struct, [trackChildren=true])

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.

Parameters

  • struct struct: Value to convert to a map.
  • trackChildren boolean: If conversion should be recursive or not.

Returns

  • ds_map: Returns struct as an ds_map.

Example

// 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}