Merge branch 'rewrite/master' into feature/chart-editor-context-menus
This commit is contained in:
@@ -77,6 +77,22 @@ class ArrayTools
|
||||
array.pop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new array with all elements of the given array, to prevent modifying the original.
|
||||
*/
|
||||
public static function clone<T>(array:Array<T>):Array<T>
|
||||
{
|
||||
return [for (element in array) element];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new array with clones of all elements of the given array, to prevent modifying the original.
|
||||
*/
|
||||
public static function deepClone<T, U:ICloneable<T>>(array:Array<U>):Array<T>
|
||||
{
|
||||
return [for (element in array) element.clone()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true only if both arrays contain the same elements (possibly in a different order).
|
||||
* @param a The first array to compare.
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package funkin.util.tools;
|
||||
|
||||
/**
|
||||
* Implement this on a class to enable `Array<T>.deepClone()` to work on it.
|
||||
* NOTE: T should be the type of the class that implements this interface.
|
||||
*/
|
||||
interface ICloneable<T>
|
||||
{
|
||||
public function clone():T;
|
||||
}
|
||||
@@ -25,6 +25,33 @@ class MapTools
|
||||
return [for (i in map.iterator()) i];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new array with all elements of the given array, to prevent modifying the original.
|
||||
*/
|
||||
public static function clone<K, T>(map:Map<K, T>):Map<K, T>
|
||||
{
|
||||
return map.copy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new array with clones of all elements of the given array, to prevent modifying the original.
|
||||
*/
|
||||
public static function deepClone<K, T, U:ICloneable<T>>(map:Map<K, U>):Map<K, T>
|
||||
{
|
||||
// TODO: This function does NOT work.
|
||||
throw "Not implemented";
|
||||
|
||||
/*
|
||||
var newMap:Map<K, T> = [];
|
||||
// Replace each value with a clone of itself.
|
||||
for (key in newMap.keys())
|
||||
{
|
||||
newMap.set(key, newMap.get(key).clone());
|
||||
}
|
||||
return newMap;
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of keys from the map (as an array, rather than an iterator).
|
||||
* TODO: Rename this?
|
||||
|
||||
Reference in New Issue
Block a user