I'd like to write a function that runs different code based on a passed array parameter's type. NON-working example:
Is there a way to do this?
A functional Object-based equivalent would be:
Basically, I want a generic function that handles all types rather than writing a function for every type: ProcessByteArray, ProcessIntArray, ProcessDoubleArray, etc.
SuperStrict Local ByteMap:Byte[5,15] Local IntMap:Int[5,15] ProcessArray ByteMap ProcessArray IntMap End Function ProcessArray(arr:Object[,] Var) If Not arr Then Return If Byte[,](arr) Then Print "Bytes" If Int[,](arr) Then Print "Ints" If Long[,](arr) Then Print "Longs" If Float[,](arr) Then Print "Floats" If Double[,](arr) Then Print "Doubles" EndFunction
Is there a way to do this?
A functional Object-based equivalent would be:
SuperStrict Local ByteMap:TByte[5,15] ByteMap[0,0] = New TByte Local IntMap:TInt[5,15] IntMap[0,0] = New TInt ProcessArray ByteMap ProcessArray IntMap End Function ProcessArray(arr:Object[,] Var) If Not arr Then Return If TByte(arr[0,0]) Then Print "Bytes" If TInt(arr[0,0]) Then Print "Ints" If TLong(arr[0,0]) Then Print "Longs" If TFloat(arr[0,0]) Then Print "Floats" If TDouble(arr[0,0]) Then Print "Doubles" EndFunction Type TByte Field f:Byte EndType Type TInt Field f:Int EndType Type TLong Field f:Long EndType Type TFloat Field f:Float EndType Type TDouble Field f:Double EndType
Basically, I want a generic function that handles all types rather than writing a function for every type: ProcessByteArray, ProcessIntArray, ProcessDoubleArray, etc.