TypeScriptToLua icon indicating copy to clipboard operation
TypeScriptToLua copied to clipboard

Provide a helper to create lua iterators

Open ark120202 opened this issue 6 years ago • 0 comments

Some observations:

  • Iterator can return any number of values
  • Iterator takes at max 2 params:
    • The first is state, which can be specified only as a part of initializer
    • The second is the first return value, which also can optionally be specified during initialization

Here's a (mostly untested) declaration:

declare function $createLuaIterator<TArgs extends any[]>(
    iter: /** @tupleReturn */ () => TArgs
): LuaTupleIterator<TArgs>;
declare function $createLuaIterator<T1, TArgs extends [T1, ...any[]]>(
    iter: /** @tupleReturn */ (state: undefined, arg1?: T1) => TArgs
): LuaTupleIterator<TArgs>;
declare function $createLuaIterator<TState, T1, TArgs extends [T1, ...any[]]>(
    iter: /** @tupleReturn */ (state: TState, arg1?: T1) => TArgs,
    state: TState
): LuaTupleIterator<TArgs>;
declare function $createLuaIterator<T1, TArgs extends [T1, ...any[]]>(
    iter: /** @tupleReturn */ (state: undefined, arg1: T1) => TArgs,
    state: undefined,
    arg1: T1
): LuaTupleIterator<TArgs>;
declare function $createLuaIterator<TState, T1, TArgs extends [T1, ...any[]]>(
    iter: /** @tupleReturn */ (state: TState, arg1: T1) => TArgs,
    state: TState,
    arg1: T1
): LuaTupleIterator<TArgs>;

ark120202 avatar May 18 '20 19:05 ark120202