'stream' values

# Mohan.Radhakrishnan at cognizant.com (10 years ago)

Can I stream values and operate on them like this ? I have a map and I would like to stream them. I also want to chain the functions. So, for example, I may sort the map's values and pass them on.

map.entries((e,m) => sort by using a predicate ).foreach(manipulate the map's values);

Thanks, Mohan This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient(s), please reply to the sender and destroy all copies of the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email, and/or any action taken in reliance on the contents of this e-mail is strictly prohibited and may be unlawful. Where permitted by applicable law, this e-mail and other e-mail communications sent to and from Cognizant e-mail addresses may be monitored.

# Mark Volkmann (10 years ago)

The entries method of a Map doesn't take a function. It does return an array though. That array contains [key, value] arrays. So you could do this.

map.entries().sort(([k1, v1], [k2, v2]) => k1.localeCompare(k2)).forEach(([k, v]) => do-something);


R. Mark Volkmann Object Computing, Inc.

# Mohan.Radhakrishnan at cognizant.com (10 years ago)

That line matches my Java code almost exactly. My traceur transpiler though throws ‘TypeError: map.entries(...).sort is not a function’. Should I switch the traspiler ?

Thanks, Mohan

From: Mark Volkmann [mailto:r.mark.volkmann at gmail.com] Sent: Wednesday, May 06, 2015 4:19 PM To: Radhakrishnan, Mohan (Cognizant) Cc: <es-discuss at mozilla.org>

Subject: Re: 'stream' values

The entries method of a Map doesn't take a function. It does return an array though. That array contains [key, value] arrays. So you could do this.

map.entries().sort(([k1, v1], [k2, v2]) => k1.localeCompare(k2)).forEach(([k, v]) => do-something);


R. Mark Volkmann Object Computing, Inc.

On May 6, 2015, at 4:27 AM, <Mohan.Radhakrishnan at cognizant.com<mailto:Mohan.Radhakrishnan at cognizant.com>> <Mohan.Radhakrishnan at cognizant.com<mailto:Mohan.Radhakrishnan at cognizant.com>> wrote:

Hi, Can I stream values and operate on them like this ? I have a map and I would like to stream them. I also want to chain the functions. So, for example, I may sort the map’s values and pass them on.

map.entries((e,m) => sort by using a predicate ).foreach(manipulate the map’s values);

Thanks, Mohan This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient(s), please reply to the sender and destroy all copies of the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email, and/or any action taken in reliance on the contents of this e-mail is strictly prohibited and may be unlawful. Where permitted by applicable law, this e-mail and other e-mail communications sent to and from Cognizant e-mail addresses may be monitored.

# Erik Arvidsson (10 years ago)

entries() returns an iterator.

To sort you need to convert to an array first.

let a = [...map.entries()]; a.sort()

# Mohan.Radhakrishnan at cognizant.com (10 years ago)

That was helpful.

I find it interesting that ES6 code is very similar to Java 8 lambdas.

Thanks, Mohan

From: Erik Arvidsson [mailto:erik.arvidsson at gmail.com] Sent: Wednesday, May 06, 2015 6:37 PM To: Radhakrishnan, Mohan (Cognizant); r.mark.volkmann at gmail.com Cc: es-discuss at mozilla.org Subject: Re: 'stream' values

entries() returns an iterator.

To sort you need to convert to an array first.

let a = [...map.entries()]; a.sort()

On Wed, May 6, 2015, 08:37 <Mohan.Radhakrishnan at cognizant.com<mailto:Mohan.Radhakrishnan at cognizant.com>> wrote:

That line matches my Java code almost exactly. My traceur transpiler though throws ‘TypeError: map.entries(...).sort is not a function’. Should I switch the traspiler ?

Thanks, Mohan

From: Mark Volkmann [mailto:r.mark.volkmann at gmail.com<mailto:r.mark.volkmann at gmail.com>]

Sent: Wednesday, May 06, 2015 4:19 PM To: Radhakrishnan, Mohan (Cognizant) Cc: <es-discuss at mozilla.org<mailto:es-discuss at mozilla.org>>

Subject: Re: 'stream' values

The entries method of a Map doesn't take a function. It does return an array though. That array contains [key, value] arrays. So you could do this.

map.entries().sort(([k1, v1], [k2, v2]) => k1.localeCompare(k2)).forEach(([k, v]) => do-something);


R. Mark Volkmann Object Computing, Inc.

On May 6, 2015, at 4:27 AM, <Mohan.Radhakrishnan at cognizant.com<mailto:Mohan.Radhakrishnan at cognizant.com>> <Mohan.Radhakrishnan at cognizant.com<mailto:Mohan.Radhakrishnan at cognizant.com>> wrote:

Hi, Can I stream values and operate on them like this ? I have a map and I would like to stream them. I also want to chain the functions. So, for example, I may sort the map’s values and pass them on.

map.entries((e,m) => sort by using a predicate ).foreach(manipulate the map’s values);

Thanks, Mohan This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient(s), please reply to the sender and destroy all copies of the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email, and/or any action taken in reliance on the contents of this e-mail is strictly prohibited and may be unlawful. Where permitted by applicable law, this e-mail and other e-mail communications sent to and from Cognizant e-mail addresses may be monitored.

# Tab Atkins Jr. (10 years ago)

On Thu, May 7, 2015 at 12:36 AM, <Mohan.Radhakrishnan at cognizant.com> wrote:

That was helpful.

I find it interesting that ES6 code is very similar to Java 8 lambdas.

The relationship is closer to the other way around. ^_^

# Brendan Eich (10 years ago)

I've been working to put the JavaScript in Java since 1995 :-D.

# Mohan.Radhakrishnan at cognizant.com (10 years ago)

Yes :-) I know that JDK 9 has (re) invented the REPL.

One of the things that prompted me to ask about streams is the underlying fork/join framework that uses the work-stealing algorithm. Will there be a similar library in ES6 or later ?

Mohan