4 ms·
SQL and functional programming constructs are actually quite similar: SELECT -> map FROM -> stream JOIN -> flatMap WHERE -> filter GROUP BY -> collect ORD
by taffer 6y ago
SQL and functional programming constructs are actually quite similar:
SELECT -> map
FROM -> stream
JOIN -> flatMap
WHERE -> filter
GROUP BY -> collect
ORDER BY -> sorted
https://blog.jooq.org/2015/08/13/common-sql-clauses-and-their-equivalents-in-java-8-streams/ https://blog.jooq.org/2015/08/13/common-sql-clauses-and-thei...
- karmakaze 6y agoI don't see how JOIN is like flatMap. It's a subset of a cross-product. It's more like do-notation: x <- .. y <- .. return (x, y)
- taffer 6y ago> I don't see how JOIN is like flatMap This is explained in the blog post I linked, including an example.
- karmakaze 6y agoIt's really flatMap/map from the link: List<Integer> s1 = Stream.of(1, 2); Supplier<Stream<String>> s2 = ()->Stream.of("A", "B"); s1.flatMap(v1 -> s2.get() .map(v2 -> tuple(v1, v2))) .forEach(System.out::println); That's just a nested loop.