Native Linq for TypeScript

Topics: General
Oct 2, 2012 at 5:32 PM

There is linq.js, but will be native LINQ included in the TypeScript language specification?

 

Oct 2, 2012 at 10:53 PM

This has already been suggested elsewhere. Since TypeScript is guided by EcmaScript 6, perhaps the array comprehension and generators syntax is what TypeScript should implement.

Coordinator
Oct 5, 2012 at 5:00 PM

We're in the process now of getting to a 1.0 where the language has stabilized.  Features like linq and array comprehensions would be a good things to ask about in the post-1.0 timeframe. 

Mar 10, 2013 at 5:19 PM
Edited Mar 10, 2013 at 5:20 PM
Still no LINQ csharp like operators supported?
Mar 10, 2013 at 9:50 PM
Edited Mar 10, 2013 at 9:51 PM
DotNetWise, we're still in pre-1.0. Check out the TypeScript roadmap, and you'll see that LINQ-style stuff isn't planned. However, the next version, 0.9.x, does have ECMAScript 6 alignment planned, which includes generators, which is similar to yield return functionality upon which C#'s LINQ is built.

Bottom line: once the next version is released, we should have ECMAScript 6 alignment, which would allow you to easily implement LINQ yourself. You wouldn't have syntax support, but you could write something like:
items
    .Where(i => i.Foo = 42)
    .Select(i => { Blah = i.Foo });
And still have it all lazily-evaluated, just like LINQ. I think that may be sufficient for most of us LINQ fans.
Mar 12, 2013 at 2:10 PM
It's already possible to write the following with TS as it stands:
var items = [{ foo: 41}, { foo: 42}];

var result =
items
    .filter(i => i.foo === 42)
    .map(i => ({ bar: i.foo }));

console.log(JSON.stringify(result)); // [{"bar":42}]
There doesn't seem to be a strong case for introducing LINQ-like syntax (Select, Where etc.) into the language.

That would create two competing syntaxes for doing the same job.
Mar 12, 2013 at 2:13 PM
So if they arelady exist, why not supporting both (aliases)?
People who know LINQ will simply reuse their knowledge, people who will learn javascript/typescript can use the above ones.
Mar 12, 2013 at 2:25 PM
@DotNetWise, sure. How many other languages would you like to see supported?!
Mar 12, 2013 at 2:26 PM
@DotNetWise, sure. How many other languages would you like to see supported?!
Mar 12, 2013 at 2:28 PM
nabog wrote:
@DotNetWise, sure. How many other languages would you like to see supported?!
Wait, it's not technically a language, and it's already partially supported :)

It's a mindset that most of .NET world already have so why not reuse it? :)
TypeScript it's exactly all about that!
Iterators, enumerators and queryables (projections) really suck in native javascript.
So why not writing less and getting more?
Mar 12, 2013 at 2:33 PM
Linq in C# is lazily evaluated. When i personally think of Linq in typescript/javascript i tend to think about generators.
i agree that eager evaluated linq is very easy to write in javascript...


On Tue, Mar 12, 2013 at 3:28 PM, DotNetWise <notifications@codeplex.com> wrote:

From: DotNetWise

nabog wrote:
@DotNetWise, sure. How many other languages would you like to see supported?!
Wait, it's not technically a language, and it's already partially supported :)

It's a mindset that most of .NET world already have so why not reuse it? :)
TypeScript it's exactly all about that!
Iterators, enumerators and queryables (projections) really suck in native javascript.
So why not writing less and getting more?

Read the full discussion online.

To add a post to this discussion, reply to this email (typescript@discussions.codeplex.com)

To start a new discussion for this project, email typescript@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Mar 12, 2013 at 2:41 PM
lazyily evaluated is not really needed in javascript. We just need to have easier (known) ways of doing stuff that is currently possible in javascript by scratching your head with the foot (long, complex/complicated code for the simple reusable operations when working with arrays)
Mar 12, 2013 at 3:04 PM
DotNetWise wrote:
lazyily evaluated is not really needed in javascript. We just need to have easier (known) ways of doing stuff that is currently possible in javascript by scratching your head with the foot (long, complex/complicated code for the simple reusable operations when working with arrays)
You may not be working with large datasets but others are. Running multiple enumerations of a set of data (the result of non-lazy evaluation of LINQ calls) can be very inefficient.
Mar 12, 2013 at 3:11 PM
I don't think the discussion here is about performance, but more about the way you can 'write' the simple actions which normally take a longer approach in plain javascript.
Of course we can debate performance in itself but that should be a separate thread.
Mar 12, 2013 at 3:13 PM
You said "lazyily evaluated is not really needed in javascript". I was refuting that point.
Mar 12, 2013 at 3:26 PM
.map and .filter are not the same thing. They are eager evaluated. LINQ is lazy evaluated. Lazy evaluation is needed, and not just for large datasets.
Mar 12, 2013 at 3:28 PM
Me too, but i felt the absurdity of that statement does not deserve an answer :)


On Tue, Mar 12, 2013 at 4:13 PM, MgSam <notifications@codeplex.com> wrote:

From: MgSam

You said "lazyily evaluated is not really needed in javascript". I was refuting that point.

Read the full discussion online.

To add a post to this discussion, reply to this email (typescript@discussions.codeplex.com)

To start a new discussion for this project, email typescript@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Mar 12, 2013 at 3:42 PM
Correct me if I'm wrong, but I don't think there is a sensible way to implement lazy evaluation until generators are natively supported by browser JavaScript engines.

(It may be possible by executing a callback at each iteration - but that's not sensible, right?)

When generators do land in the language then we can have the cake and eat it.

But until then what would we have TypeScript do?
Mar 12, 2013 at 3:43 PM
Maybe state machine based generators as c# does?


On Tue, Mar 12, 2013 at 4:42 PM, nabog <notifications@codeplex.com> wrote:

From: nabog

Correct me if I'm wrong, but I don't think there is a sensible way to implement lazy evaluation until generators are natively supported by browser JavaScript engines.

(It may be possible by executing a callback at each iteration - but that's not sensible, right?)

When generators do land in the language then we can have the cake and eat it.

But until then what would we have TypeScript do?

Read the full discussion online.

To add a post to this discussion, reply to this email (typescript@discussions.codeplex.com)

To start a new discussion for this project, email typescript@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Mar 12, 2013 at 3:47 PM
It's possible to do without generators, after all, "generators" in C# just spit out plain old procedural code, and linq.js already implements lazy evaluation.

But since it's a lot of manual code to implement lazy sequence evaluation in JS, a good solution would be to wait until we have ECMAScript 6 generators in TypeScript. At that point, implementing a lazy .map and .filter (or .Select and .Where, if you prefer) would be trivial, and might make a good foundation for a TypeScript standard library.
Mar 12, 2013 at 3:52 PM
I read some articles from 2008 when people were happy that Ecmascript4 supports decimal:

use decimal;
var a = 0.1;
var b = 0.2;

if (a+b === 0.3)
alert('Unbelievable!!');



On Tue, Mar 12, 2013 at 4:51 PM, Liviu U <liviu.u@gmail.com> wrote:
I digress, but maybe you guys have more knowledge about EcmasScript 6: is the decimal data type going to be supported?
Is there now any browser that supports it?
Is there any hope to have decent financial calculations in browser?


On Tue, Mar 12, 2013 at 4:47 PM, JudahGabriel <notifications@codeplex.com> wrote:

From: JudahGabriel

It's possible to do without generators, after all, "generators" in C# just spit out plain old procedural code, and linq.js already implements lazy evaluation.

But since it's a lot of manual code to implement lazy sequence evaluation in JS, a good solution would be to wait until we have ECMAScript 6 generators in TypeScript. At that point, implementing a lazy .map and .filter (or .Select and .Where, if you prefer) would be trivial, and might make a good foundation for a TypeScript standard library.

Read the full discussion online.

To add a post to this discussion, reply to this email (typescript@discussions.codeplex.com)

To start a new discussion for this project, email typescript@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com



Mar 12, 2013 at 3:52 PM
I digress, but maybe you guys have more knowledge about EcmasScript 6: is the decimal data type going to be supported?
Is there now any browser that supports it?
Is there any hope to have decent financial calculations in browser?


On Tue, Mar 12, 2013 at 4:47 PM, JudahGabriel <notifications@codeplex.com> wrote:

From: JudahGabriel

It's possible to do without generators, after all, "generators" in C# just spit out plain old procedural code, and linq.js already implements lazy evaluation.

But since it's a lot of manual code to implement lazy sequence evaluation in JS, a good solution would be to wait until we have ECMAScript 6 generators in TypeScript. At that point, implementing a lazy .map and .filter (or .Select and .Where, if you prefer) would be trivial, and might make a good foundation for a TypeScript standard library.

Read the full discussion online.

To add a post to this discussion, reply to this email (typescript@discussions.codeplex.com)

To start a new discussion for this project, email typescript@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Mar 12, 2013 at 3:53 PM
and now 4 years after, there is no trace of such thing



On Tue, Mar 12, 2013 at 4:52 PM, Liviu U <liviu.u@gmail.com> wrote:
I read some articles from 2008 when people were happy that Ecmascript4 supports decimal:

use decimal;
var a = 0.1;
var b = 0.2;

if (a+b === 0.3)
alert('Unbelievable!!');



On Tue, Mar 12, 2013 at 4:51 PM, Liviu U <liviu.u@gmail.com> wrote:
I digress, but maybe you guys have more knowledge about EcmasScript 6: is the decimal data type going to be supported?
Is there now any browser that supports it?
Is there any hope to have decent financial calculations in browser?


On Tue, Mar 12, 2013 at 4:47 PM, JudahGabriel <notifications@codeplex.com> wrote:

From: JudahGabriel

It's possible to do without generators, after all, "generators" in C# just spit out plain old procedural code, and linq.js already implements lazy evaluation.

But since it's a lot of manual code to implement lazy sequence evaluation in JS, a good solution would be to wait until we have ECMAScript 6 generators in TypeScript. At that point, implementing a lazy .map and .filter (or .Select and .Where, if you prefer) would be trivial, and might make a good foundation for a TypeScript standard library.

Read the full discussion online.

To add a post to this discussion, reply to this email (typescript@discussions.codeplex.com)

To start a new discussion for this project, email typescript@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com