|
|
There is linq.js, but will be native LINQ included in the TypeScript language specification?
|
|
|
|
|
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 4: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 at 4:19 PM
Edited Mar 10 at 4:20 PM
|
Still no LINQ csharp like operators supported?
|
|
|
Mar 10 at 8:50 PM
Edited Mar 10 at 8: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.
|
|
|
|
|
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.
|
|
|
|
|
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.
|
|
|
|
|
@DotNetWise, sure. How many other languages would you like to see supported?!
|
|
|
|
|
@DotNetWise, sure. How many other languages would you like to see supported?!
|
|
|
|
|
**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?
|
|
|
|
|
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?
|
|
|
|
|
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)
|
|
|
|
|
**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.
|
|
|
|
|
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.
|
|
|
|
|
You said "lazyily evaluated is not really needed in javascript". I was refuting that point.
|
|
|
|
|
.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.
|
|
|
|
|
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.
|
|
|
|
|
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?
|
|
|
|
|
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?
|
|
|
|
|
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.
|
|
|
|
|
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.
|
|
|
|
|
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.
|
|
|
|
|
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.
|
|