Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Variadic generic packs and mapping expansion #2470

Open
PoolloverNathan opened this issue Jan 8, 2024 · 0 comments
Open

feature: Variadic generic packs and mapping expansion #2470

PoolloverNathan opened this issue Jan 8, 2024 · 0 comments

Comments

@PoolloverNathan
Copy link

PoolloverNathan commented Jan 8, 2024

#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant