All Projects → StardustDL → Linq In Rust

StardustDL / Linq In Rust

Licence: apache-2.0
Language Integrated Query in Rust.

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Linq In Rust

Asyncenumerable
Defines IAsyncEnumerable, IAsyncEnumerator, ForEachAsync(), ParallelForEachAsync(), and other useful stuff to use with async-await
Stars: ✭ 367 (+664.58%)
Mutual labels:  linq
Netfabric.hyperlinq
High performance LINQ implementation with minimal heap allocations. Supports enumerables, async enumerables, arrays and Span<T>.
Stars: ✭ 479 (+897.92%)
Mutual labels:  linq
Seal Report
Open Database Reporting Tool (.Net)
Stars: ✭ 918 (+1812.5%)
Mutual labels:  linq
Tstl
TypeScript-STL (Standard Template Library, migrated from C++)
Stars: ✭ 397 (+727.08%)
Mutual labels:  iterator
Qone
Next-generation web query language, extend .NET LINQ for javascript.
Stars: ✭ 463 (+864.58%)
Mutual labels:  linq
Linq To Gameobject For Unity
LINQ to GameObject - Traverse GameObject Hierarchy by LINQ
Stars: ✭ 578 (+1104.17%)
Mutual labels:  linq
Nein Linq
NeinLinq provides helpful extensions for using LINQ providers such as Entity Framework that support only a minor subset of .NET functions, reusing functions, rewriting queries, even making them null-safe, and building dynamic queries using translatable predicates and selectors.
Stars: ✭ 347 (+622.92%)
Mutual labels:  linq
Finder
The Finder component finds files and directories via an intuitive fluent interface.
Stars: ✭ 7,840 (+16233.33%)
Mutual labels:  iterator
Scandir
Better directory iterator and faster os.walk(), now in the Python 3.5 stdlib
Stars: ✭ 471 (+881.25%)
Mutual labels:  iterator
Linq.ts
🌀LINQ for TypeScript
Stars: ✭ 687 (+1331.25%)
Mutual labels:  linq
Linqtotwitter
LINQ Provider for the Twitter API (C# Twitter Library)
Stars: ✭ 401 (+735.42%)
Mutual labels:  linq
Fromfrom
A JS library written in TS to transform sequences of data from format to another
Stars: ✭ 462 (+862.5%)
Mutual labels:  linq
Linq
Linq for list comprehension in C++
Stars: ✭ 599 (+1147.92%)
Mutual labels:  linq
Anglesharp
👼 The ultimate angle brackets parser library parsing HTML5, MathML, SVG and CSS to construct a DOM based on the official W3C specifications.
Stars: ✭ 4,018 (+8270.83%)
Mutual labels:  linq
System.linq.dynamic.core
The .NET Standard / .NET Core version from the System Linq Dynamic functionality.
Stars: ✭ 864 (+1700%)
Mutual labels:  linq
Tbox
🎁 A glib-like multi-platform c library
Stars: ✭ 3,800 (+7816.67%)
Mutual labels:  iterator
Unirx
Reactive Extensions for Unity
Stars: ✭ 5,501 (+11360.42%)
Mutual labels:  linq
Linq.py
Just as the name suggested.
Stars: ✭ 42 (-12.5%)
Mutual labels:  linq
Data Forge Ts
The JavaScript data transformation and analysis toolkit inspired by Pandas and LINQ.
Stars: ✭ 967 (+1914.58%)
Mutual labels:  linq
Linqfaster
Linq-like extension functions for Arrays, Span<T>, and List<T> that are faster and allocate less.
Stars: ✭ 615 (+1181.25%)
Mutual labels:  linq

Linq in Rust

CI Average time to resolve an issue Percentage of issues still open

Language Integrated Query in Rust (created by declarative macros).

This project is under development! API might be changed.

Quick Start

This is an example:

use linq::linq;
use linq::Queryable;

fn try_linq_methods() {
    let x = 1..100;
    let mut y: Vec<i32> = x.clone().filter(|p| p <= &5).collect();
    y.sort_by_key(|t| -t);
    let y: Vec<i32> = y.into_iter().map(|t| t * 2).collect();
    let e: Vec<i32> = x
        .clone()
        .where_by(|p| p <= &5)
        .order_by(|p| -p)
        .select(|p| p * 2)
        .collect();
    assert_eq!(e, y);
}

fn try_linq_expr() {
    let x = 1..100;
    let mut y: Vec<i32> = x.clone().filter(|p| p <= &5).collect();
    y.sort_by_key(|t| -t);
    let y: Vec<i32> = y.into_iter().map(|t| t * 2).collect();
    let e: Vec<i32> =
        linq!(from p in x.clone(), where p <= &5, orderby -p, select p * 2).collect();
    assert_eq!(e, y);
}

If you are familier with LINQ in C#, you will find this is easy to use.

Usage

The two imports is necessary:

use linq::linq;         // for `linq!` macro
use linq::iter::Enumerable;    // for LINQ methods and `linq!` macro

Methods

The trait linq::Queryable supports LINQ methods on Iterator. You can find the correspondences below.

  • Normal items mean they are builtin methods of Iterator in std.
  • Bold items mean they are implemented in this project. You can find them in module linq::iter (but they are private so that you can't import them).
  • Italic items mean they are not in roadmap. Happy for your suggestions.

  • [x] where => where_by => filter
  • [x] select => map
  • [x] select_many => select_many_single, select_many
  • [x] skip
  • [x] skip_while
  • [x] take
  • [x] take_while
  • [ ] join
  • [ ] group_join
  • [x] concate => chain
  • [x] order_by
  • [x] order_by_descending
  • [ ] then_by
  • [ ] then_by_descending
  • [x] reverse => rev
  • [ ] group_by
  • [x] distinct
  • [x] union
  • [ ] intersect
  • [ ] except
  • [x] first => next
  • [x] single
  • [x] element_at => nth
  • [x] all
  • [x] any
  • [x] contains
  • [x] count
  • [x] sum
  • [x] product
  • [x] min
  • [x] max
  • [ ] average
  • [ ] aggregate => fold

Expressions

The query expression begins with from clause and ends with select clause. Use , to seperate every clause.

linq!(from x in coll, select x)

Now we supports these keywords:

  • [x] from
    • [x] from (select_many_single)
    • [x] zfrom (select_many)
  • [x] in
  • [x] select
  • [x] where
  • [x] orderby
  • [x] descending
  • [ ] group_by
  • [ ] more...

From

from <id> in <iter expr>,

Also you can enumerate elements of each set in the collection (Attention: for this type, you can't access the value that is in the first from clause in select clause):

let x = 1..5;
let y = vec![0, 0, 1, 0, 1, 2, 0, 1, 2, 3];
let e: Vec<i32> = linq!(from p in x.clone(), from t in 0..p, select t).collect();

assert_eq!(e, y);

If you want to zip or enumerate value-pairs of two sets, use zfrom for the second from:

let x = 1..5;
let y = vec![
    (1, 0),
    (2, 0),
    (2, 1),
    (3, 0),
    (3, 1),
    (3, 2),
    (4, 0),
    (4, 1),
    (4, 2),
    (4, 3),
];
let e: Vec<_> = linq!(from p in x.clone(), zfrom t in 0..p, select (p,t)).collect();

assert_eq!(e, y);

The expression in zfrom recieve the cloned value in the first from, and the elements in two sets will be cloned for select clause.

Where

while <expr>,

You can use where clause in single-from query, and the expression will recieve a variable named the id in from clause. The expression need to return a boolean value.

Orderby

orderby <expr>,
orderby <expr>, descending,

You can use orderby clause in single-from query. This query will collect the iterator, and sort them by the expression, then return the new iterator.

Development

We need more unit-test samples. If you have any ideas, open issues to tell us.

Since the expression procedural macros is not stable, I only create macros by declarative macros.

$ cargo test
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].