3 ms·
You've just described LINQ which has a sqlish dsl as part of C#: ``` List<int> numbers = [5, 4, 1, 3, 9, 8, 6, 7, 2, 0]; // The query variables can also be i
by bbatha 2y ago
You've just described LINQ which has a sqlish dsl as part of C#:
```
List<int> numbers = [5, 4, 1, 3, 9, 8, 6, 7, 2, 0];
// The query variables can also be implicitly typed by using var
// Query #1.
IEnumerable<int> filteringQuery =
from num in numbers
where num is < 3 or > 7
select num;
// Query #2.
IEnumerable<int> orderingQuery =
from num in numbers
where num is < 3 or > 7
orderby num ascending
select num;
// Query #3.
string[] groupingQuery = ["carrots", "cabbage", "broccoli", "beans", "barley"];
IEnumerable<IGrouping<char, string>> queryFoodGroups =
from item in groupingQuery
group item by item[0];
```
https://learn.microsoft.com/en-us/dotnet/csharp/linq/get-started/write-linq-queries#example---query-syntax https://learn.microsoft.com/en-us/dotnet/csharp/linq/get-sta...
- acuozzo 2y agoI'm not prisenco, but does LINQ have its memory model in SQL? What tickles me about the idea I posted above is that you could take a snapshot of your entire program state (at sequence points) and it's just an SQLite db file.
- knome 2y agoLinq uses a bunch of iterators functions that accept lambdas. C# allows them to capture the lambdas as an expression so it can convert the expression into SQL or whatever. it also has an SQL-like syntax you can use that is compiled into those iterators. the interface is generic, with builtin support for ienumerable types and SQL data sources.