Giter Site home page Giter Site logo

linq-in-javascript's Introduction

LINQ in JavaScript

I write a lot of C# and it has a really useful way to query large collections of data, called LINQ.

Although JavaScript arrays have querying capabilities through map, reduce, filter but the limitation is they process the entire array before going to the next step, meaning if you do a map then a filter the whole collection goes through map process before it starts filtering. This can be a problem with large data sets, it can take a while.

Why LINQ?

The advantage of LINQ is that it uses lazy execusion, each item goes through the whole pipeline before the next item is processed. So if you have a large data set you can easily process subsets of the data and break early.

How does it work?

To do this it leverages the ES6 Iterators to yield each value.

Example

var items = [1, 2, 3, 4, 5, 6].asEnumerable();

for (let item in items.where(x => x % 2).select(x => x + 1))
    console.log(item);

//output will be 2, 4, 6

API

The following LINQ methods are implemented:

  • aggregate
  • all
  • any
  • asEnumerable
  • average
  • concat
  • contains
  • count
  • first, firstOrDefault
  • range
  • repeat
  • select, aliased to map
  • selectMany
  • single, singleOrDefault
  • toArray
  • where, aliased to filter

The full list of what LINQ in .NET does can be found here.

License

MIT

linq-in-javascript's People

Contributors

aaronpowell avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.