@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.
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2018 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
+ 'use strict';
20
+
21
+ // MAIN //
22
+
23
+ /**
24
+ * Specifies a sort order for ordering numeric values in ascending order.
25
+ *
26
+ * ## Notes
27
+ *
28
+ * - If `a < b`, then function returns a number less than `0`, which specifies to sort `a` to an index lower than `b`.
29
+ * - If `a > b`, then function returns a number greater than `0`, which specifies to sort `a` to an index higher than `b`.
30
+ * - If `a == b`, then function returns `0`, which specifies that the order of `a` and `b` should remain unchanged (not guaranteed).
31
+ *
32
+ * @private
33
+ * @param {number} a - first value
34
+ * @param {number} b - second value
35
+ * @returns {number} difference between `a` and `b`
36
+ */
37
+ function ascending( a, b ) {
38
+ return a - b;
39
+ }
40
+
41
+
42
+ // EXPORTS //
43
+
44
+ module.exports = ascending;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2018 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
+ 'use strict';
20
+
21
+ // MAIN //
22
+
23
+ /**
24
+ * Returns a boolean indicating if an array contains a provided value.
25
+ *
26
+ * @private
27
+ * @param {Array} arr - array
28
+ * @param {*} v - search value
29
+ * @returns {boolean} boolean indicating if an array contains a search value
30
+ */
31
+ function contains( arr, v ) {
32
+ var i;
33
+ for ( i = 0; i < arr.length; i++ ) {
34
+ if ( arr[ i ] === v ) {
35
+ return true;
36
+ }
37
+ }
38
+ return false;
39
+ }
40
+
41
+
42
+ // EXPORTS //
43
+
44
+ module.exports = contains;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2018 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
+ 'use strict';
20
+
21
+ // MAIN //
22
+
23
+ /**
24
+ * Returns an array of iterated values.
25
+ *
26
+ * @private
27
+ * @param {Object} it - iterator
28
+ * @returns {Array} output array
29
+ */
30
+ function fromIterator( it ) {
31
+ var out;
32
+ var v;
33
+
34
+ out = [];
35
+ while ( true ) {
36
+ v = it.next();
37
+ if ( v.done ) {
38
+ break;
39
+ }
40
+ out.push( v.value );
41
+ }
42
+ return out;
43
+ }
44
+
45
+
46
+ // EXPORTS //
47
+
48
+ module.exports = fromIterator;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2018 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
+ 'use strict';
20
+
21
+ // MAIN //
22
+
23
+ /**
24
+ * Returns an array of iterated values.
25
+ *
26
+ * @private
27
+ * @param {StringArray} fields - tuple fields
28
+ * @param {Object} it - iterator
29
+ * @param {Function} clbk - callback to invoke for each iterated value
30
+ * @param {*} thisArg - invocation context
31
+ * @returns {Array} output array
32
+ */
33
+ function fromIteratorMap( fields, it, clbk, thisArg ) {
34
+ var out;
35
+ var v;
36
+ var i;
37
+
38
+ out = [];
39
+ i = -1;
40
+ while ( true ) {
41
+ v = it.next();
42
+ if ( v.done ) {
43
+ break;
44
+ }
45
+ i += 1;
46
+ out.push( clbk.call( thisArg, v.value, i, fields[ i ] ) );
47
+ }
48
+ return out;
49
+ }
50
+
51
+
52
+ // EXPORTS //
53
+
54
+ module.exports = fromIteratorMap;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2018 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
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var hasOwnProp = require( '@stdlib/assert-has-own-property' );
24
+
25
+
26
+ // MAIN //
27
+
28
+ /**
29
+ * Tests if an array contains distinct elements.
30
+ *
31
+ * @private
32
+ * @param {Array} arr - input array
33
+ * @returns {boolean} boolean indicating if an array contains distinct elements
34
+ */
35
+ function hasDistinctElements( arr ) {
36
+ var obj;
37
+ var i;
38
+
39
+ obj = {};
40
+ for ( i = 0; i < arr.length; i++ ) {
41
+ if ( hasOwnProp( obj, arr[ i ] ) ) {
42
+ return false;
43
+ }
44
+ obj[ arr[i] ] = true;
45
+ }
46
+ return true;
47
+ }
48
+
49
+
50
+ // EXPORTS //
51
+
52
+ module.exports = hasDistinctElements;
package/lib/index.js ADDED
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2018 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
+ 'use strict';
20
+
21
+ /**
22
+ * Named typed tuple.
23
+ *
24
+ * @module @stdlib/dstructs-named-typed-tuple
25
+ *
26
+ * @example
27
+ * var namedtypedtuple = require( '@stdlib/dstructs-named-typed-tuple' );
28
+ *
29
+ * var point = namedtypedtuple( [ 'x', 'y' ] );
30
+ *
31
+ * var p = point( [ 1.0, -1.0 ] );
32
+ *
33
+ * var x = p[ 0 ];
34
+ * // returns 1.0
35
+ *
36
+ * x = p.x;
37
+ * // returns 1.0
38
+ *
39
+ * var y = p[ 1 ];
40
+ * // returns -1.0
41
+ *
42
+ * y = p.y;
43
+ * // returns -1.0
44
+ */
45
+
46
+ // MAIN //
47
+
48
+ var main = require( './main.js' );
49
+
50
+
51
+ // EXPORTS //
52
+
53
+ module.exports = main;