Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 67 additions & 57 deletions lib/node_modules/@stdlib/array/base/zip2views/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,71 @@ var accessors = require( '@stdlib/array/base/accessors' );
var copy = require( '@stdlib/array/base/copy' );


// FUNCTIONS //

/**
* Returns an accessor for returning the value associated with a label.
*
* @private
* @param {Collection} arr - input array
* @param {Function} getter - array element accessor
* @returns {Function} accessor
*/
function getValue( arr, getter ) {
return get;

/**
* Returns the value associated with a label.
*
* @private
* @returns {*} result
*/
function get() {
return getter( arr, this._i ); // eslint-disable-line no-invalid-this
}
}

/**
* Returns an accessor for setting the value associated with a label.
*
* @private
* @param {Collection} arr - input array
* @param {Function} setter - array element accessor
* @returns {Function} accessor
*/
function setValue( arr, setter ) {
return set;

/**
* Sets the value associated with a label.
*
* @private
* @param {*} value - value to set
*/
function set( value ) {
setter( arr, this._i, value ); // eslint-disable-line no-invalid-this
}
}

// eslint-disable-next-line stdlib/jsdoc-typedef-typos
/**
* Constructor for creating a composite view of zipped elements.
*
* ## Notes
*
* - The constructor's prototype is reset at the start of each `zip2views` invocation (see below) so that views created by one invocation never inherit label accessors defined by a different invocation.
*
* @private
* @constructor
* @param {NonNegativeInteger} i - element index
* @returns {Datum} datum instance
*/
function Datum( i ) {
setNonEnumerableReadOnly( this, '_i', i );
return this;
}


// MAIN //

/**
Expand Down Expand Up @@ -102,19 +167,8 @@ function zip2views( arrays, labels ) {
// Create a copy of provided labels to prevent external mutation:
keys = copy( labels );

// eslint-disable-next-line stdlib/jsdoc-typedef-typos
/**
* Constructor for creating a composite view of zipped elements.
*
* @private
* @constructor
* @param {NonNegativeInteger} i - element index
* @returns {Datum} datum instance
*/
function Datum( i ) {
setNonEnumerableReadOnly( this, '_i', i );
return this;
}
// Reset the shared constructor's prototype so that this invocation's views only ever expose this invocation's labels:
Datum.prototype = {};

// Define read/write accessors for each label...
for ( i = 0; i < M; i++ ) {
Expand All @@ -132,50 +186,6 @@ function zip2views( arrays, labels ) {
}
return out;

/**
* Returns an accessor for returning the value associated with a label.
*
* @private
* @param {Collection} arr - input array
* @param {Function} getter - array element accessor
* @returns {Function} accessor
*/
function getValue( arr, getter ) {
return get;

/**
* Returns the value associated with a label.
*
* @private
* @returns {*} result
*/
function get() {
return getter( arr, this._i ); // eslint-disable-line no-invalid-this
}
}

/**
* Returns an accessor for setting the value associated with a label.
*
* @private
* @param {Collection} arr - input array
* @param {Function} setter - array element accessor
* @returns {Function} accessor
*/
function setValue( arr, setter ) {
return set;

/**
* Sets the value associated with a label.
*
* @private
* @param {*} value - value to set
*/
function set( value ) {
setter( arr, this._i, value ); // eslint-disable-line no-invalid-this
}
}

/**
* Serializes a datum to JSON.
*
Expand Down