lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

feature: Variadic generic packs and mapping expansion

Open PoolloverNathan opened this issue 1 year ago • 0 comments

#1861

This feature request requests variadic generics functionality, as well as mapping those generics. My proposed implementation of this feature request would allow the following example syntax:

---@generic R, T...
---@param fn fun(...: T...):R
---@param ... Component<T>
---@return System<R>
function System.new(fn, ...)
    ...
end

---@generic R
---@param System<R> self
---@param entities Entity[]
---@return R[]
function System:run()
    ...
end

The example code above also introduces a shorthand for variadics (line 3): whenever the parameter ... would have an unexpanded parameter pack as an argument, it is implicitly expanded. Any type can be expanded at any point by suffixing a ..., as shown in line 2.

The motivation of this request arises from an well-typed ECS implementation with object-oriented systems. Without variadic generics, it is not possible in any way I know of to allow a system to depend on any amount of components and still have well-typed parameters.

PoolloverNathan avatar Jan 08 '24 22:01 PoolloverNathan