2023-01-22 19:55:30 -05:00
|
|
|
package funkin.util.tools;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A static extension which provides utility functions for Maps.
|
|
|
|
*
|
|
|
|
* For example, add `using MapTools` then call `map.values()`.
|
|
|
|
*
|
|
|
|
* @see https://haxe.org/manual/lf-static-extension.html
|
|
|
|
*/
|
|
|
|
class MapTools
|
|
|
|
{
|
2023-05-16 22:09:53 -04:00
|
|
|
/**
|
|
|
|
* Return the quantity of keys in the map.
|
|
|
|
*/
|
|
|
|
public static function size<K, T>(map:Map<K, T>):Int
|
|
|
|
{
|
|
|
|
return map.keys().array().length;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a list of values from the map, as an array.
|
|
|
|
*/
|
2023-01-22 19:55:30 -05:00
|
|
|
public static function values<K, T>(map:Map<K, T>):Array<T>
|
|
|
|
{
|
|
|
|
return [for (i in map.iterator()) i];
|
|
|
|
}
|
2023-04-10 16:05:37 -04:00
|
|
|
|
2023-05-16 22:09:53 -04:00
|
|
|
/**
|
|
|
|
* Return a list of keys from the map (as an array, rather than an iterator).
|
|
|
|
*/
|
2023-04-10 16:05:37 -04:00
|
|
|
public static function keyValues<K, T>(map:Map<K, T>):Array<K>
|
|
|
|
{
|
2023-05-16 22:09:53 -04:00
|
|
|
return map.keys().array();
|
2023-04-10 16:05:37 -04:00
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
}
|