It’s a function defined for polymorphism.
the use of a single symbol to represent multiple different types
Basically, you can give a type argument for a function. It works just as generic types:
type genericType<typeparam1, typeparam2> = { [typeparam1] : typeparam2 }
-- Type becomes { [string] : number}
local example: genericType<string, number> = {stringIndex = 1}
I haven’t messed with generic functions in Luau yet, but here’s a C++ example:
template <typename T> // Can be literally anything, T is just a convention
void example(T someParam, T anotherParam) {
std::cout << someParam << anotherParam << std::endl;
}
int main() {
// Becomes void example(string someParam, string anotherParam)
example<std::string>("Hello, ", "World!"); --> Hello, World!
// Becomes void example(int someParam, int anotherParam)
example<int>(1, 2); --> 12
}
Edit: Started looking into Luau generic functions, the equivalent of the above C++ code would be: (keep in mind generic functions don’t work as of now)
local function example<T>(someParam: T, anotherParam: T)
print(tostring(someParam), tostring(anotherParam))
end
-- Becomes example(someParam: string, anotherParam: string)
example<string>("Hello, ", "World!") --> "Hello, World!"
-- Becomes example(someParam: number, anotherParam: number)
example<number>(1, 2) --> 12
Now that I have the chance, I’ll leave words of encouragement for the team:
Very good job!