Successfully reported this slideshow.
Your SlideShare is downloading. ×

Eclipse Collections, Java Streams & Vavr - What's in them for Functional Programming

Ad

Eclipse Collections, Java Streams & Vavr -
What's in them for
Functional Programming
Naresha K

Independent Consultant

@n...

Ad

Java Streams

Ad

https://www.eclipse.org/collections/

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Loading in …3
×

Check these out next

1 of 31 Ad
1 of 31 Ad

Eclipse Collections, Java Streams & Vavr - What's in them for Functional Programming

Download to read offline

Slides from the Functional Conf 2019 presentation - "Eclipse Collections, Java Streams & Vavr - What's in them for Functional Programming". How to leverage Eclipse Collections and Vavr libraries for improved developer experience for functional programming.

Slides from the Functional Conf 2019 presentation - "Eclipse Collections, Java Streams & Vavr - What's in them for Functional Programming". How to leverage Eclipse Collections and Vavr libraries for improved developer experience for functional programming.

More Related Content

Similar to Eclipse Collections, Java Streams & Vavr - What's in them for Functional Programming (20)

More from Naresha K (20)

Eclipse Collections, Java Streams & Vavr - What's in them for Functional Programming

  1. 1. Eclipse Collections, Java Streams & Vavr - What's in them for Functional Programming Naresha K Independent Consultant @naresha_k https://blog.nareshak.com/
  2. 2. Java Streams
  3. 3. https://www.eclipse.org/collections/
  4. 4. A Taste of APIs
  5. 5. public static List<Developer> getSampleListOfDevelopers() { List<Developer> developers = new ArrayList<>(); developers.add(new Developer("Raj", 30, Arrays.asList("Java", "JavaScript"))); developers.add(new Developer("Meena", 24, Arrays.asList("Java", "Groovy", "Scala"))); developers.add(new Developer("Mark", 28, Arrays.asList("Java", "JavaScript", "Groovy"))); return developers; }
  6. 6. List<Developer> developerYoungerThan30Years = developers .stream() .filter(developer -> developer.getAge() < 30) .collect(Collectors.toList()); System.out.println(developerYoungerThan30Years);
  7. 7. String namesOfDevelopersSeparatedByComma = developers .stream() .map(developer -> developer.getName()) .collect(Collectors.joining(", ")); System.out.println(namesOfDevelopersSeparatedByComma);
  8. 8. Set<String> languagesKnown = developers .stream() .map(developer -> developer.getLanguages()) .flatMap(List::stream) .collect(Collectors.toSet()); System.out.println(languagesKnown);
  9. 9. MutableList<Developer> developers = Lists.mutable.of( new Developer("Raj", 30, Arrays.asList("Java", "JavaScript")), new Developer("Meena", 24, Arrays.asList("Java", "Groovy", "Scala")), new Developer("Mark", 28, Arrays.asList("Java", "JavaScript", "Groovy")) );
  10. 10. MutableList<Developer> developersYoungerThan30 = developers .select(developer -> developer.getAge() < 30); System.out.println("Age < 30: " + developersYoungerThan30); System.out.println("All Devs: " + developers); MutableList<Developer> developersYoungerThan30Alternate = developers .reject(developer -> developer.getAge() >= 30); System.out.println("Age < 30: " + developersYoungerThan30Alternate);
  11. 11. String namesOfDevelopers = developers .collect(developer -> developer.getName()) .makeString(", "); System.out.println("Names: " + namesOfDevelopers);
  12. 12. MutableList<String> languages = developers .flatCollect(developer -> Lists.mutable.ofAll(developer.getLanguages())) .distinct(); System.out.println(languages);
  13. 13. List<Developer> developers = List.of( new Developer("Raj", 30, Arrays.asList("Java", "JavaScript")), new Developer("Meena", 24, Arrays.asList("Java", "Groovy", "Scala")), new Developer("Mark", 28, Arrays.asList("Java", "JavaScript", "Groovy")));
  14. 14. List<Developer> developersYoungerThan30 = developers .filter(developer -> developer.getAge() < 30); System.out.println(developersYoungerThan30);
  15. 15. String namesOfDevelopers = developers .map(developer -> developer.getName()) .intersperse(", ") .reduce((v1, v2) -> v1 + v2); System.out.println(namesOfDevelopers);
  16. 16. List<String> languagesKnown = developers .map(developer -> developer.getLanguages()) .flatMap(Function.identity()) .distinct(); System.out.println(languagesKnown);
  17. 17. Mutable vs Immutable
  18. 18. Mutable vs Immutable Java Streams Implicit (Effectively Final) Collections - mostly mutable Eclipse Collections Explicit / Different APIs Vavr Immutable only
  19. 19. Eager vs Lazy
  20. 20. Eager vs Lazy Java Streams Lazy Eclipse Collections Explicit / Different APIs Vavr Explicit / Different APIs
  21. 21. Serial vs Parallel
  22. 22. Serial vs Parallel Java Streams Serial (default) Easy to switch to Parallel Eclipse Collections Serial (default) Limited support for Parallel Vavr No support for Parallel
  23. 23. Streams Gotchas
  24. 24. Error Handling
  25. 25. Java Collections Inter-op
  26. 26. Fluency of API
  27. 27. https://github.com/eclipse/eclipse-collections/blob/master/docs/guide.md#-basic-collection-types
  28. 28. Container Factory List Lists Set Sets, HashingStrategySets Bag Bags Stack Stacks SortedBag SortedBags SortedSet SortedSets Map Maps, HashingStrategyMaps SortedMap SortedMaps BiMap BiMaps Multimap Multimaps https://github.com/eclipse/eclipse-collections/blob/master/docs/guide.md#-creating-mutable-collections
  29. 29. References • https://www.infoq.com/presentations/java8-functional-programming-vavr/ • https://github.com/naresha/fnconf2019

×