vendredi 20 avril 2018

How can I clean up my Java Streams?

I have this stream, as well as quite a few others, where I abuse a bunch of calls to get the job done. Seems like an anti-pattern when taking advantage of J8.

+    Arrays.stream(resources)
+        .map(this::ingestFromFile)
+        .collect(Collectors.toList())
+        .stream()
+        .map(Container.class::cast)
+        .map(Container::getAll)
+        .flatMap(Collection::stream)
+        .collect(Collectors.toList())
+        .forEach(
+            dataType -> {
+              loaderConstants.getRepo(dataType.toString()).save(dataType);
+              LOGGER.log(Level.INFO, "Saved: " + dataType);
+            });

How can I shorten this up and what pitfalls should I look out for in the future to avoid this type of development?

Aucun commentaire:

Enregistrer un commentaire