preview

Nt1310 Unit 8 Assignment 8

Decent Essays

One of the largest features in Java 8 was the ability to stream over collections of objects. By adding the .stream()-method into the Collection interface, every collection in the java language was suddenly expanded with this new ability. Other data structures like the Map-interface, does not implement the method as they are not strictly speaking collections. In this article I will show you how Speedment Open Source streams efficiently over standard Java maps, expanding the Stream interface into something called a MapStream! This addition will make it easier to keep your streams concrete and readable even in complex scenarios. Hopefully this will allow you to keep streaming without prematurely collecting the result. The MapStream will take …show more content…

} [/code] Some operations will still need to return an ordinary Stream. If the operation change the type of the streamed element, we can’t ensure that the new type will be a Map.Entry. We can, however, add additional methods for mapping between types with Key-Value pairs. [code language="java"] @Override Stream map(Function, ? extends R> mapper); Stream map(BiFunction mapper); [/code] In addition to the Function that let the user map from an Entry to something else, he or she can also map from a Key-Value-pair to something else. This is convenient, sure, but we can also add more specific mapping operations now that we are working with pairs of values. [code language="java"] MapStream mapKey(BiFunction mapper); MapStream mapValue(BiFunction mapper); [/code] The difference doesn’t look like much, but the difference is apparent when using the …show more content…

If you are interested in more cool stuff, have a look at the Speedment Github page. Have fun

Get Access