Skip to content

Commit

Permalink
builtin (fun): add iterators support in basic methods
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaliy-art committed Nov 24, 2024
1 parent a8543af commit 9e4e4e9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tarantoolscript",
"version": "0.30.3",
"version": "0.30.4",
"author": "Vitaliy Artemov [email protected]",
"description": "TypeScript definitions for Tarantool Lua API.",
"repository": {
Expand Down
23 changes: 23 additions & 0 deletions src/builtin/fun/Basic.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ import { FunIterator } from "./FunIterator";
*/
export declare function iter<T>(value: Array<T>): FunIterator<number, [T]>;

/**
* Make iterator from the othe iterator. The function is a generalized version of pairs() and ipairs().
* @param value An iterator.
* @returns `gen`, `param`, `state` – iterator triplet.
* @see {@link https://luafun.github.io/basic.html#fun.iter}
*/
export declare function iter<TState, TReturn extends unknown[]>(
value: FunIterator<TState, TReturn>
): FunIterator<TState, TReturn>;

/**
* Make `gen`, `param`, `state` iterator from the iterable object. The function is a generalized version of pairs() and ipairs().
* @param value A map to iterate for.
Expand Down Expand Up @@ -64,6 +74,19 @@ export declare function each<T>(
value: Array<T>
): void;

/**
* Execute the `fun` for each iteration value.
* @param value An iterator.
* @see {@link https://luafun.github.io/basic.html#fun.each}
*/
export declare function each<TState, TReturn extends unknown[]>(
fun: (
this: void,
param: TReturn extends (infer TElement)[] ? TElement : never
) => unknown,
value: FunIterator<TState, TReturn>
): void;

/**
* Execute the `fun` for each iteration value.
* @param fun Function to execute on each value.
Expand Down

0 comments on commit 9e4e4e9

Please sign in to comment.