1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-12-04 20:53:57 +00:00
Funkin/source/funkin/util/tools/MapTools.hx

37 lines
806 B
Haxe
Raw Normal View History

2023-01-23 00:55:30 +00:00
package funkin.util.tools;
/**
* A static extension which provides utility functions for Maps.
2023-06-08 20:30:45 +00:00
*
2023-01-23 00:55:30 +00:00
* For example, add `using MapTools` then call `map.values()`.
2023-06-08 20:30:45 +00:00
*
2023-01-23 00:55:30 +00:00
* @see https://haxe.org/manual/lf-static-extension.html
*/
class MapTools
{
/**
* 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-23 00:55:30 +00:00
public static function values<K, T>(map:Map<K, T>):Array<T>
{
return [for (i in map.iterator()) i];
}
2023-04-10 20:05:37 +00:00
/**
* Return a list of keys from the map (as an array, rather than an iterator).
* TODO: Rename this?
*/
2023-04-10 20:05:37 +00:00
public static function keyValues<K, T>(map:Map<K, T>):Array<K>
{
return map.keys().array();
2023-04-10 20:05:37 +00:00
}
2023-01-23 00:55:30 +00:00
}