I've been working on my own scripting language for my game engine, whose interpreter I wrote in C#. So, for quite a long time now, the only languages I use are C# and my custom language.
Apparently, it's really hard to work without LINQ after you got used to it, so I decided to add it to my language! [Note: I'm talking about in-memory queries, I didn't re-implement the whole EF core...]
Here's a few examples:
const dangerousEnemies = q(room.objects) .ofType() .where(func(e) => distanceToObject(e) < 100) .groupBy(func(e) => e.specialPower) .toArr() foreach product in q(products) .orderBy(func(p) => p.price) .select(func(p) => p.name) { println(product) } func getFileExtension(filePath) { const i = q(filePath).reverse().indexOf('.') return filePath.substr(i, filePath.length() - i) } I did my best to make the design as close to .NET LINQ as possible. You can query anything that you can use in a foreach loop, and it uses deferred execution, meaning the query doesn't actually run until you iterate over it or call .toArr(), .toList(), or one of the other methods that execute it.It also performs just one iteration per query. You can do where().select(), and instead of iterating once for the where operator and then again for the select operator, it processes both in a single iteration.
This post links to the code of this little LINQ library, so you can check it if it sounds interesting to you. Would love to hear what u think about it!
Comments URL: https://news.ycombinator.com/item?id=50643342
Points: 1
# Comments: 0
