@stdlib/dstructs-named-typed-tuple 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/LICENSE +177 -0
- package/NOTICE +1 -0
- package/README.md +2402 -0
- package/SECURITY.md +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +7 -0
- package/docs/types/index.d.ts +1529 -0
- package/lib/ascending.js +44 -0
- package/lib/contains.js +44 -0
- package/lib/from_iterator.js +48 -0
- package/lib/from_iterator_map.js +54 -0
- package/lib/has_distinct_elements.js +52 -0
- package/lib/index.js +53 -0
- package/lib/main.js +1444 -0
- package/lib/validate.js +84 -0
- package/package.json +93 -0
|
@@ -0,0 +1,1529 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2021 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// TypeScript Version: 4.1
|
|
20
|
+
|
|
21
|
+
/* eslint-disable max-lines */
|
|
22
|
+
|
|
23
|
+
/// <reference types="@stdlib/types"/>
|
|
24
|
+
|
|
25
|
+
import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter';
|
|
26
|
+
import { TypedArray } from '@stdlib/types/array';
|
|
27
|
+
|
|
28
|
+
// Define a union type representing both iterable and non-iterable iterators:
|
|
29
|
+
type Iterator = Iter | IterableIterator;
|
|
30
|
+
|
|
31
|
+
type DType = 'float64' | 'float32' | 'int32' | 'uint32' | 'int16' | 'uint16' | 'int8' | 'uint8' | 'uint8c';
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Interface defining options.
|
|
35
|
+
*/
|
|
36
|
+
interface Options {
|
|
37
|
+
/**
|
|
38
|
+
* Default data type (default: 'float64').
|
|
39
|
+
*/
|
|
40
|
+
dtype?: DType;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Tuple name (default: 'tuple').
|
|
44
|
+
*/
|
|
45
|
+
name?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Function invoked for each tuple element.
|
|
50
|
+
*/
|
|
51
|
+
type Nullary = () => void;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Function invoked for each tuple element.
|
|
55
|
+
*
|
|
56
|
+
* @param value - tuple element
|
|
57
|
+
*/
|
|
58
|
+
type Unary = ( value: number ) => void;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Function invoked for each tuple element.
|
|
62
|
+
*
|
|
63
|
+
* @param value - tuple element
|
|
64
|
+
* @param index - tuple index
|
|
65
|
+
*/
|
|
66
|
+
type Binary = ( value: number, index: number ) => void;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Function invoked for each tuple element.
|
|
70
|
+
*
|
|
71
|
+
* @param value - tuple element
|
|
72
|
+
* @param index - tuple index
|
|
73
|
+
* @param field - tuple field name
|
|
74
|
+
*/
|
|
75
|
+
type Ternary = ( value: number, index: number, field: string ) => void;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Function invoked for each tuple element.
|
|
79
|
+
*
|
|
80
|
+
* @param value - tuple element
|
|
81
|
+
* @param index - tuple index
|
|
82
|
+
* @param field - tuple field name
|
|
83
|
+
* @param tuple - tuple on which the method is invoked
|
|
84
|
+
*/
|
|
85
|
+
type Quaternary = ( value: any, index: number, field: string, tuple: Tuple ) => void;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Function invoked for each tuple element.
|
|
89
|
+
*
|
|
90
|
+
* @param value - tuple element
|
|
91
|
+
* @param index - tuple index
|
|
92
|
+
* @param field - tuple field name
|
|
93
|
+
* @param tuple - tuple on which the method is invoked
|
|
94
|
+
*/
|
|
95
|
+
type Callback = Nullary | Unary | Binary | Ternary | Quaternary;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Predicate function which tests tuple elements.
|
|
99
|
+
*
|
|
100
|
+
* @returns boolean indicating whether tuple element passes a test
|
|
101
|
+
*/
|
|
102
|
+
type NullaryPredicate = () => boolean;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Predicate function which tests tuple elements.
|
|
106
|
+
*
|
|
107
|
+
* @param value - tuple element
|
|
108
|
+
* @returns boolean indicating whether tuple element passes a test
|
|
109
|
+
*/
|
|
110
|
+
type UnaryPredicate = ( value: number ) => boolean;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Predicate function which tests tuple elements.
|
|
114
|
+
*
|
|
115
|
+
* @param value - tuple element
|
|
116
|
+
* @param index - tuple index
|
|
117
|
+
* @returns boolean indicating whether tuple element passes a test
|
|
118
|
+
*/
|
|
119
|
+
type BinaryPredicate = ( value: number, index: number ) => boolean;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Predicate function which tests tuple elements.
|
|
123
|
+
*
|
|
124
|
+
* @param value - tuple element
|
|
125
|
+
* @param index - tuple index
|
|
126
|
+
* @param field - tuple field name
|
|
127
|
+
* @returns boolean indicating whether tuple element passes a test
|
|
128
|
+
*/
|
|
129
|
+
type TernaryPredicate = ( value: number, index: number, field: string ) => boolean;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Predicate function which tests tuple elements.
|
|
133
|
+
*
|
|
134
|
+
* @param value - tuple element
|
|
135
|
+
* @param index - tuple index
|
|
136
|
+
* @param field - tuple field name
|
|
137
|
+
* @param tuple - tuple on which the method is invoked
|
|
138
|
+
* @returns boolean indicating whether tuple element passes a test
|
|
139
|
+
*/
|
|
140
|
+
type QuaternaryPredicate = ( value: any, index: number, field: string, tuple: Tuple ) => boolean;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Predicate function which tests tuple elements.
|
|
144
|
+
*
|
|
145
|
+
* @param value - tuple element
|
|
146
|
+
* @param index - tuple index
|
|
147
|
+
* @param field - tuple field name
|
|
148
|
+
* @param tuple - tuple on which the method is invoked
|
|
149
|
+
* @returns boolean indicating whether tuple element passes a test
|
|
150
|
+
*/
|
|
151
|
+
type PredicateFunction = NullaryPredicate | UnaryPredicate | BinaryPredicate | TernaryPredicate | QuaternaryPredicate;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Function applied against an accumulator.
|
|
155
|
+
*
|
|
156
|
+
* @returns value assigned to the accumulator
|
|
157
|
+
*/
|
|
158
|
+
type NullaryReducer = () => any;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Function applied against an accumulator.
|
|
162
|
+
*
|
|
163
|
+
* @param acc - accumulated result
|
|
164
|
+
* @returns value assigned to the accumulator
|
|
165
|
+
*/
|
|
166
|
+
type UnaryReducer = ( acc: any ) => any;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Function applied against an accumulator.
|
|
170
|
+
*
|
|
171
|
+
* @param acc - accumulated result
|
|
172
|
+
* @param value - tuple element
|
|
173
|
+
* @returns value assigned to the accumulator
|
|
174
|
+
*/
|
|
175
|
+
type BinaryReducer = ( acc: any, value: number ) => any;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Function applied against an accumulator.
|
|
179
|
+
*
|
|
180
|
+
* @param acc - accumulated result
|
|
181
|
+
* @param value - tuple element
|
|
182
|
+
* @param index - tuple index
|
|
183
|
+
* @returns value assigned to the accumulator
|
|
184
|
+
*/
|
|
185
|
+
type TernaryReducer = ( acc: any, value: number, index: number ) => any;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Function applied against an accumulator.
|
|
189
|
+
*
|
|
190
|
+
* @param acc - accumulated result
|
|
191
|
+
* @param value - tuple element
|
|
192
|
+
* @param index - tuple index
|
|
193
|
+
* @param field - tuple field name
|
|
194
|
+
* @returns value assigned to the accumulator
|
|
195
|
+
*/
|
|
196
|
+
type QuaternaryReducer = ( acc: any, value: number, index: number, field: string ) => any;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Function applied against an accumulator.
|
|
200
|
+
*
|
|
201
|
+
* @param acc - accumulated result
|
|
202
|
+
* @param value - tuple element
|
|
203
|
+
* @param index - tuple index
|
|
204
|
+
* @param field - tuple field name
|
|
205
|
+
* @param tuple - tuple on which the method is invoked
|
|
206
|
+
* @returns value assigned to the accumulator
|
|
207
|
+
*/
|
|
208
|
+
type QuinaryReducer = ( acc: any, value: number, index: number, field: string, tuple: Tuple ) => any;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Function applied against an accumulator.
|
|
212
|
+
*
|
|
213
|
+
* @param acc - accumulated result
|
|
214
|
+
* @param value - tuple element
|
|
215
|
+
* @param index - tuple index
|
|
216
|
+
* @param field - tuple field name
|
|
217
|
+
* @param tuple - tuple on which the method is invoked
|
|
218
|
+
* @returns value assigned to the accumulator
|
|
219
|
+
*/
|
|
220
|
+
type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer | QuinaryReducer;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Function which specifies the sort order.
|
|
224
|
+
*
|
|
225
|
+
* ## Notes
|
|
226
|
+
*
|
|
227
|
+
* - The comparison function is provided two tuple elements, `a` and `b`, per invocation, and its return value determines the sort order as follows:
|
|
228
|
+
*
|
|
229
|
+
* - If the comparison function returns a value **less** than zero, then the method sorts `a` to an index lower than `b` (i.e., `a` should come **before** `b`).
|
|
230
|
+
* - If the comparison function returns a value **greater** than zero, then the method sorts `a` to an index higher than `b` (i.e., `b` should come **before** `a`).
|
|
231
|
+
* - If the comparison function returns **zero**, then the relative order of `a` and `b` _should_ remain unchanged.
|
|
232
|
+
*
|
|
233
|
+
*
|
|
234
|
+
* @param a - first tuple value
|
|
235
|
+
* @param b - second tuple value
|
|
236
|
+
* @returns value determining the sort order
|
|
237
|
+
*/
|
|
238
|
+
type CompareFunction = ( a: number, b: number ) => number;
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Callback invoked for each source element.
|
|
242
|
+
*
|
|
243
|
+
* @returns transformed value
|
|
244
|
+
*/
|
|
245
|
+
type FactoryNullary = () => number;
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Callback invoked for each source element.
|
|
249
|
+
*
|
|
250
|
+
* @param value - source value
|
|
251
|
+
* @returns transformed value
|
|
252
|
+
*/
|
|
253
|
+
type FactoryUnary = ( value: number ) => number;
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Callback invoked for each source element.
|
|
257
|
+
*
|
|
258
|
+
* @param value - source value
|
|
259
|
+
* @param index - source index
|
|
260
|
+
* @returns transformed value
|
|
261
|
+
*/
|
|
262
|
+
type FactoryBinary = ( value: number, index: number ) => number;
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Callback invoked for each source element.
|
|
266
|
+
*
|
|
267
|
+
* @param value - source value
|
|
268
|
+
* @param index - source index
|
|
269
|
+
* @param field - tuple field
|
|
270
|
+
* @returns transformed value
|
|
271
|
+
*/
|
|
272
|
+
type FactoryTernary = ( value: number, index: number, field: string ) => number;
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Callback invoked for each source element.
|
|
276
|
+
*
|
|
277
|
+
* @param value - source value
|
|
278
|
+
* @param index - source index
|
|
279
|
+
* @param field - tuple field
|
|
280
|
+
* @returns transformed value
|
|
281
|
+
*/
|
|
282
|
+
type FactoryCallback = FactoryNullary | FactoryUnary | FactoryBinary | FactoryTernary;
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Callback invoked for each field.
|
|
286
|
+
*
|
|
287
|
+
* @returns transformed value
|
|
288
|
+
*/
|
|
289
|
+
type FactoryObjectNullary = () => number;
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Callback invoked for each field.
|
|
293
|
+
*
|
|
294
|
+
* @param value - source object tuple field value
|
|
295
|
+
* @returns transformed value
|
|
296
|
+
*/
|
|
297
|
+
type FactoryObjectUnary = ( value: number ) => number;
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Callback invoked for each field.
|
|
301
|
+
*
|
|
302
|
+
* @param value - source object tuple field value
|
|
303
|
+
* @param field - source object tuple field name
|
|
304
|
+
* @returns transformed value
|
|
305
|
+
*/
|
|
306
|
+
type FactoryObjectBinary = ( value: number, field: string ) => number;
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Callback invoked for each field.
|
|
310
|
+
*
|
|
311
|
+
* @param value - source object tuple field value
|
|
312
|
+
* @param field - source object tuple field name
|
|
313
|
+
* @returns transformed value
|
|
314
|
+
*/
|
|
315
|
+
type FactoryObjectCallback = FactoryObjectNullary | FactoryObjectUnary | FactoryObjectBinary;
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Named typed tuple.
|
|
319
|
+
*/
|
|
320
|
+
interface Tuple {
|
|
321
|
+
/**
|
|
322
|
+
* Size (in bytes) of each tuple element.
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* var factory = namedtypedtuple( [ 'x', 'y' ] );
|
|
326
|
+
*
|
|
327
|
+
* var tuple = factory( [ 1.0, -1.0 ] );
|
|
328
|
+
*
|
|
329
|
+
* var nbytes = tuple.BYTES_PER_ELEMENT;
|
|
330
|
+
* // returns 8
|
|
331
|
+
*/
|
|
332
|
+
readonly BYTES_PER_ELEMENT: number;
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Pointer to the underlying data buffer.
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* var factory = namedtypedtuple( [ 'x', 'y' ] );
|
|
339
|
+
*
|
|
340
|
+
* var tuple = factory( [ 1.0, -1.0 ] );
|
|
341
|
+
*
|
|
342
|
+
* var buf = tuple.buffer;
|
|
343
|
+
* // returns <ArrayBuffer>
|
|
344
|
+
*/
|
|
345
|
+
readonly buffer: ArrayBuffer;
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Length (in bytes) of the tuple.
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* var factory = namedtypedtuple( [ 'x', 'y' ] );
|
|
352
|
+
*
|
|
353
|
+
* var tuple = factory( [ 1.0, -1.0 ] );
|
|
354
|
+
*
|
|
355
|
+
* var nbytes = tuple.byteLength;
|
|
356
|
+
* // returns 16
|
|
357
|
+
*/
|
|
358
|
+
readonly byteLength: number;
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Offset (in bytes) of a tuple from the start of its underlying `ArrayBuffer`.
|
|
362
|
+
*
|
|
363
|
+
* @example
|
|
364
|
+
* var ArrayBuffer = require( '@stdlib/array-buffer' );
|
|
365
|
+
*
|
|
366
|
+
* var factory = namedtypedtuple( [ 'x', 'y' ] );
|
|
367
|
+
*
|
|
368
|
+
* var tuple = factory( [ 1.0, -1.0 ] );
|
|
369
|
+
*
|
|
370
|
+
* var offset = tuple.byteOffset;
|
|
371
|
+
* // returns 0
|
|
372
|
+
*
|
|
373
|
+
* var buf = new ArrayBuffer( 64 );
|
|
374
|
+
* tuple = factory( buf, 32 );
|
|
375
|
+
*
|
|
376
|
+
* offset = tuple.byteOffset;
|
|
377
|
+
* // returns 32
|
|
378
|
+
*/
|
|
379
|
+
readonly byteOffset: number;
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Number of tuple elements.
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* var factory = namedtypedtuple( [ 'x', 'y' ] );
|
|
386
|
+
*
|
|
387
|
+
* var tuple = factory( [ 1.0, -1.0 ] );
|
|
388
|
+
*
|
|
389
|
+
* var len = tuple.length;
|
|
390
|
+
* // returns 2
|
|
391
|
+
*/
|
|
392
|
+
readonly length: number;
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Tuple name.
|
|
396
|
+
*
|
|
397
|
+
* @example
|
|
398
|
+
* // Create a tuple factory which generates tuples having the default tuple name:
|
|
399
|
+
* var factory = namedtypedtuple( [ 'x', 'y' ] );
|
|
400
|
+
*
|
|
401
|
+
* var tuple = factory( [ 1.0, -1.0 ] );
|
|
402
|
+
*
|
|
403
|
+
* var n = tuple.name;
|
|
404
|
+
* // returns 'tuple'
|
|
405
|
+
*
|
|
406
|
+
* // Create a tuple factory which generates tuples having a custom tuple name:
|
|
407
|
+
* var opts = {
|
|
408
|
+
* 'name': 'Point'
|
|
409
|
+
* };
|
|
410
|
+
* factory = namedtypedtuple( [ 'x', 'y' ], opts );
|
|
411
|
+
*
|
|
412
|
+
* tuple = factory( [ 1.0, -1.0 ] );
|
|
413
|
+
*
|
|
414
|
+
* n = tuple.name;
|
|
415
|
+
* // returns 'Point'
|
|
416
|
+
*/
|
|
417
|
+
readonly name: string;
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Returns the list of tuple fields.
|
|
421
|
+
*
|
|
422
|
+
* @example
|
|
423
|
+
* var factory = namedtypedtuple( [ 'x', 'y' ] );
|
|
424
|
+
*
|
|
425
|
+
* var tuple = factory( [ 1.0, -1.0 ] );
|
|
426
|
+
*
|
|
427
|
+
* var fields = tuple.fields;
|
|
428
|
+
* // returns [ 'x', 'y' ]
|
|
429
|
+
*/
|
|
430
|
+
readonly fields: Array<string>;
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Returns the list of tuple fields in index order.
|
|
434
|
+
*
|
|
435
|
+
* @example
|
|
436
|
+
* var factory = namedtypedtuple( [ 'x', 'y' ] );
|
|
437
|
+
*
|
|
438
|
+
* var tuple = factory( [ 1.0, -1.0 ] );
|
|
439
|
+
*
|
|
440
|
+
* // Sort tuple elements in ascending order:
|
|
441
|
+
* tuple.sort();
|
|
442
|
+
*
|
|
443
|
+
* // Get the list of tuple fields:
|
|
444
|
+
* var fields = tuple.fields;
|
|
445
|
+
* // returns [ 'x', 'y' ]
|
|
446
|
+
*
|
|
447
|
+
* // Get the list of tuple fields in index order:
|
|
448
|
+
* fields = tuple.orderedFields;
|
|
449
|
+
* // returns [ 'y', 'x' ]
|
|
450
|
+
*/
|
|
451
|
+
readonly orderedFields: Array<string>;
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Copies a sequence of elements within the tuple starting at `start` and ending at `end` (non-inclusive) to the position starting at `target`.
|
|
455
|
+
*
|
|
456
|
+
* @param target - target start index position
|
|
457
|
+
* @param start - source start index position
|
|
458
|
+
* @param end - source end index position (default: tuple.length)
|
|
459
|
+
* @returns modified tuple
|
|
460
|
+
*
|
|
461
|
+
* @example
|
|
462
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z', 'w', 'v' ] );
|
|
463
|
+
*
|
|
464
|
+
* var tuple = factory( [ 2.0, -2.0, 1.0, -1.0, 1.0 ] );
|
|
465
|
+
*
|
|
466
|
+
* var x = tuple.x;
|
|
467
|
+
* // returns 2.0
|
|
468
|
+
*
|
|
469
|
+
* var y = tuple.y;
|
|
470
|
+
* // returns -2.0
|
|
471
|
+
*
|
|
472
|
+
* // Copy the last two elements to the first two elements:
|
|
473
|
+
* tuple.copyWithin( 0, 3 );
|
|
474
|
+
*
|
|
475
|
+
* x = tuple.x;
|
|
476
|
+
* // returns -1.0
|
|
477
|
+
*
|
|
478
|
+
* y = tuple.y;
|
|
479
|
+
* // returns 1.0
|
|
480
|
+
*/
|
|
481
|
+
copyWithin( target: number, start: number, end?: number ): Tuple;
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Returns an iterator for iterating over tuple key-value pairs.
|
|
485
|
+
*
|
|
486
|
+
* @returns iterator for iterating over tuple key-value pairs
|
|
487
|
+
*
|
|
488
|
+
* @example
|
|
489
|
+
* var factory = namedtypedtuple( [ 'x', 'y' ] );
|
|
490
|
+
*
|
|
491
|
+
* var tuple = factory( [ 1.0, -1.0 ] );
|
|
492
|
+
*
|
|
493
|
+
* // Create an iterator:
|
|
494
|
+
* var it = tuple.entries();
|
|
495
|
+
*
|
|
496
|
+
* // Iterate over key-value pairs...
|
|
497
|
+
* var v = it.next().value;
|
|
498
|
+
* // returns [ 0, 'x', 1.0 ]
|
|
499
|
+
*
|
|
500
|
+
* v = it.next().value;
|
|
501
|
+
* // returns [ 1, 'y', -1.0 ]
|
|
502
|
+
*
|
|
503
|
+
* var bool = it.next().done;
|
|
504
|
+
* // returns true
|
|
505
|
+
*/
|
|
506
|
+
entries(): Iterator;
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Tests whether all tuple elements pass a test implemented by a `predicate` function.
|
|
510
|
+
*
|
|
511
|
+
* @param predicate - predicate function which tests tuple elements
|
|
512
|
+
* @param thisArg - callback execution context
|
|
513
|
+
* @returns boolean indicating whether all tuple elements pass.
|
|
514
|
+
*
|
|
515
|
+
* @example
|
|
516
|
+
* var factory = namedtypedtuple( [ 'x', 'y' ] );
|
|
517
|
+
*
|
|
518
|
+
* var tuple = factory( [ 1.0, -1.0 ] );
|
|
519
|
+
*
|
|
520
|
+
* function predicate( v ) {
|
|
521
|
+
* return ( v >= 0.0 );
|
|
522
|
+
* }
|
|
523
|
+
*
|
|
524
|
+
* var bool = tuple.every( predicate );
|
|
525
|
+
* // returns false
|
|
526
|
+
*/
|
|
527
|
+
every( predicate: PredicateFunction, thisArg?: any ): boolean;
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Returns the field of the first tuple element strictly equal to a search element.
|
|
531
|
+
*
|
|
532
|
+
* @param searchElement - search element
|
|
533
|
+
* @param fromIndex - tuple index from which to begin searching; if provided a negative value, the method resolves the start index relative to the last tuple element (default: 0)
|
|
534
|
+
* @returns tuple field
|
|
535
|
+
*
|
|
536
|
+
* @example
|
|
537
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
538
|
+
*
|
|
539
|
+
* var tuple = factory( [ 1.0, 0.0, -1.0 ] );
|
|
540
|
+
*
|
|
541
|
+
* var field = tuple.fieldOf( -1.0 );
|
|
542
|
+
* // returns 'z'
|
|
543
|
+
*
|
|
544
|
+
* field = tuple.fieldOf( 2.0 );
|
|
545
|
+
* // returns undefined
|
|
546
|
+
*/
|
|
547
|
+
fieldOf( searchElement: number, fromIndex?: number ): string | undefined;
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Fills a tuple from a `start` index to an `end` index (non-inclusive) with a provided `value`.
|
|
551
|
+
*
|
|
552
|
+
* @param value - fill value
|
|
553
|
+
* @param start - start index; if less than zero, the start index is resolved relative to the last tuple element
|
|
554
|
+
* @param end - end index (non-inclusive); if less than zero, the end index is resolved relative to the last tuple element
|
|
555
|
+
* @returns modified tuple
|
|
556
|
+
*
|
|
557
|
+
* @example
|
|
558
|
+
* var factory = namedtypedtuple( [ 'x', 'y' ] );
|
|
559
|
+
*
|
|
560
|
+
* var tuple = factory();
|
|
561
|
+
*
|
|
562
|
+
* // Set all tuple elements to the same value:
|
|
563
|
+
* tuple.fill( 2.0 );
|
|
564
|
+
*
|
|
565
|
+
* var x = tuple.x;
|
|
566
|
+
* // returns 2.0
|
|
567
|
+
*
|
|
568
|
+
* var y = tuple.y;
|
|
569
|
+
* // returns 2.0
|
|
570
|
+
*
|
|
571
|
+
* // Set all tuple elements starting from the first index to the same value:
|
|
572
|
+
* tuple.fill( 3.0, 1 );
|
|
573
|
+
*
|
|
574
|
+
* x = tuple.x;
|
|
575
|
+
* // returns 2.0
|
|
576
|
+
*
|
|
577
|
+
* y = tuple.y;
|
|
578
|
+
* // returns 3.0
|
|
579
|
+
*
|
|
580
|
+
* // Set all tuple elements, except the last element, to the same value:
|
|
581
|
+
* tuple.fill( 4.0, 0, tuple.length-1 );
|
|
582
|
+
*
|
|
583
|
+
* x = tuple.x;
|
|
584
|
+
* // returns 4.0
|
|
585
|
+
*
|
|
586
|
+
* y = tuple.y;
|
|
587
|
+
* // returns 3.0
|
|
588
|
+
*/
|
|
589
|
+
fill( value: number, start?: number, end?: number ): Tuple;
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* Creates a new tuple (of the same data type as the host tuple) which includes those elements for which a `predicate` function returns a truthy value.
|
|
593
|
+
*
|
|
594
|
+
* @param predicate - predicate function which filters tuple elements
|
|
595
|
+
* @param thisArg - callback execution context
|
|
596
|
+
* @returns a new named typed tuple
|
|
597
|
+
*
|
|
598
|
+
* @example
|
|
599
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
600
|
+
*
|
|
601
|
+
* var p1 = factory( [ 1.0, 0.0, -1.0 ] );
|
|
602
|
+
*
|
|
603
|
+
* function predicate( v ) {
|
|
604
|
+
* return ( v >= 0.0 );
|
|
605
|
+
* }
|
|
606
|
+
*
|
|
607
|
+
* var p2 = p1.filter( predicate );
|
|
608
|
+
*
|
|
609
|
+
* var f = p2.fields;
|
|
610
|
+
* // returns [ 'x', 'y' ]
|
|
611
|
+
*/
|
|
612
|
+
filter( predicate: PredicateFunction, thisArg?: any ): Tuple;
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* Returns the first tuple element for which a provided `predicate` function returns a truthy value.
|
|
616
|
+
*
|
|
617
|
+
* @param predicate - predicate function which tests tuple elements
|
|
618
|
+
* @param thisArg - callback execution context
|
|
619
|
+
* @returns tuple element
|
|
620
|
+
*
|
|
621
|
+
* @example
|
|
622
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
623
|
+
*
|
|
624
|
+
* var tuple = factory( [ 1.0, 0.0, -1.0 ] );
|
|
625
|
+
*
|
|
626
|
+
* function predicate( v ) {
|
|
627
|
+
* return ( v < 0.0 );
|
|
628
|
+
* }
|
|
629
|
+
*
|
|
630
|
+
* var v = tuple.find( predicate );
|
|
631
|
+
* // returns -1.0
|
|
632
|
+
*/
|
|
633
|
+
find( predicate: PredicateFunction, thisArg?: any ): number | undefined;
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* Returns the field of the first tuple element for which a provided `predicate` function returns a truthy value.
|
|
637
|
+
*
|
|
638
|
+
* @param predicate - predicate function which tests tuple elements
|
|
639
|
+
* @param thisArg - callback execution context
|
|
640
|
+
* @returns tuple field
|
|
641
|
+
*
|
|
642
|
+
* @example
|
|
643
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
644
|
+
*
|
|
645
|
+
* var tuple = factory( [ 1.0, 0.0, -1.0 ] );
|
|
646
|
+
*
|
|
647
|
+
* function predicate( v ) {
|
|
648
|
+
* return ( v < 0.0 );
|
|
649
|
+
* }
|
|
650
|
+
*
|
|
651
|
+
* var field = tuple.findField( predicate );
|
|
652
|
+
* // returns 'z'
|
|
653
|
+
*/
|
|
654
|
+
findField( predicate: PredicateFunction, thisArg?: any ): string | undefined;
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* Returns the index of the first tuple element for which a provided `predicate` function returns a truthy value.
|
|
658
|
+
*
|
|
659
|
+
* @param predicate - predicate function which tests tuple elements
|
|
660
|
+
* @param thisArg - callback execution context
|
|
661
|
+
* @returns tuple index
|
|
662
|
+
*
|
|
663
|
+
* @example
|
|
664
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
665
|
+
*
|
|
666
|
+
* var tuple = factory( [ 1.0, 0.0, -1.0 ] );
|
|
667
|
+
*
|
|
668
|
+
* function predicate( v ) {
|
|
669
|
+
* return ( v < 0.0 );
|
|
670
|
+
* }
|
|
671
|
+
*
|
|
672
|
+
* var idx = tuple.findIndex( predicate );
|
|
673
|
+
* // returns 2
|
|
674
|
+
*/
|
|
675
|
+
findIndex( predicate: PredicateFunction, thisArg?: any ): number | undefined;
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Invokes a callback for each tuple element.
|
|
679
|
+
*
|
|
680
|
+
* @param fcn - function to invoke for each tuple element
|
|
681
|
+
* @param thisArg - callback execution context
|
|
682
|
+
*
|
|
683
|
+
* @example
|
|
684
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
685
|
+
*
|
|
686
|
+
* var tuple = factory( [ 1.0, 0.0, -1.0 ], 'int32' );
|
|
687
|
+
*
|
|
688
|
+
* var str = '';
|
|
689
|
+
*
|
|
690
|
+
* function fcn( v, i, f ) {
|
|
691
|
+
* str += f + '=' + v;
|
|
692
|
+
* if ( i < tuple.length-1 ) {
|
|
693
|
+
* str += ' ';
|
|
694
|
+
* }
|
|
695
|
+
* }
|
|
696
|
+
*
|
|
697
|
+
* tuple.forEach( fcn );
|
|
698
|
+
*
|
|
699
|
+
* console.log( str );
|
|
700
|
+
* // => 'x=1 y=0 z=-1'
|
|
701
|
+
*/
|
|
702
|
+
forEach( fcn: Callback, thisArg?: any ): void;
|
|
703
|
+
|
|
704
|
+
/**
|
|
705
|
+
* Returns a `boolean` indicating whether a tuple includes a search element.
|
|
706
|
+
*
|
|
707
|
+
* @param searchElement - search element
|
|
708
|
+
* @param fromIndex - tuple index from which to begin searching; if provided a negative value, the method resolves the start index relative to the last tuple element (default: 0)
|
|
709
|
+
* @returns boolean indicating whether a tuple includes a search element
|
|
710
|
+
*
|
|
711
|
+
* @example
|
|
712
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
713
|
+
*
|
|
714
|
+
* var tuple = factory( [ 1.0, 0.0, -1.0 ] );
|
|
715
|
+
*
|
|
716
|
+
* var bool = tuple.includes( -1.0 );
|
|
717
|
+
* // returns true
|
|
718
|
+
*
|
|
719
|
+
* bool = tuple.includes( 2.0 );
|
|
720
|
+
* // returns false
|
|
721
|
+
*/
|
|
722
|
+
includes( searchElement: number, fromIndex?: number ): boolean;
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* Returns the index of the first tuple element strictly equal to a search element.
|
|
726
|
+
*
|
|
727
|
+
* @param searchElement - search element
|
|
728
|
+
* @param fromIndex - tuple index from which to begin searching; if provided a negative value, the method resolves the start index relative to the last tuple element (default: 0)
|
|
729
|
+
* @returns tuple index
|
|
730
|
+
*
|
|
731
|
+
* @example
|
|
732
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
733
|
+
*
|
|
734
|
+
* var tuple = factory( [ 1.0, 0.0, -1.0 ] );
|
|
735
|
+
*
|
|
736
|
+
* var idx = tuple.indexOf( -1.0 );
|
|
737
|
+
* // returns 2
|
|
738
|
+
*
|
|
739
|
+
* idx = tuple.indexOf( 2.0 );
|
|
740
|
+
* // returns -1
|
|
741
|
+
*/
|
|
742
|
+
indexOf( searchElement: number, fromIndex?: number ): number;
|
|
743
|
+
|
|
744
|
+
/**
|
|
745
|
+
* Converts a tuple index to a field name.
|
|
746
|
+
*
|
|
747
|
+
* @param ind - tuple index; if less than zero, the method resolves the index relative to the last tuple element
|
|
748
|
+
* @returns field name
|
|
749
|
+
*
|
|
750
|
+
* @example
|
|
751
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
752
|
+
*
|
|
753
|
+
* var tuple = factory( [ 1.0, 0.0, -1.0 ] );
|
|
754
|
+
*
|
|
755
|
+
* var field = tuple.ind2key( 1 );
|
|
756
|
+
* // returns 'y'
|
|
757
|
+
*
|
|
758
|
+
* field = tuple.ind2key( 100 );
|
|
759
|
+
* // returns undefined
|
|
760
|
+
*/
|
|
761
|
+
ind2key( ind: number ): string | undefined;
|
|
762
|
+
|
|
763
|
+
/**
|
|
764
|
+
* Serializes a tuple by joining all tuple elements as a string.
|
|
765
|
+
*
|
|
766
|
+
* @param separator - string delineating tuple elements (default: ',')
|
|
767
|
+
* @returns tuple serialized as a string
|
|
768
|
+
*
|
|
769
|
+
* @example
|
|
770
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
771
|
+
*
|
|
772
|
+
* var tuple = factory( [ 1.0, 0.0, -1.0 ], 'int32' );
|
|
773
|
+
*
|
|
774
|
+
* var str = tuple.join();
|
|
775
|
+
* // returns '1,0,-1'
|
|
776
|
+
*
|
|
777
|
+
* @example
|
|
778
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
779
|
+
*
|
|
780
|
+
* var tuple = factory( [ 1.0, 0.0, -1.0 ], 'int32' );
|
|
781
|
+
*
|
|
782
|
+
* var str = tuple.join( '|' );
|
|
783
|
+
* // returns '1|0|-1'
|
|
784
|
+
*/
|
|
785
|
+
join( separator?: string ): string;
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* Returns an iterator for iterating over tuple keys.
|
|
789
|
+
*
|
|
790
|
+
* @returns iterator for iterating over tuple keys
|
|
791
|
+
*
|
|
792
|
+
* @example
|
|
793
|
+
* var factory = namedtypedtuple( [ 'x', 'y' ] );
|
|
794
|
+
*
|
|
795
|
+
* var tuple = factory( [ 1.0, -1.0 ] );
|
|
796
|
+
*
|
|
797
|
+
* // Create an iterator:
|
|
798
|
+
* var it = tuple.keys();
|
|
799
|
+
*
|
|
800
|
+
* // Iterate over keys...
|
|
801
|
+
* var v = it.next().value;
|
|
802
|
+
* // returns [ 0, 'x' ]
|
|
803
|
+
*
|
|
804
|
+
* v = it.next().value;
|
|
805
|
+
* // returns [ 1, 'y' ]
|
|
806
|
+
*
|
|
807
|
+
* var bool = it.next().done;
|
|
808
|
+
* // returns true
|
|
809
|
+
*/
|
|
810
|
+
keys(): Iterator;
|
|
811
|
+
|
|
812
|
+
/**
|
|
813
|
+
* Converts a field name to a tuple index.
|
|
814
|
+
*
|
|
815
|
+
* @param field - tuple field name
|
|
816
|
+
* @returns tuple index
|
|
817
|
+
*
|
|
818
|
+
* @example
|
|
819
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
820
|
+
*
|
|
821
|
+
* var tuple = factory( [ 1.0, 0.0, -1.0 ] );
|
|
822
|
+
*
|
|
823
|
+
* var idx = tuple.key2ind( 'y' );
|
|
824
|
+
* // returns 1
|
|
825
|
+
*
|
|
826
|
+
* idx = tuple.key2ind( 'foo' );
|
|
827
|
+
* // returns -1
|
|
828
|
+
*/
|
|
829
|
+
key2ind( field: string ): number;
|
|
830
|
+
|
|
831
|
+
/**
|
|
832
|
+
* Returns the field of the last tuple element strictly equal to a search element, iterating from right to left.
|
|
833
|
+
*
|
|
834
|
+
* @param searchElement - search element
|
|
835
|
+
* @param fromIndex - tuple index from which to begin searching; if provided a negative value, the method resolves the start index relative to the last tuple element (default: -1)
|
|
836
|
+
* @returns tuple field
|
|
837
|
+
*
|
|
838
|
+
* @example
|
|
839
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z', 'w', 'v' ] );
|
|
840
|
+
*
|
|
841
|
+
* var tuple = factory( [ 1.0, 0.0, -1.0, 0.0, 1.0 ] );
|
|
842
|
+
*
|
|
843
|
+
* var field = tuple.lastFieldOf( 0.0 );
|
|
844
|
+
* // returns 'w'
|
|
845
|
+
*
|
|
846
|
+
* field = tuple.lastFieldOf( 2.0 );
|
|
847
|
+
* // returns undefined
|
|
848
|
+
*/
|
|
849
|
+
lastFieldOf( searchElement: number, fromIndex?: number ): string | undefined;
|
|
850
|
+
|
|
851
|
+
/**
|
|
852
|
+
* Returns the index of the last tuple element strictly equal to a search element, iterating from right to left.
|
|
853
|
+
*
|
|
854
|
+
* @param searchElement - search element
|
|
855
|
+
* @param fromIndex - tuple index from which to begin searching; if provided a negative value, the method resolves the start index relative to the last tuple element (default: -1)
|
|
856
|
+
* @returns tuple index
|
|
857
|
+
*
|
|
858
|
+
* @example
|
|
859
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z', 'w', 'v' ] );
|
|
860
|
+
*
|
|
861
|
+
* var tuple = factory( [ 1.0, 0.0, -1.0, 0.0, 1.0 ] );
|
|
862
|
+
*
|
|
863
|
+
* var idx = tuple.lastIndexOf( 0.0 );
|
|
864
|
+
* // returns 3
|
|
865
|
+
*
|
|
866
|
+
* idx = tuple.lastIndexOf( 2.0 );
|
|
867
|
+
* // returns -1
|
|
868
|
+
*/
|
|
869
|
+
lastIndexOf( searchElement: number, fromIndex?: number ): number | undefined;
|
|
870
|
+
|
|
871
|
+
/**
|
|
872
|
+
* Maps each tuple element to an element in a new tuple having the same data type as the host tuple.
|
|
873
|
+
*
|
|
874
|
+
* @param fcn - function which maps tuple elements to elements in the new tuple
|
|
875
|
+
* @param thisArg - callback execution context
|
|
876
|
+
* @returns a new named typed tuple
|
|
877
|
+
*
|
|
878
|
+
* @example
|
|
879
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
880
|
+
*
|
|
881
|
+
* var p1 = factory( [ 1.0, 0.0, -1.0 ] );
|
|
882
|
+
*
|
|
883
|
+
* function fcn( v ) {
|
|
884
|
+
* return v * 2.0;
|
|
885
|
+
* }
|
|
886
|
+
*
|
|
887
|
+
* var p2 = p1.map( fcn );
|
|
888
|
+
*
|
|
889
|
+
* var x = p2.x;
|
|
890
|
+
* // returns 2.0
|
|
891
|
+
*
|
|
892
|
+
* var y = p2.y;
|
|
893
|
+
* // returns 0.0
|
|
894
|
+
*
|
|
895
|
+
* var z = p2.z;
|
|
896
|
+
* // returns -2.0
|
|
897
|
+
*/
|
|
898
|
+
map( fcn: Callback, thisArg?: any ): Tuple;
|
|
899
|
+
|
|
900
|
+
/**
|
|
901
|
+
* Applies a function against an accumulator and each element in a tuple and returns the accumulated result.
|
|
902
|
+
*
|
|
903
|
+
* ## Notes
|
|
904
|
+
*
|
|
905
|
+
* - If provided an initial value, the method invokes a provided function with the initial value as the first argument and the first tuple element as the second argument.
|
|
906
|
+
* - If not provided an initial value, the method invokes a provided function with the first tuple element as the first argument and the second tuple element as the second argument.
|
|
907
|
+
*
|
|
908
|
+
* @param fcn - function to apply
|
|
909
|
+
* @param initialValue - initial accumulation value
|
|
910
|
+
* @returns accumulated result
|
|
911
|
+
*
|
|
912
|
+
* @example
|
|
913
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
914
|
+
*
|
|
915
|
+
* var tuple = factory( [ 2.0, 0.0, -3.0 ] );
|
|
916
|
+
*
|
|
917
|
+
* function fcn( acc, v ) {
|
|
918
|
+
* return acc + ( v*v );
|
|
919
|
+
* }
|
|
920
|
+
*
|
|
921
|
+
* var v = tuple.reduce( fcn );
|
|
922
|
+
* // returns 11.0
|
|
923
|
+
*/
|
|
924
|
+
reduce( fcn: Reducer, initialValue?: any ): any;
|
|
925
|
+
|
|
926
|
+
/**
|
|
927
|
+
* Applies a function against an accumulator and each element in a tuple and returns the accumulated result, iterating from right to left.
|
|
928
|
+
*
|
|
929
|
+
* ## Notes
|
|
930
|
+
*
|
|
931
|
+
* - If provided an initial value, the method invokes a provided function with the initial value as the first argument and the last tuple element as the second argument.
|
|
932
|
+
* - If not provided an initial value, the method invokes a provided function with the last tuple element as the first argument and the second-to-last tuple element as the second argument.
|
|
933
|
+
*
|
|
934
|
+
* @param fcn - function to apply
|
|
935
|
+
* @param initialValue - initial accumulation value
|
|
936
|
+
* @returns accumulated result
|
|
937
|
+
*
|
|
938
|
+
* @example
|
|
939
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
940
|
+
*
|
|
941
|
+
* var tuple = factory( [ 2.0, 0.0, -3.0 ] );
|
|
942
|
+
*
|
|
943
|
+
* function fcn( acc, v ) {
|
|
944
|
+
* return acc + ( v*v );
|
|
945
|
+
* }
|
|
946
|
+
*
|
|
947
|
+
* var v = tuple.reduceRight( fcn );
|
|
948
|
+
* // returns 1.0
|
|
949
|
+
*/
|
|
950
|
+
reduceRight( fcn: Reducer, initialValue?: any ): any;
|
|
951
|
+
|
|
952
|
+
/**
|
|
953
|
+
* Reverses a tuple **in-place** (thus mutating the tuple on which the method is invoked).
|
|
954
|
+
*
|
|
955
|
+
* @returns modified tuple
|
|
956
|
+
*
|
|
957
|
+
* @example
|
|
958
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
959
|
+
*
|
|
960
|
+
* var tuple = factory( [ 2.0, 0.0, -3.0 ] );
|
|
961
|
+
*
|
|
962
|
+
* var x = tuple[ 0 ];
|
|
963
|
+
* // returns 2.0
|
|
964
|
+
*
|
|
965
|
+
* x = tuple.x;
|
|
966
|
+
* // returns 2.0
|
|
967
|
+
*
|
|
968
|
+
* // Reverse the tuple:
|
|
969
|
+
* tuple.reverse();
|
|
970
|
+
*
|
|
971
|
+
* var fields = tuple.orderedFields;
|
|
972
|
+
* // returns [ 'z', 'y', 'x' ]
|
|
973
|
+
*
|
|
974
|
+
* var z = tuple[ 0 ];
|
|
975
|
+
* // returns -3.0
|
|
976
|
+
*
|
|
977
|
+
* // Tuple field assignments do NOT change:
|
|
978
|
+
* x = tuple.x;
|
|
979
|
+
* // returns 2.0
|
|
980
|
+
*/
|
|
981
|
+
reverse(): Tuple;
|
|
982
|
+
|
|
983
|
+
/**
|
|
984
|
+
* Sets tuple elements.
|
|
985
|
+
*
|
|
986
|
+
* @param arr - source array containing tuple values to set
|
|
987
|
+
* @param offset - tuple index at which to start writing values (default: 0)
|
|
988
|
+
*
|
|
989
|
+
* @example
|
|
990
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
991
|
+
*
|
|
992
|
+
* var tuple = factory( [ 1.0, 0.0, -1.0 ] );
|
|
993
|
+
*
|
|
994
|
+
* var y = tuple[ 1 ];
|
|
995
|
+
* // returns 0.0
|
|
996
|
+
*
|
|
997
|
+
* y = tuple.y;
|
|
998
|
+
* // returns 0.0
|
|
999
|
+
*
|
|
1000
|
+
* // Set the first two tuple elements:
|
|
1001
|
+
* tuple.set( [ -2.0, 2.0 ] );
|
|
1002
|
+
*
|
|
1003
|
+
* var x = tuple[ 0 ];
|
|
1004
|
+
* // returns -2.0
|
|
1005
|
+
*
|
|
1006
|
+
* x = tuple.x;
|
|
1007
|
+
* // returns -2.0
|
|
1008
|
+
*
|
|
1009
|
+
* y = tuple[ 1 ];
|
|
1010
|
+
* // returns 2.0
|
|
1011
|
+
*
|
|
1012
|
+
* y = tuple.y;
|
|
1013
|
+
* // returns 2.0
|
|
1014
|
+
*/
|
|
1015
|
+
set( arr: ArrayLike<number>, offset?: number ): void;
|
|
1016
|
+
|
|
1017
|
+
/**
|
|
1018
|
+
* Copies tuple elements to a new tuple with the same underlying data type as the host tuple.
|
|
1019
|
+
*
|
|
1020
|
+
* @param begin - start element index (inclusive); if less than zero, the start index is resolved relative to the last tuple element (default: 0)
|
|
1021
|
+
* @param end - end element index (exclusive); if less than zero, the end index is resolved relative to the last tuple element (default: tuple.length)
|
|
1022
|
+
*
|
|
1023
|
+
* @example
|
|
1024
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
1025
|
+
*
|
|
1026
|
+
* var p1 = factory( [ 1.0, 0.0, -1.0 ] );
|
|
1027
|
+
*
|
|
1028
|
+
* var p2 = p1.slice();
|
|
1029
|
+
*
|
|
1030
|
+
* var bool = ( p1 === p2 );
|
|
1031
|
+
* // returns false
|
|
1032
|
+
*
|
|
1033
|
+
* bool = ( p1.buffer === p2.buffer );
|
|
1034
|
+
* // returns false
|
|
1035
|
+
*
|
|
1036
|
+
* var x = p2.x;
|
|
1037
|
+
* // returns 1.0
|
|
1038
|
+
*
|
|
1039
|
+
* var y = p2.y;
|
|
1040
|
+
* // returns 0.0
|
|
1041
|
+
*
|
|
1042
|
+
* var z = p2.z;
|
|
1043
|
+
* // returns -1.0
|
|
1044
|
+
*/
|
|
1045
|
+
slice( begin?: number, end?: number ): Tuple;
|
|
1046
|
+
|
|
1047
|
+
/**
|
|
1048
|
+
* Tests whether at least one tuple element passes a test implemented by a `predicate` function.
|
|
1049
|
+
*
|
|
1050
|
+
* @param predicate - predicate function which tests tuple elements
|
|
1051
|
+
* @param thisArg - callback execution context
|
|
1052
|
+
* @returns boolean indicating whether at least one tuple element passes
|
|
1053
|
+
*
|
|
1054
|
+
* @example
|
|
1055
|
+
* var factory = namedtypedtuple( [ 'x', 'y' ] );
|
|
1056
|
+
*
|
|
1057
|
+
* var tuple = factory( [ 1.0, -1.0 ] );
|
|
1058
|
+
*
|
|
1059
|
+
* function predicate( v ) {
|
|
1060
|
+
* return ( v < 0.0 );
|
|
1061
|
+
* }
|
|
1062
|
+
*
|
|
1063
|
+
* var bool = tuple.some( predicate );
|
|
1064
|
+
* // returns true
|
|
1065
|
+
*
|
|
1066
|
+
* @example
|
|
1067
|
+
* var factory = namedtypedtuple( [ 'x', 'y' ] );
|
|
1068
|
+
*
|
|
1069
|
+
* var tuple = factory( [ 1.0, 1.0 ] );
|
|
1070
|
+
*
|
|
1071
|
+
* function predicate( v ) {
|
|
1072
|
+
* this.count += 1;
|
|
1073
|
+
* return ( v < 0.0 );
|
|
1074
|
+
* }
|
|
1075
|
+
*
|
|
1076
|
+
* var ctx = {
|
|
1077
|
+
* 'count': 0
|
|
1078
|
+
* };
|
|
1079
|
+
*
|
|
1080
|
+
* var bool = tuple.some( predicate, ctx );
|
|
1081
|
+
* // returns false
|
|
1082
|
+
*
|
|
1083
|
+
* var n = ctx.count;
|
|
1084
|
+
* // returns 2
|
|
1085
|
+
*/
|
|
1086
|
+
some( predicate: PredicateFunction, thisArg?: any ): boolean;
|
|
1087
|
+
|
|
1088
|
+
/**
|
|
1089
|
+
* Sorts a tuple **in-place** (thus mutating the tuple on which the method is invoked).
|
|
1090
|
+
*
|
|
1091
|
+
* ## Notes
|
|
1092
|
+
*
|
|
1093
|
+
* - By default, the method sorts tuple elements in ascending order. To impose a custom order, provide a `compareFunction`.
|
|
1094
|
+
*
|
|
1095
|
+
* @param compareFunction - function which specifies the sort order; the default sort order is ascending order
|
|
1096
|
+
* @returns modified tuple
|
|
1097
|
+
*
|
|
1098
|
+
* @example
|
|
1099
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
1100
|
+
*
|
|
1101
|
+
* var tuple = factory( [ 2.0, -3.0, 0.0 ] );
|
|
1102
|
+
*
|
|
1103
|
+
* var x = tuple[ 0 ];
|
|
1104
|
+
* // returns 2.0
|
|
1105
|
+
*
|
|
1106
|
+
* x = tuple.x;
|
|
1107
|
+
* // returns 2.0
|
|
1108
|
+
*
|
|
1109
|
+
* // Sort the tuple (in ascending order):
|
|
1110
|
+
* tuple.sort();
|
|
1111
|
+
*
|
|
1112
|
+
* var fields = tuple.orderedFields;
|
|
1113
|
+
* // returns [ 'y', 'z', 'x' ]
|
|
1114
|
+
*
|
|
1115
|
+
* var y = tuple[ 0 ];
|
|
1116
|
+
* // returns -3.0
|
|
1117
|
+
*
|
|
1118
|
+
* // Tuple field assignments do NOT change:
|
|
1119
|
+
* x = tuple.x;
|
|
1120
|
+
* // returns 2.0
|
|
1121
|
+
*
|
|
1122
|
+
* @example
|
|
1123
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
1124
|
+
*
|
|
1125
|
+
* var tuple = factory( [ 2.0, -3.0, 0.0 ] );
|
|
1126
|
+
*
|
|
1127
|
+
* var x = tuple[ 0 ];
|
|
1128
|
+
* // returns 2.0
|
|
1129
|
+
*
|
|
1130
|
+
* x = tuple.x;
|
|
1131
|
+
* // returns 2.0
|
|
1132
|
+
*
|
|
1133
|
+
* function descending( a, b ) {
|
|
1134
|
+
* return b - a;
|
|
1135
|
+
* }
|
|
1136
|
+
*
|
|
1137
|
+
* // Sort the tuple (in descending order):
|
|
1138
|
+
* tuple.sort( descending );
|
|
1139
|
+
*
|
|
1140
|
+
* var fields = tuple.orderedFields;
|
|
1141
|
+
* // returns [ 'x', 'z', 'y' ]
|
|
1142
|
+
*
|
|
1143
|
+
* var z = tuple[ 1 ];
|
|
1144
|
+
* // returns 0.0
|
|
1145
|
+
*
|
|
1146
|
+
* // Tuple field assignments do NOT change:
|
|
1147
|
+
* y = tuple.y;
|
|
1148
|
+
* // returns -3.0
|
|
1149
|
+
*/
|
|
1150
|
+
sort( compareFunction?: CompareFunction ): Tuple;
|
|
1151
|
+
|
|
1152
|
+
/**
|
|
1153
|
+
* Creates a new typed array over the same underlying ArrayBuffer and with the same underlying data type as the host tuple.
|
|
1154
|
+
*
|
|
1155
|
+
* @param begin - start element index (inclusive); if less than zero, the start index is resolved relative to the last tuple element (default: 0)
|
|
1156
|
+
* @param end - end element index (exclusive); if less than zero, the end index is resolved relative to the last tuple element (default: tuple.length)
|
|
1157
|
+
* @returns a new typed array view
|
|
1158
|
+
*
|
|
1159
|
+
* @example
|
|
1160
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
1161
|
+
*
|
|
1162
|
+
* var tuple = factory( [ 1.0, 0.0, -1.0 ] );
|
|
1163
|
+
*
|
|
1164
|
+
* var arr = tuple.subarray();
|
|
1165
|
+
* // returns <Float64Array>[ 1.0, 0.0, -1.0 ]
|
|
1166
|
+
*
|
|
1167
|
+
* @example
|
|
1168
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
1169
|
+
*
|
|
1170
|
+
* var tuple = factory( [ 1.0, 0.0, -1.0 ] );
|
|
1171
|
+
*
|
|
1172
|
+
* var arr = tuple.subarray( 1 );
|
|
1173
|
+
* // returns <Float64Array>[ 0.0, -1.0 ]
|
|
1174
|
+
*
|
|
1175
|
+
* @example
|
|
1176
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
1177
|
+
*
|
|
1178
|
+
* var tuple = factory( [ 1.0, 0.0, -1.0 ] );
|
|
1179
|
+
*
|
|
1180
|
+
* var arr = tuple.subarray( 0, 2 );
|
|
1181
|
+
* // returns <Float64Array>[ 1.0, 0.0 ]
|
|
1182
|
+
*/
|
|
1183
|
+
subarray( begin?: number, end?: number ): TypedArray;
|
|
1184
|
+
|
|
1185
|
+
/**
|
|
1186
|
+
* Creates a new named typed tuple over the same underlying ArrayBuffer and with the same underlying data type as the host tuple.
|
|
1187
|
+
*
|
|
1188
|
+
* @param begin - start element index (inclusive); if less than zero, the start index is resolved relative to the last tuple element (default: 0)
|
|
1189
|
+
* @param end - end element index (exclusive); if less than zero, the end index is resolved relative to the last tuple element (default: tuple.length)
|
|
1190
|
+
* @returns a new named typed tuple
|
|
1191
|
+
*
|
|
1192
|
+
* @example
|
|
1193
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
1194
|
+
*
|
|
1195
|
+
* var p1 = factory( [ 1.0, 0.0, -1.0 ] );
|
|
1196
|
+
*
|
|
1197
|
+
* var p2 = p1.subtuple();
|
|
1198
|
+
*
|
|
1199
|
+
* var bool = ( p1 === p2 );
|
|
1200
|
+
* // returns false
|
|
1201
|
+
*
|
|
1202
|
+
* bool = ( p1.buffer === p2.buffer );
|
|
1203
|
+
* // returns true
|
|
1204
|
+
*
|
|
1205
|
+
* var len = p2.length;
|
|
1206
|
+
* // returns 3
|
|
1207
|
+
*
|
|
1208
|
+
* var x = p2.x;
|
|
1209
|
+
* // returns 1.0
|
|
1210
|
+
*
|
|
1211
|
+
* var y = p2.y;
|
|
1212
|
+
* // returns 0.0
|
|
1213
|
+
*
|
|
1214
|
+
* var z = p2.z;
|
|
1215
|
+
* // returns -1.0
|
|
1216
|
+
*/
|
|
1217
|
+
subtuple( begin?: number, end?: number ): Tuple;
|
|
1218
|
+
|
|
1219
|
+
/**
|
|
1220
|
+
* Serializes a tuple as JSON.
|
|
1221
|
+
*
|
|
1222
|
+
* @returns a tuple JSON representation
|
|
1223
|
+
*
|
|
1224
|
+
* @example
|
|
1225
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
1226
|
+
*
|
|
1227
|
+
* var tuple = factory( [ 1.0, 0.0, -1.0 ] );
|
|
1228
|
+
*
|
|
1229
|
+
* var obj = tuple.toJSON();
|
|
1230
|
+
* // returns { 'x': 1.0, 'y': 0.0, 'z': -1.0 }
|
|
1231
|
+
*/
|
|
1232
|
+
toJSON(): any;
|
|
1233
|
+
|
|
1234
|
+
/**
|
|
1235
|
+
* Serializes a tuple as a locale-specific `string`.
|
|
1236
|
+
*
|
|
1237
|
+
* @param locales - a BCP 47 language tag, or an array of such tags
|
|
1238
|
+
* @param options - options
|
|
1239
|
+
* @returns a typed array string representation
|
|
1240
|
+
*
|
|
1241
|
+
* @example
|
|
1242
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
1243
|
+
*
|
|
1244
|
+
* var tuple = factory( [ 1.0, 0.0, -1.0 ], 'int32' );
|
|
1245
|
+
*
|
|
1246
|
+
* var str = tuple.toLocaleString();
|
|
1247
|
+
* // returns 'tuple(x=1, y=0, z=-1)'
|
|
1248
|
+
*/
|
|
1249
|
+
toLocaleString( locales: string | Array<string>, options?: any ): string;
|
|
1250
|
+
|
|
1251
|
+
/**
|
|
1252
|
+
* Serializes a tuple as a `string`.
|
|
1253
|
+
*
|
|
1254
|
+
* ## Notes
|
|
1255
|
+
*
|
|
1256
|
+
* - The returned `string` uses the tuple `name` as specified when creating a tuple factory.
|
|
1257
|
+
*
|
|
1258
|
+
* @returns a tuple string representation
|
|
1259
|
+
*
|
|
1260
|
+
* @example
|
|
1261
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ] );
|
|
1262
|
+
*
|
|
1263
|
+
* var tuple = factory( [ 1.0, 0.0, -1.0 ], 'int32' );
|
|
1264
|
+
*
|
|
1265
|
+
* var str = tuple.toString();
|
|
1266
|
+
* // returns 'tuple(x=1, y=0, z=-1)'
|
|
1267
|
+
*
|
|
1268
|
+
* @example
|
|
1269
|
+
* var opts = {
|
|
1270
|
+
* 'name': 'Point'
|
|
1271
|
+
* };
|
|
1272
|
+
*
|
|
1273
|
+
* var factory = namedtypedtuple( [ 'x', 'y', 'z' ], opts );
|
|
1274
|
+
*
|
|
1275
|
+
* var tuple = factory( [ 1.0, 0.0, -1.0 ], 'int32' );
|
|
1276
|
+
*
|
|
1277
|
+
* var str = tuple.toString();
|
|
1278
|
+
* // returns 'Point(x=1, y=0, z=-1)'
|
|
1279
|
+
*/
|
|
1280
|
+
toString(): string;
|
|
1281
|
+
|
|
1282
|
+
/**
|
|
1283
|
+
* Returns an iterator for iterating over tuple elements.
|
|
1284
|
+
*
|
|
1285
|
+
* @returns iterator for iterating over tuple elements
|
|
1286
|
+
*
|
|
1287
|
+
* @example
|
|
1288
|
+
* var factory = namedtypedtuple( [ 'x', 'y' ] );
|
|
1289
|
+
*
|
|
1290
|
+
* var tuple = factory( [ 1.0, -1.0 ] );
|
|
1291
|
+
*
|
|
1292
|
+
* // Create an iterator:
|
|
1293
|
+
* var it = tuple.values();
|
|
1294
|
+
*
|
|
1295
|
+
* // Iterate over tuple elements...
|
|
1296
|
+
* var v = it.next().value;
|
|
1297
|
+
* // returns 1.0
|
|
1298
|
+
*
|
|
1299
|
+
* v = it.next().value;
|
|
1300
|
+
* // returns -1.0
|
|
1301
|
+
*
|
|
1302
|
+
* var bool = it.next().done;
|
|
1303
|
+
* // returns true
|
|
1304
|
+
*/
|
|
1305
|
+
values(): Iterator;
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
/**
|
|
1309
|
+
* Interface defining a typed tuple factory.
|
|
1310
|
+
*/
|
|
1311
|
+
interface Factory {
|
|
1312
|
+
/**
|
|
1313
|
+
* Returns a named typed tuple of the specified data type.
|
|
1314
|
+
*
|
|
1315
|
+
* @param dtype - tuple data type (default data type if not supplied)
|
|
1316
|
+
* @returns named typed tuple
|
|
1317
|
+
*
|
|
1318
|
+
* @example
|
|
1319
|
+
* var factory = namedtypedtuple( [ 'x', 'y' ] );
|
|
1320
|
+
*
|
|
1321
|
+
* var tuple = factory( 'int32' );
|
|
1322
|
+
*
|
|
1323
|
+
* var x = tuple.x;
|
|
1324
|
+
* // returns 0
|
|
1325
|
+
*
|
|
1326
|
+
* x = tuple[ 0 ];
|
|
1327
|
+
* // returns 0
|
|
1328
|
+
*
|
|
1329
|
+
* var y = tuple.y;
|
|
1330
|
+
* // returns 0
|
|
1331
|
+
*
|
|
1332
|
+
* y = tuple[ 1 ];
|
|
1333
|
+
* // returns 0
|
|
1334
|
+
*
|
|
1335
|
+
* @example
|
|
1336
|
+
* var factory = namedtypedtuple( [ 'x', 'y' ] );
|
|
1337
|
+
*
|
|
1338
|
+
* var tuple = factory();
|
|
1339
|
+
*
|
|
1340
|
+
* var x = tuple.x;
|
|
1341
|
+
* // returns 0.0
|
|
1342
|
+
*
|
|
1343
|
+
* x = tuple[ 0 ];
|
|
1344
|
+
* // returns 0.0
|
|
1345
|
+
*
|
|
1346
|
+
* var y = tuple.y;
|
|
1347
|
+
* // returns 0.0
|
|
1348
|
+
*
|
|
1349
|
+
* y = tuple[ 1 ];
|
|
1350
|
+
* // returns 0.0
|
|
1351
|
+
*/
|
|
1352
|
+
( dtype?: DType ): Tuple;
|
|
1353
|
+
|
|
1354
|
+
/**
|
|
1355
|
+
* Creates a named typed tuple from a typed array, array-like object, or iterable.
|
|
1356
|
+
*
|
|
1357
|
+
* @param obj - typed array, array-like object, or iterable from which to generate a named typed tuple
|
|
1358
|
+
* @param dtype - tuple data type
|
|
1359
|
+
* @returns named typed tuple
|
|
1360
|
+
*
|
|
1361
|
+
* @example
|
|
1362
|
+
* var factory = namedtypedtuple( [ 'x', 'y' ] );
|
|
1363
|
+
*
|
|
1364
|
+
* var tuple = factory( [ 1.0, -1.0 ] );
|
|
1365
|
+
*
|
|
1366
|
+
* var x = tuple.x;
|
|
1367
|
+
* // returns 1.0
|
|
1368
|
+
*
|
|
1369
|
+
* x = tuple[ 0 ];
|
|
1370
|
+
* // returns 1.0
|
|
1371
|
+
*
|
|
1372
|
+
* var y = tuple.y;
|
|
1373
|
+
* // returns -1.0
|
|
1374
|
+
*
|
|
1375
|
+
* y = tuple[ 1 ];
|
|
1376
|
+
* // returns -1.0
|
|
1377
|
+
*
|
|
1378
|
+
* @example
|
|
1379
|
+
* var Float64Array = require( '@stdlib/array-float64' );
|
|
1380
|
+
*
|
|
1381
|
+
* var factory = namedtypedtuple( [ 'x', 'y' ] );
|
|
1382
|
+
*
|
|
1383
|
+
* var tuple = factory( new Float64Array( [ 1.0, -1.0 ] ) );
|
|
1384
|
+
*
|
|
1385
|
+
* var x = tuple.x;
|
|
1386
|
+
* // returns 1.0
|
|
1387
|
+
*
|
|
1388
|
+
* x = tuple[ 0 ];
|
|
1389
|
+
* // returns 1.0
|
|
1390
|
+
*
|
|
1391
|
+
* var y = tuple.y;
|
|
1392
|
+
* // returns -1.0
|
|
1393
|
+
*
|
|
1394
|
+
* y = tuple[ 1 ];
|
|
1395
|
+
* // returns -1.0
|
|
1396
|
+
*/
|
|
1397
|
+
( obj: TypedArray | ArrayLike<number> | Iterable<number>, dtype?: DType ): Tuple;
|
|
1398
|
+
|
|
1399
|
+
/**
|
|
1400
|
+
* Returns a named typed tuple view of an ArrayBuffer.
|
|
1401
|
+
*
|
|
1402
|
+
* @param buffer - underlying ArrayBuffer
|
|
1403
|
+
* @param byteOffset - integer byte offset specifying the location of the first tuple element (default: 0)
|
|
1404
|
+
* @param dtype - tuple data type
|
|
1405
|
+
* @returns named typed tuple
|
|
1406
|
+
*/
|
|
1407
|
+
( buffer: ArrayBuffer, byteOffset?: number, dtype?: DType ): Tuple;
|
|
1408
|
+
|
|
1409
|
+
/**
|
|
1410
|
+
* Creates a new named typed tuple from an array-like object or an iterable.
|
|
1411
|
+
*
|
|
1412
|
+
* @param src - source of tuple elements
|
|
1413
|
+
* @param map - callback to invoke for each source element
|
|
1414
|
+
* @param thisArg - callback execution context
|
|
1415
|
+
* @returns named typed tuple
|
|
1416
|
+
*
|
|
1417
|
+
* @example
|
|
1418
|
+
* var factory = namedtypedtuple( [ 'x', 'y' ] );
|
|
1419
|
+
*
|
|
1420
|
+
* var tuple = factory.from( [ 1.0, -1.0 ] );
|
|
1421
|
+
*
|
|
1422
|
+
* var x = tuple.x;
|
|
1423
|
+
* // returns 1.0
|
|
1424
|
+
*
|
|
1425
|
+
* x = tuple[ 0 ];
|
|
1426
|
+
* // returns 1.0
|
|
1427
|
+
*
|
|
1428
|
+
* var y = tuple.y;
|
|
1429
|
+
* // returns -1.0
|
|
1430
|
+
*
|
|
1431
|
+
* y = tuple[ 1 ];
|
|
1432
|
+
* // returns -1.0
|
|
1433
|
+
*/
|
|
1434
|
+
from( src: ArrayLike<number> | Iterable<number>, map?: FactoryCallback, thisArg?: any ): Tuple;
|
|
1435
|
+
|
|
1436
|
+
/**
|
|
1437
|
+
* Creates a new named typed tuple from an object containing tuple fields.
|
|
1438
|
+
*
|
|
1439
|
+
* @param obj - source object
|
|
1440
|
+
* @param map - callback to invoke for each source object tuple field
|
|
1441
|
+
* @param thisArg - callback execution context
|
|
1442
|
+
* @returns named typed tuple
|
|
1443
|
+
*
|
|
1444
|
+
* @example
|
|
1445
|
+
* var factory = namedtypedtuple( [ 'x', 'y' ] );
|
|
1446
|
+
*
|
|
1447
|
+
* var obj = {
|
|
1448
|
+
* 'x': 1.0,
|
|
1449
|
+
* 'y': -1.0
|
|
1450
|
+
* };
|
|
1451
|
+
*
|
|
1452
|
+
* var tuple = factory.fromObject( obj );
|
|
1453
|
+
*
|
|
1454
|
+
* var x = tuple.x;
|
|
1455
|
+
* // returns 1.0
|
|
1456
|
+
*
|
|
1457
|
+
* x = tuple[ 0 ];
|
|
1458
|
+
* // returns 1.0
|
|
1459
|
+
*
|
|
1460
|
+
* var y = tuple.y;
|
|
1461
|
+
* // returns -1.0
|
|
1462
|
+
*
|
|
1463
|
+
* y = tuple[ 1 ];
|
|
1464
|
+
* // returns -1.0
|
|
1465
|
+
*/
|
|
1466
|
+
fromObject( obj: any, map?: FactoryObjectCallback, thisArg?: any ): Tuple;
|
|
1467
|
+
|
|
1468
|
+
/**
|
|
1469
|
+
* Creates a new named typed tuple from a variable number of arguments.
|
|
1470
|
+
*
|
|
1471
|
+
* @param elements - tuple elements
|
|
1472
|
+
* @returns named typed tuple
|
|
1473
|
+
*
|
|
1474
|
+
* @example
|
|
1475
|
+
* var factory = namedtypedtuple( [ 'x', 'y' ] );
|
|
1476
|
+
*
|
|
1477
|
+
* var tuple = factory.of( 1.0, -1.0 );
|
|
1478
|
+
*
|
|
1479
|
+
* var x = tuple.x;
|
|
1480
|
+
* // returns 1.0
|
|
1481
|
+
*
|
|
1482
|
+
* x = tuple[ 0 ];
|
|
1483
|
+
* // returns 1.0
|
|
1484
|
+
*
|
|
1485
|
+
* var y = tuple.y;
|
|
1486
|
+
* // returns -1.0
|
|
1487
|
+
*
|
|
1488
|
+
* y = tuple[ 1 ];
|
|
1489
|
+
* // returns -1.0
|
|
1490
|
+
*/
|
|
1491
|
+
of( ...elements: Array<number> ): Tuple;
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
/**
|
|
1495
|
+
* Returns a named typed tuple factory.
|
|
1496
|
+
*
|
|
1497
|
+
* @param names - field (property) names
|
|
1498
|
+
* @param options - options
|
|
1499
|
+
* @param options.dtype - default data type (default: 'float64')
|
|
1500
|
+
* @param options.name - tuple name (default: 'tuple')
|
|
1501
|
+
* @throws must provide distinct field names
|
|
1502
|
+
* @throws cannot provide a reserved field (property) name
|
|
1503
|
+
* @throws must provide valid options
|
|
1504
|
+
* @throws must provide a recognized data type
|
|
1505
|
+
* @returns factory function
|
|
1506
|
+
*
|
|
1507
|
+
* @example
|
|
1508
|
+
* var point = namedtypedtuple( [ 'x', 'y' ] );
|
|
1509
|
+
*
|
|
1510
|
+
* var p = point( [ 1.0, -1.0 ] );
|
|
1511
|
+
*
|
|
1512
|
+
* var x = p[ 0 ];
|
|
1513
|
+
* // returns 1.0
|
|
1514
|
+
*
|
|
1515
|
+
* x = p.x;
|
|
1516
|
+
* // returns 1.0
|
|
1517
|
+
*
|
|
1518
|
+
* var y = p[ 1 ];
|
|
1519
|
+
* // returns -1.0
|
|
1520
|
+
*
|
|
1521
|
+
* y = p.y;
|
|
1522
|
+
* // returns -1.0
|
|
1523
|
+
*/
|
|
1524
|
+
declare function namedtypedtuple( names: Array<string>, options?: Options ): Factory;
|
|
1525
|
+
|
|
1526
|
+
|
|
1527
|
+
// EXPORTS //
|
|
1528
|
+
|
|
1529
|
+
export = namedtypedtuple;
|