How to use linq - 10 common examples

To help you get started, we’ve selected a few linq examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github data-forge / data-forge-js / package-test / npm / index.js View on Github external
'use strict';

var dataForge = require('data-forge');
var E = require('linq');

// 
// Create a simple data frame.
//
var values = E
	.range(0, 14)
	.select(function (i) {
		return [i, Math.sin(i), Math.cos(i)];
	})
	.toArray();

var dataFrame = new dataForge.DataFrame({
		columnNames: ["index", "Sin", "Cos"], 
		rows: values
	})
	.setIndex("index")
	.dropSeries("index");

console.log(dataFrame.skip(4).take(5).toString());

var series = dataFrame.getSeries("Sin");
github data-forge / data-forge-js / examples / 1. display data frame - console / index.js View on Github external
'use strict';

var dataForge = require('../../index.js');
var E = require('linq');

// 
// Create a simple data frame.
//
var values = E
	.range(0, 14)
	.select(function (i) {
		return [i, Math.sin(i), Math.cos(i)];
	})
	.toArray();

var dataFrame = new dataForge.DataFrame({
		columnNames: ["index", "Sin", "Cos"], 
		rows: values 
	})
	.setIndex("index")
	.dropSeries("index");

console.log(dataFrame.skip(4).take(5).toString());

var series = dataFrame.getSeries("Sin");
github data-forge / data-forge-js / src / basedataframe.js View on Github external
return new ArrayIterator(
						E.from(self.toValues())
							.select(function (row, rowIndex) {
								return row.concat([data[rowIndex]]);
							})
							.toArray()
					);
				},
			},
			index: self.getIndex(),
		});
	}
	else {
		// Replace existing column.
		return new DataFrame({
			columnNames: E.from(self.getColumnNames())
				.select(function (thisColumnName, thisColumnIndex) {
					if (thisColumnIndex === columnIndex) {
						return columnName;
					}
					else { 
						return thisColumnName;
					}
				})
				.toArray(),
			rows: {
				getIterator: function () {
					return new ArrayIterator(
						E.from(self.toValues())
							.select(function (row, rowIndex) {
								return E.from(row)
									.select(function (column, thisColumnIndex) {
github data-forge / data-forge-js / src / series.js View on Github external
return value;
		};
	}

	var self = this;

	//todo: make this lazy.

	/* todo: Want to zip here, when zip can specify the index. 

	series.zip(series.skip(1), function (prev, next) { 
		});

	*/

	var input = E.from(self.toPairs())
		.select(function (pair) {
			return {
				pair: pair,
				considered: false,
			};
		})
		.toArray();

	var output = [];

	for (var i = 0; i < input.length; ++i) {
		var underConsideration = input[i];
		if (underConsideration.considered) {
			// Skip this item, it has already been dealt with.
			continue;
		}
github sky-uk / api-explorer / packages / apiexplorer / src / infrastructure / loaders / swagger1Loader.js View on Github external
.then(apiSpec => {
      let newApiSpec = executeInterceptor(config, apiSpec)
      let defaultHost = new URI(config.url.url).host()

      onLoadProgress(`Loading content from '${url}' completed`)
      const apis = Enumerable
        .from(newApiSpec.apis)
        .select(api => {
          return { path: api.path, url: config.url.resolveChildUrl(`${apiSpec.basePath}${api.path}`), onLoadProgress: onLoadProgress, config }
        })
        .toArray()

      async.map(apis, executeFetch, (err, result) => {
        if (err) {
          onLoadError(`Error loading Swagger 1.x apis: ${err}`)
          console.error(err)
        } else {
          onLoadProgress(`Loading of Swagger spec 1.x completed.`)

          let apiDeclarations = {}
          result.forEach(element => { apiDeclarations[element.path] = element.result })
github sky-uk / api-explorer / packages / apiexplorer / src / components / LateralMenuLegacy.js View on Github external
renderAPI (apiOperations) {
    if (apiOperations.length === 0 || !this.isApiVisible(apiOperations[0].apiname, apiOperations)) return

    const tags = Enumerable.from(apiOperations).selectMany(o => o.spec.tags).distinct().toArray()
    return (
      <li>
        <a href="#">
          <i>
          <span>
          <strong>{apiOperations[0].apiname}</strong><span>
        </span></span></i></a><i>
        <ul>
          {tags.map(tag =&gt; this.renderOperationsWithTag(apiOperations, tag))}
        </ul>
      </i></li><i>
    )
  }
</i>
github data-forge / data-forge-js / src / dataframe.js View on Github external
getColumnNames: function () {
				return E.from(self.iterable.getColumnNames())
					.concat([columnName])
					.distinct()
					.toArray();
			},
		},
github data-forge / data-forge-js / src / basedataframe.js View on Github external
BaseDataFrame.prototype.setSeries = function (columnName, data) { //todo: should allow column name or index.
	assert.isString(columnName, "Expected 'columnName' parameter to 'setSeries' to be a string.");

	var self = this;

	if (Object.isFunction(data)) {
		data = E.from(self.toObjects())
			.select(data)
			.toArray();
	}
	else if (!Object.isArray(data)) {
		assert.isObject(data, "Expected 'data' parameter to 'setSeries' to be either an array or a series object.");
		assert.isFunction(data.reindex, "Expected 'data' parameter to 'setSeries' to have a 'reindex' function that allows the column to be reindexed.");

		data = data.reindex(self.getIndex()).toValues();
	}

	//todo: overview and improve the way this works.

	var DataFrame = require('./dataframe');

	var columnIndex = self.getColumnIndex(columnName);
	if (columnIndex &lt; 0) {
github data-forge / data-forge-js / src / merge-dataframes.js View on Github external
var leftPairs = leftDataFrame.toPairs();
		var rightPairs = rightDataFrame.toPairs();

		var mergedColumnNames = [columnName]
			.concat(dropElement(leftDataFrame.getColumnNames(), leftColumnIndex))
			.concat(dropElement(rightDataFrame.getColumnNames(), rightColumnIndex));

		var leftColumns = leftDataFrame.getColumnNames();
		var rightColumns = rightDataFrame.getColumnNames();

		var leftIndices = E.from(leftPairs)
			.select(function (leftPair) {
				return leftPair[1][leftColumns[leftColumnIndex]];
			})
			.toArray();
		var rightIndices = E.from(rightPairs)
			.select(function (rightPair) {
				return rightPair[1][rightColumns[rightColumnIndex]];
			})
			.toArray();

		var distinctIndices = E.from(leftIndices.concat(rightIndices)).distinct().toArray();

		var leftMap = E.from(leftPairs)
			.groupBy(function (leftPair) {
				return leftPair[1][leftColumns[leftColumnIndex]];
			})
			.toObject(
				function (group) {
					return group.key();
				},
				function (group) {
github data-forge / data-forge-js / src / dataframe.js View on Github external
function (row) {
			return E.from(columnNames)
				.select(function (columnName, columnIndex) {
					return [columnName, columnIndex];
				})
				.toObject(
					function (column) {
						return column[0];
					},
					function (column) {
						return row[column[1]];
					}
				);							
		}
	);

linq

linq.js - LINQ for JavaScript

MIT
Latest version published 7 months ago

Package Health Score

64 / 100
Full package analysis

Popular linq functions