Skip to content

Commit

Permalink
builtin (fun): fix declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaliy-art committed Nov 28, 2024
1 parent cff223d commit c2f466b
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 88 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.8",
"version": "0.30.9",
"author": "Vitaliy Artemov [email protected]",
"description": "TypeScript definitions for Tarantool Lua API.",
"repository": {
Expand Down
12 changes: 6 additions & 6 deletions src/builtin/fun/Basic.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export declare function iter<TState, TReturn extends unknown[]>(
* @returns `gen`, `param`, `state` – iterator triplet.
* @see {@link https://luafun.github.io/basic.html#fun.iter}
*/
export declare function iter(
value: AnyTable
): FunIterator<string, [string, unknown]>;
export declare function iter<TValue>(
value: Record<string, TValue>
): FunIterator<string, [string, TValue]>;

/**
* Make `gen`, `param`, `state` iterator from the iterable object. The function is a generalized version of pairs() and ipairs().
Expand Down Expand Up @@ -90,9 +90,9 @@ export declare function each<TState, TReturn extends unknown[]>(
* @param value A map to iterate for.
* @see {@link https://luafun.github.io/basic.html#fun.each}
*/
export declare function each(
fun: (this: void, ...params: [string, unknown]) => unknown,
value: AnyTable
export declare function each<TValue>(
fun: (this: void, key: string, value: TValue) => unknown,
value: Record<string, TValue>
): void;

/**
Expand Down
6 changes: 3 additions & 3 deletions src/builtin/fun/Compositions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ export declare function cycle<TState, TReturn extends unknown[]>(
* @returns A new iterator.
* @see {@link https://luafun.github.io/compositions.html#fun.cycle}
*/
export declare function cycle(
value: AnyTable
): FunIterator<number, [string, unknown]>;
export declare function cycle<TValue>(
value: Record<string, TValue>
): FunIterator<number, [string, TValue]>;

/**
* Make a new iterator that returns elements from `{gen, param, state}` iterator until the end
Expand Down
19 changes: 8 additions & 11 deletions src/builtin/fun/Filtering.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export declare function filter<TState, TReturn extends unknown[]>(
* @returns An iterator.
* @see {@link https://luafun.github.io/filtering.html#fun.filter}
*/
export declare function filter(
predicate: (this: void, key: string, value: any) => boolean,
value: AnyTable
): FunIterator<string, [string, unknown]>;
export declare function filter<TValue>(
predicate: (this: void, key: string, value: TValue) => boolean,
value: Record<string, TValue>
): FunIterator<string, [string, TValue]>;

/**
* Return a new iterator of those elements that satisfy the `predicate`.
Expand Down Expand Up @@ -114,14 +114,11 @@ export declare function partition<TState, TReturn extends unknown[]>(
* @returns An iterator pair.
* @see {@link https://luafun.github.io/filtering.html#fun.partition}
*/
export declare function partition(
predicate: (this: void, key: string, value: any) => boolean,
value: AnyTable
export declare function partition<TValue>(
predicate: (this: void, key: string, value: TValue) => boolean,
value: Record<string, TValue>
): LuaMultiReturn<
[
FunIterator<string, [string, unknown]>,
FunIterator<string, [string, unknown]>
]
[FunIterator<string, [string, TValue]>, FunIterator<string, [string, TValue]>]
>;

/**
Expand Down
11 changes: 7 additions & 4 deletions src/builtin/fun/Indexing.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ export declare function index<TState, TReturn extends unknown[]>(
* @returns The position of element or nil.
* @see {@link https://luafun.github.io/indexing.html#fun.index}
*/
export declare function index(x: string, value: AnyTable): number?;
export declare function index(
x: string,
value: Record<string, unknown>
): number?;

/**
* The function returns the position of the first symbol in the string which is equal (using `==`) to the query element,
Expand Down Expand Up @@ -87,9 +90,9 @@ export declare function indexes<T>(
* @returns An iterator.
* @see {@link https://luafun.github.io/indexing.html#fun.indexes}
*/
export declare function indexes(
x: unknown,
value: AnyTable
export declare function indexes<TValue>(
x: TValue,
value: Record<string, TValue>
): FunIterator<number, [number]>;

/**
Expand Down
26 changes: 13 additions & 13 deletions src/builtin/fun/Reducing.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ export declare function foldl<T, R>(
* @returns Reducing result.
* @see {@link https://luafun.github.io/reducing.html#fun.foldl}
*/
export declare function foldl<R>(
accfun: (this: void, acc: R, key: string, value: unknown) => R,
export declare function foldl<R, TValue>(
accfun: (this: void, acc: R, key: string, value: TValue) => R,
initval: R,
value: AnyTable
value: Record<string, TValue>
): R;

/**
Expand Down Expand Up @@ -208,9 +208,9 @@ export declare function all<T>(
* Returns `true` if all key-value pairs of map satisfy the `predicate`.
* @see {@link https://luafun.github.io/reducing.html#fun.all}
*/
export declare function all(
predicate: (this: void, key: string, value: unknown) => boolean,
value: AnyTable
export declare function all<TValue>(
predicate: (this: void, key: string, value: TValue) => boolean,
value: Record<string, TValue>
): boolean;

/**
Expand Down Expand Up @@ -259,9 +259,9 @@ export declare function any<TState, TReturn extends unknown[]>(
* The iteration stops on the first such value.
* @see {@link https://luafun.github.io/reducing.html#fun.any}
*/
export declare function any(
predicate: (this: void, key: string, value: unknown) => boolean,
value: AnyTable
export declare function any<TValue>(
predicate: (this: void, key: string, value: TValue) => boolean,
value: Record<string, TValue>
): boolean;

/**
Expand Down Expand Up @@ -359,7 +359,7 @@ export declare function min<TState, TReturn extends [number, ...unknown[]]>(
* The iterator must be non-null, otherwise error is raised.
* @see {@link https://luafun.github.io/reducing.html#fun.min}
*/
export declare function min(value: AnyTable): string;
export declare function min(value: Record<string, unknown>): string;

/**
* Return a minimum value from the iterator using `<`.
Expand Down Expand Up @@ -435,7 +435,7 @@ export declare function min_by<
*/
export declare function min_by(
cmp: (this: void, a: string, b: string) => string,
value: AnyTable
value: Record<string, unknown>
): string;

/**
Expand Down Expand Up @@ -483,7 +483,7 @@ export declare function max<TState, TReturn extends [number, ...unknown[]]>(
* The iterator must be non-null, otherwise error is raised.
* @see {@link https://luafun.github.io/reducing.html#fun.max}
*/
export declare function max(value: AnyTable): string;
export declare function max(value: Record<string, unknown>): string;

/**
* Return a maximum value from the iterator using `>`.
Expand Down Expand Up @@ -559,7 +559,7 @@ export declare function max_by<
*/
export declare function max_by(
cmp: (this: void, a: string, b: string) => string,
value: AnyTable
value: Record<string, unknown>
): string;

/**
Expand Down
75 changes: 33 additions & 42 deletions src/builtin/fun/Slicing.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ export declare function nth<TState, TReturn extends unknown[]>(
* @returns The n-th key-value pair of map.
* @see {@link https://luafun.github.io/slicing.html#fun.nth}
*/
export declare function nth(
export declare function nth<TValue>(
n: number,
value: AnyTable
): LuaMultiReturn<[string, unknown] | [undefined]>;
value: Record<string, TValue>
): LuaMultiReturn<[string, TValue] | [undefined]>;

/**
* Return the n-th symbol of string.
Expand Down Expand Up @@ -87,9 +87,9 @@ export declare function head<TState, TReturn extends unknown[]>(
* @returns A first key-value pair of map.
* @see {@link https://luafun.github.io/slicing.html#fun.head}
*/
export declare function head(
value: AnyTable
): LuaMultiReturn<[string, unknown]>;
export declare function head<TValue>(
value: Record<string, TValue>
): LuaMultiReturn<[string, TValue]>;

/**
* Extract the first symbol of string. If value is empty then an error is raised.
Expand Down Expand Up @@ -142,9 +142,9 @@ export declare function tail<TState, TReturn extends unknown[]>(
* @returns `gen`, `param`, `state` iterator without a first element.
* @see {@link https://luafun.github.io/slicing.html#fun.tail}
*/
export declare function tail(
value: AnyTable
): FunIterator<string, [string, unknown]>;
export declare function tail<TValue>(
value: Record<string, TValue>
): FunIterator<string, [string, TValue]>;

/**
* Return a copy of string without its first symbol.
Expand Down Expand Up @@ -204,10 +204,10 @@ export declare function take_n<TState, TReturn extends unknown[]>(
* @returns An iterator on the subsequence of first `n` key-value paris.
* @see {@link https://luafun.github.io/slicing.html#fun.take_n}
*/
export declare function take_n(
export declare function take_n<TValue>(
n: number,
value: AnyTable
): FunIterator<string, [string, unknown]>;
value: Record<string, TValue>
): FunIterator<string, [string, TValue]>;

/**
* Return an iterator on the subsequence of first `n` symbols of string.
Expand Down Expand Up @@ -272,10 +272,10 @@ export declare function take_while<TState, TReturn extends unknown[]>(
* @returns An iterator on the subsequence of first key-value pairs satisfying the condition.
* @see {@link https://luafun.github.io/slicing.html#fun.take_while}
*/
export declare function take_while(
predicate: (this: void, key: string, value: any) => boolean,
value: AnyTable
): FunIterator<string, [string, unknown]>;
export declare function take_while<TValue>(
predicate: (this: void, key: string, value: TValue) => boolean,
value: Record<string, TValue>
): FunIterator<string, [string, TValue]>;

/**
* Returns an iterator on the subsequence of first symbols satisfying the condition.
Expand Down Expand Up @@ -341,10 +341,10 @@ export declare function drop_n<TState, TReturn extends unknown[]>(
* @returns An iterator after skipping first `n` key-value paris.
* @see {@link https://luafun.github.io/slicing.html#fun.drop_n}
*/
export declare function drop_n(
export declare function drop_n<TValue>(
n: number,
value: AnyTable
): FunIterator<string, [string, unknown]>;
value: Record<string, TValue>
): FunIterator<string, [string, TValue]>;

/**
* Return an iterator after skipping first `n` symbols of string.
Expand Down Expand Up @@ -409,10 +409,10 @@ export declare function drop_while<TState, TReturn extends unknown[]>(
* @returns An iterator after skipping the longest prefix of first key-value pairs satisfying the condition.
* @see {@link https://luafun.github.io/slicing.html#fun.drop_while}
*/
export declare function drop_while(
predicate: (this: void, key: string, value: any) => boolean,
value: AnyTable
): FunIterator<string, [string, unknown]>;
export declare function drop_while<TValue>(
predicate: (this: void, key: string, value: TValue) => boolean,
value: Record<string, TValue>
): FunIterator<string, [string, TValue]>;

/**
* Returns an iterator after skipping the longest prefix of first symbols satisfying the condition.
Expand Down Expand Up @@ -481,14 +481,11 @@ export declare function span<TState, TReturn extends unknown[]>(
* @returns An iterator pair (first `n` key-value pairs and remainder).
* @see {@link https://luafun.github.io/slicing.html#fun.span}
*/
export declare function span(
export declare function span<TValue>(
n: number,
value: AnyTable
value: Record<string, TValue>
): LuaMultiReturn<
[
FunIterator<string, [string, unknown]>,
FunIterator<string, [string, unknown]>
]
[FunIterator<string, [string, TValue]>, FunIterator<string, [string, TValue]>]
>;

/**
Expand Down Expand Up @@ -561,14 +558,11 @@ export declare function span<TState, TReturn extends unknown[]>(
* @returns An iterator pair.
* @see {@link https://luafun.github.io/slicing.html#fun.span}
*/
export declare function span(
predicate: (this: void, key: string, value: any) => boolean,
value: AnyTable
export declare function span<TValue>(
predicate: (this: void, key: string, value: TValue) => boolean,
value: Record<string, TValue>
): LuaMultiReturn<
[
FunIterator<string, [string, unknown]>,
FunIterator<string, [string, unknown]>
]
[FunIterator<string, [string, TValue]>, FunIterator<string, [string, TValue]>]
>;

/**
Expand Down Expand Up @@ -641,14 +635,11 @@ export declare function split_at<TState, TReturn extends unknown[]>(
* @returns An iterator pair (first `n` key-value pairs and remainder).
* @see {@link https://luafun.github.io/slicing.html#fun.split_at}
*/
export declare function split_at(
export declare function split_at<TValue>(
n: number,
value: AnyTable
value: Record<string, TValue>
): LuaMultiReturn<
[
FunIterator<string, [string, unknown]>,
FunIterator<string, [string, unknown]>
]
[FunIterator<string, [string, TValue]>, FunIterator<string, [string, TValue]>]
>;

/**
Expand Down
12 changes: 6 additions & 6 deletions src/builtin/fun/Transformations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export declare function map<TResult, TState, TReturn extends [...unknown[]]>(
* @returns A new iterator.
* @see {@link https://luafun.github.io/transformations.html#fun.map}
*/
export declare function map<TResult>(
fun: (this: void, key: string, value: unknown) => TResult,
value: AnyTable
export declare function map<TResult, TValue>(
fun: (this: void, key: string, value: TValue) => TResult,
value: Record<string, TValue>
): FunIterator<number, [TResult]>;

/**
Expand Down Expand Up @@ -109,9 +109,9 @@ export declare function enumerate<TState, TReturn extends unknown[]>(
* @returns A new iterator.
* @see {@link https://luafun.github.io/transformations.html#fun.enumerate}
*/
export declare function enumerate(
value: AnyTable
): FunIterator<number, [number, string, unknown]>;
export declare function enumerate<TValue>(
value: Record<string, TValue>
): FunIterator<number, [number, string, TValue]>;

/**
* Return a new iterator by enumerating all elements of `gen, param, state` iterator starting from `1`.
Expand Down

0 comments on commit c2f466b

Please sign in to comment.