Skip to content
The C# Language Integrated Queries ported for Javascript for amazing performance
JavaScript TypeScript CSS Other
Branch: master
Clone or download
Latest commit eccfeab Feb 17, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode Added minifier as an extension, changed name of minified file Jan 11, 2020
qUnit Initial commit Jan 4, 2020
.gitignore - added Linqer.all.js for node.js use and used it as the main entry … Feb 2, 2020
LICENSE Initial commit Jan 4, 2020
LInQer.Enumerable.ts - added comments to the code to better explain the mechanism - bugfi… Feb 17, 2020
LInQer.GroupEnumerable.ts - added comments to the code to better explain the mechanism - bugfi… Feb 17, 2020
LInQer.OrderedEnumerable.ts - added comments to the code to better explain the mechanism - bugfi… Feb 17, 2020
LInQer.Slim.ts - added comments to the code to better explain the mechanism - bugfi… Feb 17, 2020
LInQer.all.d.ts - added comments to the code to better explain the mechanism - bugfi… Feb 17, 2020
LInQer.all.js - added comments to the code to better explain the mechanism - bugfi… Feb 17, 2020
LInQer.all.js.map - added comments to the code to better explain the mechanism - bugfi… Feb 17, 2020
LInQer.extra.js - added comments to the code to better explain the mechanism - bugfi… Feb 17, 2020
LInQer.extra.js.map - added comments to the code to better explain the mechanism - bugfi… Feb 17, 2020
LInQer.extra.min.js - bugfix: lead had the wrong indexing function for elementAt - bugfi… Feb 16, 2020
LInQer.extra.ts - added comments to the code to better explain the mechanism - bugfi… Feb 17, 2020
LInQer.js - added comments to the code to better explain the mechanism - bugfi… Feb 17, 2020
LInQer.js.map - added comments to the code to better explain the mechanism - bugfi… Feb 17, 2020
LInQer.min.js - added comments to the code to better explain the mechanism - bugfi… Feb 17, 2020
LInQer.slim.js - added comments to the code to better explain the mechanism - bugfi… Feb 17, 2020
LInQer.slim.js.map - added comments to the code to better explain the mechanism - bugfi… Feb 17, 2020
LInQer.slim.min.js - bugfix: lead had the wrong indexing function for elementAt - bugfi… Feb 16, 2020
README.md - bugfix: lead had the wrong indexing function for elementAt - bugfi… Feb 16, 2020
Release.txt - added comments to the code to better explain the mechanism - bugfi… Feb 17, 2020
build.bat - added Linqer.all.js for node.js use and used it as the main entry … Feb 2, 2020
npm.export.ts Exporting Linqer namespace directly Feb 2, 2020
package-lock.json - added comments to the code to better explain the mechanism - bugfi… Feb 17, 2020
package.json - added comments to the code to better explain the mechanism - bugfi… Feb 17, 2020
tests.html - change of algorithm for sorting - useQuickSort and useBrowserSort … Feb 6, 2020
tests.js added length, slice, splice and everything nice Feb 14, 2020
tests.performance.html - separated the performance tests in their own files - small perform… Feb 9, 2020
tests.performance.js - separated the performance tests in their own files - small perform… Feb 9, 2020
tests.slim.html - separated the performance tests in their own files - small perform… Feb 9, 2020
tests.slim.js - separated the performance tests in their own files - small perform… Feb 9, 2020
tsconfig.all.json Added typings for Intellisense in TypeScript Feb 9, 2020
tsconfig.extra.json Added extra functions, fixed build errors Jan 27, 2020
tsconfig.json - added Linqer.all.js for node.js use and used it as the main entry … Feb 2, 2020
tsconfig.slim.json Added extra functions, fixed build errors Jan 27, 2020

README.md

LInQer

The C# Language Integrated Queries ported for Javascript for amazing performance

npm version License: MIT

Installation

$ npm install @siderite/linqer

Quick start

const source = ... an array or a generator function or anything that is iterable... ;
const enumerable = Linqer.Enumerable.from(source); // now you can both iterate and use LINQ like functions
const result = enumerable
                .where(item=>!!item.value) // like filter
                .select(item=>{ value: item.value, key: item.name }) // like map
                .groupBy(item=>item.key)
                .where(g=>g.length>10)
                .orderBy(g=>g.key)
                .selectMany()
                .skip(15)
                .take(5);
for (const item of result) ...

in Node.js you have to prepend:

const Linqer = require('@siderite/linqer');

Licence

MIT

Array functions in Javascript create a new array for each operation, which is terribly wasteful. Using iterators and generator functions and objects, we can limit the operations to the items in the array that interest us, not all of them.

Blog post

https://siderite.dev/blog/linq-in-javascript-linqer. Leave comments there or add Issues on GitHub for feedback and support.

Hosted

Find it hosted on GitHub Pages and use it freely in your projects at:

Reference

Reference Linqer.slim.js for the basic methods:

  • from, empty, range, repeat - static on Linqer.Enumerable
  • length property - same as count, but throws error if the enumerable needs to be enumerated to get the length (no side effects)
  • concat
  • count
  • distinct
  • elementAt and elementAtOrDefault
  • first and firstOrDefault
  • last and lastOrDefault
  • min, max, stats (min, max and count)
  • select
  • skip and take
  • splice function - kind of useless, but it was an experiment to see if I can make Enumerable appear as an Array-like object
  • sum and sumAndCount (sum and count)
  • toArray
  • toList - similar to toArray, but returns a seekable Enumerable (itself if already seekable) that can do count and elementAt without iterating
  • where

Reference Linqer.js for all of the original Enumerable methods, the ones in slim and then the following:

  • aggregate
  • all
  • any
  • append
  • average
  • asEnumerable
  • cast
  • contains
  • defaultIfEmpty - throws not implemented
  • except
  • intersect
  • join
  • groupBy
  • groupJoin
  • longCount
  • ofType
  • orderBy
  • orderByDescending
  • prepend
  • reverse
  • selectMany
  • sequenceEqual
  • single
  • singleOrDefault
  • skip - on an ordered enumerable
  • skipLast - on a regular or ordered enumerable
  • skipWhile
  • slice
  • take - on an ordered enumerable
  • takeLast - on a regular or ordered enumerable
  • takeWhile
  • thenBy - on an ordered enumerable
  • thenByDescending - on an ordered enumerable
  • toDictionary - throws not implemented
  • toLookup - throws not implemented
  • toMap
  • toObject
  • toHashSet - throws not implemented
  • toSet
  • union
  • zip

Reference Linqer.extra.js (needs Linqer.js) for some additional methods:

  • shuffle - randomizes the enumerable
  • randomSample - implements random reservoir sampling of k items
  • distinctByHash - distinct based on a hashing function, not a comparer - faster
  • exceptByHash - except based on a hashing function, not a comparer - faster
  • intersectByHash - intersect based on a hashing function, not a comparer - faster
  • binarySearch - find the index of a value in a sorted enumerable by binary search
  • lag - joins each item of the enumerable with previous items from the same enumerable
  • lead - joins each item of the enumerable with next items from the same enumerable
  • padStart - pad enumerable at the start to a minimum length
  • padEnd - pad enumerable at the end to a minimum length

Original Enumerable .NET class

The original C# class can be found here: https://docs.microsoft.com/en-us/dotnet/api/system.linq.enumerable .

Building the solution

The library has been ported to Typescript. Run build.bat to create the .js and .map files from the .ts code.

You can’t perform that action at this time.