mirror of
https://github.com/ninjamuffin99/Funkin.git
synced 2024-12-27 07:27:12 +00:00
35 lines
659 B
Haxe
35 lines
659 B
Haxe
package funkin.util.tools;
|
|
|
|
/**
|
|
* A static extension which provides utility functions for Iterators.
|
|
*
|
|
* For example, add `using IteratorTools` then call `iterator.array()`.
|
|
*
|
|
* @see https://haxe.org/manual/lf-static-extension.html
|
|
*/
|
|
class IteratorTools
|
|
{
|
|
public static function array<T>(iterator:Iterator<T>):Array<T>
|
|
{
|
|
return [for (i in iterator) i];
|
|
}
|
|
|
|
public static function count<T>(iterator:Iterator<T>, ?predicate:(item:T) -> Bool):Int
|
|
{
|
|
var n = 0;
|
|
|
|
if (predicate == null)
|
|
{
|
|
for (_ in iterator)
|
|
n++;
|
|
}
|
|
else
|
|
{
|
|
for (x in iterator)
|
|
if (predicate(x)) n++;
|
|
}
|
|
|
|
return n;
|
|
}
|
|
}
|