@oazmi/superbuild 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/_dnt.shims.d.ts +2 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +57 -0
- package/esm/deps/jsr.io/@oazmi/esbuild-types/0.28.0/src/mod.d.ts +598 -0
- package/esm/deps/jsr.io/@oazmi/esbuild-types/0.28.0/src/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/esbuild-types/0.28.0/src/mod.js +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/alias.d.ts +617 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/alias.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/alias.js +671 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array1d.d.ts +487 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array1d.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array1d.js +536 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array2d.d.ts +266 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array2d.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array2d.js +318 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/binder.d.ts +368 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/binder.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/binder.js +380 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/crossenv.d.ts +711 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/crossenv.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/crossenv.js +1173 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/cryptoman.d.ts +171 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/cryptoman.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/cryptoman.js +308 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/deps.d.ts +10 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/deps.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/deps.js +10 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack.d.ts +168 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack.js +236 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack_varint.d.ts +90 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack_varint.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack_varint.js +237 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericarray.d.ts +213 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericarray.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericarray.js +363 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericmethods.d.ts +233 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericmethods.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericmethods.js +256 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/pathman.d.ts +1436 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/pathman.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/pathman.js +1730 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/promiseman.d.ts +647 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/promiseman.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/promiseman.js +762 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/stringman.d.ts +538 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/stringman.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/stringman.js +626 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/struct.d.ts +734 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/struct.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/struct.js +764 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedbuffer.d.ts +137 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedbuffer.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedbuffer.js +234 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedefs.d.ts +391 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedefs.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedefs.js +8 -0
- package/esm/deps.d.ts +56 -0
- package/esm/deps.d.ts.map +1 -0
- package/esm/deps.js +37 -0
- package/esm/esbuild/metafile.d.ts +90 -0
- package/esm/esbuild/metafile.d.ts.map +1 -0
- package/esm/esbuild/metafile.js +275 -0
- package/esm/esbuild/native.d.ts +95 -0
- package/esm/esbuild/native.d.ts.map +1 -0
- package/esm/esbuild/native.js +127 -0
- package/esm/esbuild/outputfile.d.ts +86 -0
- package/esm/esbuild/outputfile.d.ts.map +1 -0
- package/esm/esbuild/outputfile.js +221 -0
- package/esm/esbuild/strongtypes.d.ts +90 -0
- package/esm/esbuild/strongtypes.d.ts.map +1 -0
- package/esm/esbuild/strongtypes.js +8 -0
- package/esm/esbuild/typedefs.d.ts +121 -0
- package/esm/esbuild/typedefs.d.ts.map +1 -0
- package/esm/esbuild/typedefs.js +55 -0
- package/esm/esbuild/weaktypes.d.ts +46 -0
- package/esm/esbuild/weaktypes.d.ts.map +1 -0
- package/esm/esbuild/weaktypes.js +8 -0
- package/esm/funcdefs.d.ts +89 -0
- package/esm/funcdefs.d.ts.map +1 -0
- package/esm/funcdefs.js +145 -0
- package/esm/mod.d.ts +4 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +2 -0
- package/esm/package.json +3 -0
- package/esm/plugins/emissions_driver.d.ts +33 -0
- package/esm/plugins/emissions_driver.d.ts.map +1 -0
- package/esm/plugins/emissions_driver.js +260 -0
- package/esm/plugins/long_build.d.ts +138 -0
- package/esm/plugins/long_build.d.ts.map +1 -0
- package/esm/plugins/long_build.js +288 -0
- package/esm/plugins/native_replica.d.ts +48 -0
- package/esm/plugins/native_replica.d.ts.map +1 -0
- package/esm/plugins/native_replica.js +122 -0
- package/esm/super/build.d.ts +53 -0
- package/esm/super/build.d.ts.map +1 -0
- package/esm/super/build.js +39 -0
- package/esm/super/build_context.d.ts +83 -0
- package/esm/super/build_context.d.ts.map +1 -0
- package/esm/super/build_context.js +124 -0
- package/esm/super/mod.d.ts +12 -0
- package/esm/super/mod.d.ts.map +1 -0
- package/esm/super/mod.js +9 -0
- package/esm/super/plugin.d.ts +23 -0
- package/esm/super/plugin.d.ts.map +1 -0
- package/esm/super/plugin.js +31 -0
- package/esm/super/plugin_build.d.ts +38 -0
- package/esm/super/plugin_build.d.ts.map +1 -0
- package/esm/super/plugin_build.js +198 -0
- package/esm/super/typedefs.d.ts +323 -0
- package/esm/super/typedefs.d.ts.map +1 -0
- package/esm/super/typedefs.js +10 -0
- package/esm/typedefs.d.ts +21 -0
- package/esm/typedefs.d.ts.map +1 -0
- package/esm/typedefs.js +5 -0
- package/license.md +37 -0
- package/package.json +88 -0
- package/readme.md +181 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
/** utility functions for creating other general purpose functions that can bind their passed function's functionality to some specific object.
|
|
2
|
+
*
|
|
3
|
+
* those are certainly a lot of words thrown in the air with no clarity as to what am I even saying.
|
|
4
|
+
* just as they say, a code block example is worth a thousand assembly instructions. here's the gist of it:
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { assertEquals } from "jsr:@std/assert"
|
|
8
|
+
*
|
|
9
|
+
* const bind_pushing_to = bindMethodFactory(Array.prototype.push) // equivalent to `bindMethodFactoryByName(Array.prototype, "push")`
|
|
10
|
+
* const bind_seek_to = bindMethodFactory(Array.prototype.at, -1) // equivalent to `bindMethodFactoryByName(Array.prototype, "at", -1)`
|
|
11
|
+
* const bind_splicing_to = bindMethodFactoryByName(Array.prototype, "splice") // equivalent to `bindMethodFactory(Array.prototype.splice)`
|
|
12
|
+
* const bind_clear_to = bindMethodFactoryByName(Array.prototype, "splice", 0) // equivalent to `bindMethodFactory(Array.prototype.splice, 0)`
|
|
13
|
+
*
|
|
14
|
+
* const my_array = [1, 2, 3, 4, 5, 6]
|
|
15
|
+
* const push_my_array = bind_pushing_to(my_array)
|
|
16
|
+
* const seek_my_array = bind_seek_to(my_array)
|
|
17
|
+
* const splice_my_array = bind_splicing_to(my_array)
|
|
18
|
+
* const clear_my_array = bind_clear_to(my_array) as (deleteCount?: number, ...items: number[]) => number[]
|
|
19
|
+
*
|
|
20
|
+
* push_my_array(7, 8, 9)
|
|
21
|
+
* assertEquals(my_array, [1, 2, 3, 4, 5, 6, 7, 8, 9])
|
|
22
|
+
* assertEquals(seek_my_array(), 9)
|
|
23
|
+
* splice_my_array(4, 3)
|
|
24
|
+
* assertEquals(my_array, [1, 2, 3, 4, 8, 9])
|
|
25
|
+
* clear_my_array()
|
|
26
|
+
* assertEquals(my_array, [])
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* you may have some amateur level questions about *why?* would anyone want to do that. here is why:
|
|
30
|
+
* - calling a method via property access is slower. so when you call an array `arr`'s push or pop methods a million times,
|
|
31
|
+
* having a bound function for that specific purpose will be quicker by about x1.3 times:
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { assertLess } from "jsr:@std/assert"
|
|
35
|
+
* import { timeIt } from "./timeman.ts"
|
|
36
|
+
*
|
|
37
|
+
* // WARNING: JIT is pretty smart, and the test consistiently fails for `i` and `j` > `10_000_000`,
|
|
38
|
+
* // this is despite my efforts to make it difficult for the JIT to optimize the slow method, by computing some modulo and only popping when it is zero.
|
|
39
|
+
* // thus to be safe, I tuned `i` and `j` down to `100_000` iterations
|
|
40
|
+
*
|
|
41
|
+
* let i = 100_000, j = 100_000, sum1 = 0, sum2 = 0
|
|
42
|
+
* const
|
|
43
|
+
* arr1 = Array(777).fill(0).map(Math.random),
|
|
44
|
+
* arr2 = Array(777).fill(0).map(Math.random)
|
|
45
|
+
*
|
|
46
|
+
* // slower way:
|
|
47
|
+
* const t1 = timeIt(() => {
|
|
48
|
+
* while(i--) {
|
|
49
|
+
* const new_length = arr1.push(Math.random())
|
|
50
|
+
* sum1 += ((new_length + i) % 3 === 0 ? arr1.pop()! : arr1.at(-1)!)
|
|
51
|
+
* }
|
|
52
|
+
* })
|
|
53
|
+
*
|
|
54
|
+
* // faster way (allegedly):
|
|
55
|
+
* const
|
|
56
|
+
* push_arr2 = Array.prototype.push.bind(arr2),
|
|
57
|
+
* pop_arr2 = Array.prototype.pop.bind(arr2),
|
|
58
|
+
* seek_arr2 = Array.prototype.at.bind(arr2, -1)
|
|
59
|
+
* const t2 = timeIt(() => {
|
|
60
|
+
* while(j--) {
|
|
61
|
+
* const new_length = push_arr2(Math.random())
|
|
62
|
+
* sum2 += ((new_length + i) % 3 === 0 ? pop_arr2()! : seek_arr2()!)
|
|
63
|
+
* }
|
|
64
|
+
* })
|
|
65
|
+
*
|
|
66
|
+
* // assertLess(t2, t1) // TODO: RIP, performance gains have diminished in deno. curse you V8 JIT.
|
|
67
|
+
* // I still do think that in non-micro-benchmarks and real life applications (where there are a variety of objects and structures),
|
|
68
|
+
* // there still is a bit of performance gain. and lets not forget the benefit of minifiability.
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* next, you may be wondering why not destructure the method or assign it to a variable?
|
|
72
|
+
* - this cannot be generally done for prototype-bound methods, because it needs the context of *who* is the caller (and therefor the *this* of interest).
|
|
73
|
+
* all builtin javascript class methods are prototype-bound. meaning that for every instance of a builtin class no new functions are specifically created for that instance,
|
|
74
|
+
* and instead, the instance holds a reference to the class's prototype object's method, but applies itself as the *this* when called.
|
|
75
|
+
*
|
|
76
|
+
* ```ts
|
|
77
|
+
* import { assertEquals, assertThrows } from "jsr:@std/assert"
|
|
78
|
+
*
|
|
79
|
+
* const arr = [1, 2, 3, 4, 5, 6]
|
|
80
|
+
*
|
|
81
|
+
* // prototype-bound methods need to be called via property access, otherwise they will loose their `this` context when uncoupled from their parent object
|
|
82
|
+
* const { push, pop } = arr
|
|
83
|
+
* assertThrows(() => push(7, 8, 9)) // `TypeError: Cannot convert undefined or null to object`
|
|
84
|
+
* assertThrows(() => pop()) // `TypeError: Cannot convert undefined or null to object`
|
|
85
|
+
*
|
|
86
|
+
* const
|
|
87
|
+
* push2 = arr.push,
|
|
88
|
+
* pop2 = arr.pop
|
|
89
|
+
* assertThrows(() => push2(7, 8, 9)) // `TypeError: Cannot convert undefined or null to object`
|
|
90
|
+
* assertThrows(() => pop2()) // `TypeError: Cannot convert undefined or null to object`
|
|
91
|
+
*
|
|
92
|
+
* // but you can do the binding yourself too to make it work
|
|
93
|
+
* const push3 = arr.push.bind(arr) // equivalent to `Array.prototype.push.bind(arr)`
|
|
94
|
+
* const pop3 = arr.pop.bind(arr) // equivalent to `Array.prototype.pop.bind(arr)`
|
|
95
|
+
* push3(7, 8, 9) // will work
|
|
96
|
+
* pop3() // will work
|
|
97
|
+
*
|
|
98
|
+
* // or use this submodule to do the same thing:
|
|
99
|
+
* // import { bind_array_pop, bind_array_push } from "@oazmi/kitchensink/binder"
|
|
100
|
+
* const push4 = bind_array_push(arr)
|
|
101
|
+
* const pop4 = bind_array_pop(arr)
|
|
102
|
+
* push4(7, 8, 9) // will work
|
|
103
|
+
* pop4() // will work
|
|
104
|
+
* ```
|
|
105
|
+
* - finally, property accesses are not easily minifiable (although they do get compressed when gzipped).
|
|
106
|
+
* however, if you bind your method calls to a variable, then it will become minifiable, which is somewhat the primary motivation for this submodule.
|
|
107
|
+
*
|
|
108
|
+
* with full automatic typing, you won't be compensating in any way.
|
|
109
|
+
* on the side note, it was figuring out the automatic typing that took me almost 16 hours just to write 3 lines of equivalent javascript code for the main 2 factory functions of this submodule.
|
|
110
|
+
* **curse you typescript!**
|
|
111
|
+
*
|
|
112
|
+
* @module
|
|
113
|
+
*/
|
|
114
|
+
/** generates a factory function that binds a class-prototype-method `func` (by reference) to the passed object `S` (which should be an instance of the class).
|
|
115
|
+
* @param func the method to generate the binding for
|
|
116
|
+
* @param args partial tuple of the first few arguments that should be passed in by default
|
|
117
|
+
* @returns a function that can bind any object `obj: S` to the said method
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* const bind_map_set = bindMethodFactory(Map.prototype.set)
|
|
122
|
+
* type ID = number
|
|
123
|
+
* const graph_edges = new Map<ID, Set<ID>>()
|
|
124
|
+
* const set_graph_edge = bind_map_set(graph_edges) // automatic type inference will correctly assign it the type: `(key: number, value: Set<number>) => Map<number, Set<number>>`
|
|
125
|
+
* const edges: [ID, ID[]][] = [[1, [1,2,3]], [2, [3,5]], [3, [4, 7]], [4, [4,5]], [5, [7]]]
|
|
126
|
+
* for (const [id, adjacent_ids] of edges) { set_graph_edge(id, new Set(adjacent_ids)) }
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* example with assigned default arguments
|
|
130
|
+
* ```ts
|
|
131
|
+
* import { assertEquals } from "jsr:@std/assert"
|
|
132
|
+
*
|
|
133
|
+
* const bind_queue_delete_bottom_n_elements = bindMethodFactory(Array.prototype.splice, 0)
|
|
134
|
+
* const queue = [1, 2, 3, 7, 7, 7, 9, 9, 9]
|
|
135
|
+
* const release_from_queue = bind_queue_delete_bottom_n_elements(queue) // automatic type inference will correctly assign it the type: `(deleteCount: number, ...items: number[]) => number[]`
|
|
136
|
+
* const test_arr: number[][] = []
|
|
137
|
+
* while (queue.length > 0) { test_arr.push(release_from_queue(3)) }
|
|
138
|
+
* assertEquals(test_arr, [
|
|
139
|
+
* [1, 2, 3],
|
|
140
|
+
* [7, 7, 7],
|
|
141
|
+
* [9, 9, 9],
|
|
142
|
+
* ])
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
export const bindMethodFactory = /*@__PURE__*/ (func, ...args) => ((thisArg) => func.bind(thisArg, ...args));
|
|
146
|
+
/** generates a factory function that binds a class-prototype-method (by name) to the passed object `S` (which should be an instance of the class).
|
|
147
|
+
* @param instance an object containing the the method (typically a prototype object, but it doesn't have to be that)
|
|
148
|
+
* @param method_name the name of the method to generate the binding for
|
|
149
|
+
* @param args partial tuple of the first few arguments that should be passed in by default
|
|
150
|
+
* @returns a function that can bind any object `obj: S` to the said method
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```ts
|
|
154
|
+
* const bind_map_set = bindMethodFactoryByName(Map.prototype, "set")
|
|
155
|
+
* type ID = number
|
|
156
|
+
* const graph_edges = new Map<ID, Set<ID>>()
|
|
157
|
+
* const set_graph_edge = bind_map_set(graph_edges) // automatic type inference will correctly assign it the type: `(key: number, value: Set<number>) => Map<number, Set<number>>`
|
|
158
|
+
* const edges: [ID, ID[]][] = [[1, [1,2,3]], [2, [3,5]], [3, [4, 7]], [4, [4,5]], [5, [7]]]
|
|
159
|
+
* for (const [id, adjacent_ids] of edges) { set_graph_edge(id, new Set(adjacent_ids)) }
|
|
160
|
+
* ```
|
|
161
|
+
*
|
|
162
|
+
* example with assigned default arguments
|
|
163
|
+
* ```ts
|
|
164
|
+
* import { assertEquals } from "jsr:@std/assert"
|
|
165
|
+
*
|
|
166
|
+
* const bind_queue_delete_bottom_n_elements = bindMethodFactoryByName(Array.prototype, "splice", 0)
|
|
167
|
+
* const queue = [1, 2, 3, 7, 7, 7, 9, 9, 9]
|
|
168
|
+
* const release_from_queue = bind_queue_delete_bottom_n_elements(queue) // automatic type inference will correctly assign it the type: `(deleteCount: number, ...items: number[]) => number[]`
|
|
169
|
+
* const test_arr: number[][] = []
|
|
170
|
+
* while (queue.length > 0) { test_arr.push(release_from_queue(3)) }
|
|
171
|
+
* assertEquals(test_arr, [
|
|
172
|
+
* [1, 2, 3],
|
|
173
|
+
* [7, 7, 7],
|
|
174
|
+
* [9, 9, 9],
|
|
175
|
+
* ])
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
export const bindMethodFactoryByName = /*@__PURE__*/ (instance, method_name, ...args) => {
|
|
179
|
+
return ((thisArg) => {
|
|
180
|
+
return instance[method_name].bind(thisArg, ...args);
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
/** binds a class-prototype-method `func` (by reference) to the passed object `self` (which should be an instance of the class), and returns that bound method.
|
|
184
|
+
* @param self the object to bind the method `func` to
|
|
185
|
+
* @param func the prototype-method to bind (by reference)
|
|
186
|
+
* @param args partial tuple of the first few arguments that should be passed in by default
|
|
187
|
+
* @returns a version of the function `func` that is now bound to the object `self`, with the default first few partial arguments `args`
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* type ID = number
|
|
192
|
+
* const graph_edges = new Map<ID, Set<ID>>()
|
|
193
|
+
* const set_graph_edge = bindMethodToSelf(graph_edges, graph_edges.set) // automatic type inference will correctly assign it the type: `(key: number, value: Set<number>) => Map<number, Set<number>>`
|
|
194
|
+
* const edges: [ID, ID[]][] = [[1, [1,2,3]], [2, [3,5]], [3, [4, 7]], [4, [4,5]], [5, [7]]]
|
|
195
|
+
* for (const [id, adjacent_ids] of edges) { set_graph_edge(id, new Set(adjacent_ids)) }
|
|
196
|
+
* ```
|
|
197
|
+
*
|
|
198
|
+
* example with assigned default arguments
|
|
199
|
+
* ```ts
|
|
200
|
+
* import { assertEquals } from "jsr:@std/assert"
|
|
201
|
+
*
|
|
202
|
+
* const queue = [1, 2, 3, 7, 7, 7, 9, 9, 9]
|
|
203
|
+
* const release_from_queue = bindMethodToSelf(queue, queue.splice, 0) // automatic type inference will correctly assign it the type: `(deleteCount: number, ...items: number[]) => number[]`
|
|
204
|
+
* const test_arr: number[][] = []
|
|
205
|
+
* while (queue.length > 0) { test_arr.push(release_from_queue(3)) }
|
|
206
|
+
* assertEquals(test_arr, [
|
|
207
|
+
* [1, 2, 3],
|
|
208
|
+
* [7, 7, 7],
|
|
209
|
+
* [9, 9, 9],
|
|
210
|
+
* ])
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
export const bindMethodToSelf = /*@__PURE__*/ (self, func, ...args) => func.bind(self, ...args);
|
|
214
|
+
/** binds a class-prototype-method (by name `method_name`) to the passed object `self` (which should be an instance of the class), and returns that bound method.
|
|
215
|
+
* @param self the object to bind the method `method_name` to
|
|
216
|
+
* @param method_name the name of the prototype-method to bind
|
|
217
|
+
* @param args partial tuple of the first few arguments that should be passed in by default
|
|
218
|
+
* @returns a version of the function `method_name` that is now bound to the object `self`, with the default first few partial arguments `args`
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```ts
|
|
222
|
+
* type ID = number
|
|
223
|
+
* const graph_edges = new Map<ID, Set<ID>>()
|
|
224
|
+
* const set_graph_edge = bindMethodToSelfByName(graph_edges, "set") // automatic type inference will correctly assign it the type: `(key: number, value: Set<number>) => Map<number, Set<number>>`
|
|
225
|
+
* const edges: [ID, ID[]][] = [[1, [1,2,3]], [2, [3,5]], [3, [4, 7]], [4, [4,5]], [5, [7]]]
|
|
226
|
+
* for (const [id, adjacent_ids] of edges) { set_graph_edge(id, new Set(adjacent_ids)) }
|
|
227
|
+
* ```
|
|
228
|
+
*
|
|
229
|
+
* example with assigned default arguments
|
|
230
|
+
* ```ts
|
|
231
|
+
* import { assertEquals } from "jsr:@std/assert"
|
|
232
|
+
*
|
|
233
|
+
* const queue = [1, 2, 3, 7, 7, 7, 9, 9, 9]
|
|
234
|
+
* const release_from_queue = bindMethodToSelfByName(queue, "splice", 0) // automatic type inference will correctly assign it the type: `(deleteCount: number, ...items: number[]) => number[]`
|
|
235
|
+
* const test_arr: number[][] = []
|
|
236
|
+
* while (queue.length > 0) { test_arr.push(release_from_queue(3)) }
|
|
237
|
+
* assertEquals(test_arr, [
|
|
238
|
+
* [1, 2, 3],
|
|
239
|
+
* [7, 7, 7],
|
|
240
|
+
* [9, 9, 9],
|
|
241
|
+
* ])
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
export const bindMethodToSelfByName = /*@__PURE__*/ (self, method_name, ...args) => self[method_name].bind(self, ...args);
|
|
245
|
+
const
|
|
246
|
+
// NOTE: the `prototypeOfClass` over here is a clone of the one in `"./srtruct.ts"`, but I want this file to be dependency free, hence is why I have to clone it.
|
|
247
|
+
prototypeOfClass = (cls) => {
|
|
248
|
+
return cls.prototype;
|
|
249
|
+
}, array_proto = /*@__PURE__*/ prototypeOfClass(Array), map_proto = /*@__PURE__*/ prototypeOfClass(Map), set_proto = /*@__PURE__*/ prototypeOfClass(Set), string_proto = /*@__PURE__*/ prototypeOfClass(String);
|
|
250
|
+
// default array methods
|
|
251
|
+
/** binding function for `Array.prototype.at`. */
|
|
252
|
+
export const bind_array_at = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "at");
|
|
253
|
+
/** binding function for `Array.prototype.concat`. */
|
|
254
|
+
export const bind_array_concat = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "concat");
|
|
255
|
+
/** binding function for `Array.prototype.copyWithin`. */
|
|
256
|
+
export const bind_array_copyWithin = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "copyWithin");
|
|
257
|
+
/** binding function for `Array.prototype.entries`. */
|
|
258
|
+
export const bind_array_entries = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "entries");
|
|
259
|
+
/** binding function for `Array.prototype.every`. */
|
|
260
|
+
export const bind_array_every = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "every");
|
|
261
|
+
/** binding function for `Array.prototype.fill`. */
|
|
262
|
+
export const bind_array_fill = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "fill");
|
|
263
|
+
/** binding function for `Array.prototype.filter`. */
|
|
264
|
+
export const bind_array_filter = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "filter");
|
|
265
|
+
/** binding function for `Array.prototype.find`. */
|
|
266
|
+
export const bind_array_find = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "find");
|
|
267
|
+
/** binding function for `Array.prototype.findIndex`. */
|
|
268
|
+
export const bind_array_findIndex = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "findIndex");
|
|
269
|
+
/** binding function for `Array.prototype.findLast`. */
|
|
270
|
+
export const bind_array_findLast = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "findLast");
|
|
271
|
+
/** binding function for `Array.prototype.findLastIndex`. */
|
|
272
|
+
export const bind_array_findLastIndex = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "findLastIndex");
|
|
273
|
+
/** binding function for `Array.prototype.flat`. */
|
|
274
|
+
export const bind_array_flat = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "flat");
|
|
275
|
+
/** binding function for `Array.prototype.flatMap`. */
|
|
276
|
+
export const bind_array_flatMap = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "flatMap");
|
|
277
|
+
/** binding function for `Array.prototype.forEach`. */
|
|
278
|
+
export const bind_array_forEach = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "forEach");
|
|
279
|
+
/** binding function for `Array.prototype.includes`. */
|
|
280
|
+
export const bind_array_includes = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "includes");
|
|
281
|
+
/** binding function for `Array.prototype.indexOf`. */
|
|
282
|
+
export const bind_array_indexOf = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "indexOf");
|
|
283
|
+
/** binding function for `Array.prototype.join`. */
|
|
284
|
+
export const bind_array_join = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "join");
|
|
285
|
+
/** binding function for `Array.prototype.keys`. */
|
|
286
|
+
export const bind_array_keys = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "keys");
|
|
287
|
+
/** binding function for `Array.prototype.lastIndexOf`. */
|
|
288
|
+
export const bind_array_lastIndexOf = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "lastIndexOf");
|
|
289
|
+
/** binding function for `Array.prototype.map`. */
|
|
290
|
+
export const bind_array_map = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "map");
|
|
291
|
+
/** binding function for `Array.prototype.pop`. */
|
|
292
|
+
export const bind_array_pop = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "pop");
|
|
293
|
+
/** binding function for `Array.prototype.push`. */
|
|
294
|
+
export const bind_array_push = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "push");
|
|
295
|
+
/** binding function for `Array.prototype.reduce`. */
|
|
296
|
+
export const bind_array_reduce = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "reduce");
|
|
297
|
+
/** binding function for `Array.prototype.reduceRight`. */
|
|
298
|
+
export const bind_array_reduceRight = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "reduceRight");
|
|
299
|
+
/** binding function for `Array.prototype.reverse`. */
|
|
300
|
+
export const bind_array_reverse = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "reverse");
|
|
301
|
+
/** binding function for `Array.prototype.shift`. */
|
|
302
|
+
export const bind_array_shift = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "shift");
|
|
303
|
+
/** binding function for `Array.prototype.slice`. */
|
|
304
|
+
export const bind_array_slice = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "slice");
|
|
305
|
+
/** binding function for `Array.prototype.some`. */
|
|
306
|
+
export const bind_array_some = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "some");
|
|
307
|
+
/** binding function for `Array.prototype.sort`. */
|
|
308
|
+
export const bind_array_sort = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "sort");
|
|
309
|
+
/** binding function for `Array.prototype.splice`. */
|
|
310
|
+
export const bind_array_splice = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "splice");
|
|
311
|
+
/** binding function for `Array.prototype.unshift`. */
|
|
312
|
+
export const bind_array_unshift = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "unshift");
|
|
313
|
+
/** binding function for `Array.prototype.toLocaleString`. */
|
|
314
|
+
export const bind_array_toLocaleString = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "toLocaleString");
|
|
315
|
+
/** binding function for `Array.prototype.toReversed`. */
|
|
316
|
+
export const bind_array_toReversed = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "toReversed");
|
|
317
|
+
/** binding function for `Array.prototype.toSorted`. */
|
|
318
|
+
export const bind_array_toSorted = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "toSorted");
|
|
319
|
+
/** binding function for `Array.prototype.toSpliced`. */
|
|
320
|
+
export const bind_array_toSpliced = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "toSpliced");
|
|
321
|
+
/** binding function for `Array.prototype.toString`. */
|
|
322
|
+
export const bind_array_toString = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "toString");
|
|
323
|
+
/** binding function for `Array.prototype.values`. */
|
|
324
|
+
export const bind_array_values = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "values");
|
|
325
|
+
/** binding function for `Array.prototype.with`. */
|
|
326
|
+
export const bind_array_with = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "with");
|
|
327
|
+
// specialized array methods
|
|
328
|
+
/** binding function for `Array.prototype.splice(0)`. */
|
|
329
|
+
export const bind_array_clear = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "splice", 0);
|
|
330
|
+
/** binding function for `Array.prototype.at(-1)`. */
|
|
331
|
+
export const bind_stack_seek = /*@__PURE__*/ bindMethodFactoryByName(array_proto, "at", -1);
|
|
332
|
+
// default set methods
|
|
333
|
+
/** binding function for `Set.prototype.add`. */
|
|
334
|
+
export const bind_set_add = /*@__PURE__*/ bindMethodFactoryByName(set_proto, "add");
|
|
335
|
+
/** binding function for `Set.prototype.clear`. */
|
|
336
|
+
export const bind_set_clear = /*@__PURE__*/ bindMethodFactoryByName(set_proto, "clear");
|
|
337
|
+
/** binding function for `Set.prototype.delete`. */
|
|
338
|
+
export const bind_set_delete = /*@__PURE__*/ bindMethodFactoryByName(set_proto, "delete");
|
|
339
|
+
/** binding function for `Set.prototype.entries`. */
|
|
340
|
+
export const bind_set_entries = /*@__PURE__*/ bindMethodFactoryByName(set_proto, "entries");
|
|
341
|
+
/** binding function for `Set.prototype.forEach`. */
|
|
342
|
+
export const bind_set_forEach = /*@__PURE__*/ bindMethodFactoryByName(set_proto, "forEach");
|
|
343
|
+
/** binding function for `Set.prototype.has`. */
|
|
344
|
+
export const bind_set_has = /*@__PURE__*/ bindMethodFactoryByName(set_proto, "has");
|
|
345
|
+
/** binding function for `Set.prototype.keys`. */
|
|
346
|
+
export const bind_set_keys = /*@__PURE__*/ bindMethodFactoryByName(set_proto, "keys");
|
|
347
|
+
/** binding function for `Set.prototype.values`. */
|
|
348
|
+
export const bind_set_values = /*@__PURE__*/ bindMethodFactoryByName(set_proto, "values");
|
|
349
|
+
// default map methods
|
|
350
|
+
/** binding function for `Map.prototype.clear`. */
|
|
351
|
+
export const bind_map_clear = /*@__PURE__*/ bindMethodFactoryByName(map_proto, "clear");
|
|
352
|
+
/** binding function for `Map.prototype.delete`. */
|
|
353
|
+
export const bind_map_delete = /*@__PURE__*/ bindMethodFactoryByName(map_proto, "delete");
|
|
354
|
+
/** binding function for `Map.prototype.entries`. */
|
|
355
|
+
export const bind_map_entries = /*@__PURE__*/ bindMethodFactoryByName(map_proto, "entries");
|
|
356
|
+
/** binding function for `Map.prototype.forEach`. */
|
|
357
|
+
export const bind_map_forEach = /*@__PURE__*/ bindMethodFactoryByName(map_proto, "forEach");
|
|
358
|
+
/** binding function for `Map.prototype.get`. */
|
|
359
|
+
export const bind_map_get = /*@__PURE__*/ bindMethodFactoryByName(map_proto, "get");
|
|
360
|
+
/** binding function for `Map.prototype.has`. */
|
|
361
|
+
export const bind_map_has = /*@__PURE__*/ bindMethodFactoryByName(map_proto, "has");
|
|
362
|
+
/** binding function for `Map.prototype.keys`. */
|
|
363
|
+
export const bind_map_keys = /*@__PURE__*/ bindMethodFactoryByName(map_proto, "keys");
|
|
364
|
+
/** binding function for `Map.prototype.set`. */
|
|
365
|
+
export const bind_map_set = /*@__PURE__*/ bindMethodFactoryByName(map_proto, "set");
|
|
366
|
+
/** binding function for `Map.prototype.values`. */
|
|
367
|
+
export const bind_map_values = /*@__PURE__*/ bindMethodFactoryByName(map_proto, "values");
|
|
368
|
+
// default string methods
|
|
369
|
+
/** binding function for `String.prototype.at`. */
|
|
370
|
+
export const bind_string_at = /*@__PURE__*/ bindMethodFactoryByName(string_proto, "at");
|
|
371
|
+
/** binding function for `String.prototype.charAt`. */
|
|
372
|
+
export const bind_string_charAt = /*@__PURE__*/ bindMethodFactoryByName(string_proto, "charAt");
|
|
373
|
+
/** binding function for `String.prototype.charCodeAt`. */
|
|
374
|
+
export const bind_string_charCodeAt = /*@__PURE__*/ bindMethodFactoryByName(string_proto, "charCodeAt");
|
|
375
|
+
/** binding function for `String.prototype.codePointAt`. */
|
|
376
|
+
export const bind_string_codePointAt = /*@__PURE__*/ bindMethodFactoryByName(string_proto, "codePointAt");
|
|
377
|
+
/** binding function for `String.prototype.startsWith`. */
|
|
378
|
+
export const bind_string_startsWith = /*@__PURE__*/ bindMethodFactoryByName(string_proto, "startsWith");
|
|
379
|
+
/** binding function for `String.prototype.endsWith`. */
|
|
380
|
+
export const bind_string_endsWith = /*@__PURE__*/ bindMethodFactoryByName(string_proto, "endsWith");
|