All Projects → tsdotnet → linq

tsdotnet / linq

Licence: MIT license
A familiar set of functions that operate on JavaScript iterables (ES2015+) in a similar way to .NET's LINQ does with enumerables.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to linq

stream
Go Stream, like Java 8 Stream.
Stars: ✭ 60 (+53.85%)
Mutual labels:  map, filter, reduce
go-streams
Stream Collections for Go. Inspired in Java 8 Streams and .NET Linq
Stars: ✭ 127 (+225.64%)
Mutual labels:  linq, filter, iterables
Performance Analysis Js
Map/Reduce/Filter/Find Vs For loop Vs For each Vs Lodash vs Ramda
Stars: ✭ 532 (+1264.1%)
Mutual labels:  map, filter
Pgo
Go library for PHP community with convenient functions
Stars: ✭ 51 (+30.77%)
Mutual labels:  map, filter
Fungen
Replace boilerplate code with functional patterns using 'go generate'
Stars: ✭ 122 (+212.82%)
Mutual labels:  map, filter
Itiriri Async
A library for asynchronous iteration.
Stars: ✭ 78 (+100%)
Mutual labels:  map, filter
Gods
GoDS (Go Data Structures). Containers (Sets, Lists, Stacks, Maps, Trees), Sets (HashSet, TreeSet, LinkedHashSet), Lists (ArrayList, SinglyLinkedList, DoublyLinkedList), Stacks (LinkedListStack, ArrayStack), Maps (HashMap, TreeMap, HashBidiMap, TreeBidiMap, LinkedHashMap), Trees (RedBlackTree, AVLTree, BTree, BinaryHeap), Comparators, Iterators, …
Stars: ✭ 10,883 (+27805.13%)
Mutual labels:  map, enumerable
Ngx Mat Select Search
Angular component providing an input field for searching / filtering MatSelect options of the Angular Material library.
Stars: ✭ 416 (+966.67%)
Mutual labels:  select, filter
Torchdata
PyTorch dataset extended with map, cache etc. (tensorflow.data like)
Stars: ✭ 226 (+479.49%)
Mutual labels:  map, filter
linqjs
use linq and lambda in javascript on es6, can use linq function in an Object or an Array or a String value | 一个方便对数组、字典、树形数据进行操作、筛选等操作的工具库
Stars: ✭ 17 (-56.41%)
Mutual labels:  linq, enumerable
Elements-of-Functional-Programming-in-Python
Learn how to how to use the lambda, map, filter and reduce functions in Python to transform data structures.
Stars: ✭ 14 (-64.1%)
Mutual labels:  filter, reduce
leaflet-tag-filter-button
Adds tag filter control for layers (marker, geojson features etc.) to LeafLet.
Stars: ✭ 48 (+23.08%)
Mutual labels:  map, filter
Itiriri
A library built for ES6 iteration protocol.
Stars: ✭ 155 (+297.44%)
Mutual labels:  map, filter
data-point
JavaScript Utility for collecting, processing and transforming data
Stars: ✭ 67 (+71.79%)
Mutual labels:  aggregate, reduce
morphmorph
😱 Isomorphic transformations. Map, transform, filter, and morph your objects
Stars: ✭ 26 (-33.33%)
Mutual labels:  filter, reduce
svelte-typeahead
Accessible, fuzzy search typeahead component
Stars: ✭ 141 (+261.54%)
Mutual labels:  filter
farmOS-map
farmOS Map is an OpenLayers wrapper library designed for agricultural mapping needs. It can be used in any project that has similar requirements.
Stars: ✭ 18 (-53.85%)
Mutual labels:  map
city-of-doors
The Map of Sigil, City of Doors
Stars: ✭ 40 (+2.56%)
Mutual labels:  map
ExtApp
ExtApp是一个基于三层架构,使用NHibernate、API Controller和ExtJs创建的,用于简化政府和企业应用开发的Web应用程序框架。
Stars: ✭ 14 (-64.1%)
Mutual labels:  map
FFmpeg-CRT-transform
CRT simulation without shaders... the slow way
Stars: ✭ 142 (+264.1%)
Mutual labels:  filter

alt text tsdotnet / linq

GitHub license 100% code coverage npm-publish npm version

A familiar set of functions that operate on JavaScript iterables (ES2015+) in a similar way to .NET's LINQ does with enumerables.

Docs

tsdotnet.github.io/linq

Source

GitHub

API

linq<T> vs linqExtended<T>

It is possible to do everything with just linq but linqExtended offers more functionality for those expecting to use common resolutions like .count, .first, .last, etc. Using linq will save you some bytes when your common use cases do not need resolutions.

Iterating

for(const e of linq(source).filter(a)) {
    // Iterate filtered results.
}
for(const e of linq(source)
    .filterWith(a, b, c)
    .transform(x)) {
    // Iterate filtered and then transformed results.
}
for(const e of linq(source)
    .where(predicate)
    .skip(10).take(10)
    .select(mapping)) {
    // Iterate filtered and mapped results.
}

Resolving

const result = linq(source)
    .filterWith(a, b, c)
    .transform(x)
    .resolve(r);
const firstElement = linqExtended(source)
    .where(predicate)
    .select(mapping)
    .first();

Examples

linq<T> with imported filters

import linq from '@tsdotnet/linq/dist/linq';
import range from '@tsdotnet/linq/dist/iterables/range';
import where from '@tsdotnet/linq/dist/filters/where';
import descending from '@tsdotnet/linq/dist/filters/descending';

const source = range(1,100); // Iterable<number>
const filtered = linq(source).filters(
     where(n => n%2===1),
     descending);

for(const o of filtered) {

    // Emit all odd numbers in descending order.
    console.log(o);  // 99, 97, 95 ...
}

linq<T> with simplified imports

import linq, {iterables, resolutions} from '@tsdotnet/linq';

const source = iterables.range(1,100); // Iterable<number>
const result = linq(source)
    .where(n => n%2===1) // odd numbers only
    .resolve(resolutions.sum); // 2500

or

import linq from '@tsdotnet/linq';
import {range} from '@tsdotnet/linq/dist/iterables';
import {sum} from '@tsdotnet/linq/dist/resolutions';

const source = range(1, 100); // Iterable<number>
const result = linqExtended(source)
    .where(n => n%2===1) // odd numbers only
    .resolve(sum); // 2500

Concepts

Iterables

ES2015 enables full support for the iteration protocol.

Iterables are a significant leap forward in operating with data sequences. Instead of loading entire sets into arrays or other collections, iterables allow for progressive iteration or synchronous streaming of data.

tsdotnet/linq is designed around iterables but also optimized for arrays.

Generators

Iterable<T> helpers are provided as sources. Calling for an Iterator<T> should always start from the beginning and iterators are not shared. Same behavior as LINQ in .NET.

empty, range, and repeat to name a few. See the docs for a full list.

Filters

linq(source).filter(a, b);
linq(source).filter(a).filter(b);
linq(source).filter(a).where(predicate);

Any function that receives an Iterable<T> and returns an Iterable<T> is considered an IterableFilter<T>. A filter may result in a different order or ultimately a completely different set than the input but must be of the same type.

There are an extensive set of filters. See the docs for a full list.

Transforms

linq(source).transform(x);
linq(source).filter(a).transform(x);
linq(source).where(predicate).transform(x);
linq(source).where(predicate).select(mapping);

Any function that receives an Iterable<T> and returns an Iterable<TResult> is considered an IterableValueTransform<T, TResult>.

Any filter can be used as a transform, but not every transform can be used as a filter.

notNull, rows, select, selectMany and groupBy to name a few. See the docs for a full list.

Resolutions

sequence = linq(source);

sequence.resolve(r);
sequence.transform(x).resolve(r);
sequence.filter(a).transform(x).resolve(r);
sequence.where(predicate).resolve(r);
sequence.filterWith(a, b).transform(x).resolve(r);
sequence = linqExtended(source);

// Examples: 
sequence.any(predicate);
sequence.any(); // resolution predicates are optional.

sequence.count(predicate);
sequence.first(predicate);
sequence.last(predicate);
sequence.singleOrDefault(defaultValue, predicate);
sequence.firstOrUndefined(predicate);
sequence.lastOrNull(predicate);

A resolution is a transform that takes an Iterable<T> and returns TResult. Unlike .filter(a) and .transform(x), .resolve(r) does not wrap the result in another Linq<T>.

There are an extensive set of resolutions. See the docs for a full list.

History

Originally this was a port of linq.js converted to full TypeScript under the name TypeScript.NET Library and then TypeScript.NET-Core with full module support but potentially more than a user might want for a simple task. Instead of .NET style extensions, Enumerables incurred a heavy cost of all the extensions under one module.

Modern web standards and practices demanded more granular access to classes and functions. Hence tsdotnet was born. tsdotnet/linq functionally allows for all the features of its predecessor as well as providing type-safety, and most of the features of LINQ in .NET while not forcing the consumer to download unneeded/undesired modules (extensions).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].