A bunch of static extensions to make life easier.

Static methods

staticinlineunsafeGet<T>(array:Array<T>, index:Int):T

staticinlineunsafeSet<T>(array:Array<T>, index:Int, value:T):Void

staticinlinesetArrayLength<T>(array:Array<T>, length:Int):Void

staticinlinerandomElement<T>(array:Array<T>):T

Return a random element contained in the given array

@:value({ unsafe : false })staticrandomElementExcept<T>(array:Array<T>, except:T, unsafe:Bool = false):T

Return a random element contained in the given array that is not equal to the except arg.

Parameters:

array

The array in which we extract the element from

except

The element we don't want

unsafe

If set to true, will prevent allocating a new array (and may be faster) but will loop forever if there is no element except the one we don't want

Returns:

The random element or null if nothing was found

staticrandomElementMatchingValidator<T>(array:Array<T>, validator:T ‑> Bool):T

Return a random element contained in the given array that is validated by the provided validator. If no item is valid, returns null.

Parameters:

array

The array in which we extract the element from

validator

A function that returns true if the item is valid, false if not

Returns:

The random element or null if nothing was found

staticshuffle<T>(arr:Array<T>):Void

Shuffle an Array. This operation affects the array in place. The shuffle algorithm used is a variation of the Fisher Yates Shuffle

staticswapElements<T>(arr:Array<T>, index0:Int, index1:Int):Void

staticremoveNullElements<T>(arr:Array<T>):Void

staticinlinetoBytes(buffer:UInt8Array):Bytes

Available on unity