-
Notifications
You must be signed in to change notification settings - Fork 0
/
List.ts
37 lines (30 loc) · 949 Bytes
/
List.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import * as Func from "./Function"
type BuildList<
T,
Length extends number,
List extends unknown[]
> = List["length"] extends Length ? List : BuildList<T, Length, [T, ...List]>
export type From<T, Length extends number> = BuildList<T, Length, []>
export type Set<T, N extends number, List extends unknown[]> = {
[k in keyof List]: k extends `${N}` ? T : List[k]
}
export type Tail<Tuple extends unknown[]> = ((
...args: Tuple
) => unknown) extends (_: unknown, ..._1: infer Rest) => unknown
? Rest
: never
export type Eq<X, Y> = [X, Y] extends [Y, X] ? true : false
export type LMap<K extends Func.FNames, XS extends any[]> = XS extends [
infer H,
...infer Tail
]
? [Func.Apply<K, H>, ...LMap<K, Tail>]
: []
export type Filter<K extends Func.FNames, XS extends any[]> = XS extends [
infer H,
...infer Tail
]
? Func.Apply<K, H> extends false | never
? [...Filter<K, Tail>]
: [H, ...Filter<K, Tail>]
: []