LInQer – C# Integrated Queries ported to Javascript

栏目: IT技术 · 发布时间: 4年前

内容简介:The C# Language Integrated Queries ported for Javascript for amazing performanceArray 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 operation

LInQer v1.0.0

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

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.

More details on the blog post for it: https://siderite.dev/blog/linq-in-javascript-linqer/ . Leave comments there or add Issues here in order to get features or bug fixes or whatever.

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

Usage

Reference Linqer.slim.js for the basic methods:

  • the static from, empty, range, repeat
  • concat
  • count
  • distinct
  • elementAt and elementAtOrDefault
  • first and firstOrDefault
  • last and lastOrDefault
  • min, max, stats (min, max and count)
  • select
  • skip and take
  • sum and sumAndCount (sum and count)
  • toArray
  • toList - similar to toArray, but returns an Enumerable (itself if already seekable)
  • where

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

  • aggregate
  • all
  • any
  • append
  • average
  • asEnumerable
  • cast
  • contains
  • defaultIfEmpty - throws not implemented
  • except
  • intersect
  • longCount
  • ofType
  • prepend
  • reverse
  • selectMany
  • sequenceEqual
  • single
  • singleOrDefault
  • skipLast
  • skipWhile
  • takeLast
  • takeWhile
  • toDictionary - throws not implemented
  • toMap
  • toObject
  • toHashSet - throws not implemented
  • toSet
  • toList - throws not implemented
  • 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
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)
                .selectMany()
                .skip(15)
                .take(5)
                .toArray();

Original Enumerable

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

Building the solution

The source files have been moved to Typescript. Run build.bat to create the js and map files.


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

蚂蚁金服

蚂蚁金服

由曦 / 中信出版集团股份有限公司 / 2017-4-7 / CNY 59.00

在中国,支付宝(其母公司为蚂蚁金服)是一个家喻户晓的品牌。我们在用手机扫码支付,或者用余额宝理财的时候,一定会和支付宝发生关系。但是很多人不知道,支付宝的母公司叫作“蚂蚁金服”。蚂蚁金服不仅有支付宝,还有余额宝、网商银行、芝麻信用等一系列产品和服务。成立于2004年、起始于支付宝的蚂蚁金服集团,如今已经是全球估值最高的科技金融企业。然而,在成立之初,它只是淘宝网的结算部门,员工只有区区几人,记账用......一起来看看 《蚂蚁金服》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试