jeudi 31 mars 2016

Java 8 Lambda To Handle for > if > else

I need to run two different tasks based on a whole mess of filters

I'm just now grasping the concept of Lambdas, so I guess my question is, how do you handle multiple "else" conditions containing complicated logic... within a Lambda?

I know I can use filter and map to select certain pieces of data. How does "nesting" work with filters?

Could I do something like:

//Iterate over list of sites
sites.stream()
//Check if current site is active
.map(isActive ? 
//{Do something with site because site is active};
//Set a variable for later user maybe?
:
//{Do something else involving the current site because it's not?};
//Set a different variable maybe?
);

//use variable from first map?

Can someone provide me with some proper syntax and maybe a basic explanation of what I'm doing to my data when I run through these abstract processes that are doing me a bamboozle.

Secondly, if I wanted to run these two map processes in parallel, would I just do this?

sites.stream().parallel()?

As usual, thanks for helping with my ignorance!

Aucun commentaire:

Enregistrer un commentaire