I am not very comfortable with this. How can I learn to do this in traditionally non-FP languages like Java? (Am CS undergrad student)
MAP: Take a collection, say a list/array or a dictionary/hash, and perform some function on each member of the collection, returning a new collection who's members are the return values for each original member. It's a loop, but no loop!
REDUCE: Do the same thing as map, but carry along an output variable, and have your function's output for each member (potentially) mutate that output variable. Summing is a basic example.
I'm not specifically recommending preferring this in Java as a step towards functional programming. It's in, uh, more terse languages like Python and Ruby where the payoff is obvious [1][2]. And among not-functional programming languages, it's not just dynamic languages, either. Consider Dart (and seriously, consider Dart) [3]. Also, Javascript, which has had many features shoehorned-in over the years, has these and related functions.
[0] https://www.java67.com/2016/09/map-reduce-example-java8.html
[1] Double some numbers Python: result = map(lambda x: x + x, array_of_numbers)
[2] In Ruby: result = array_of_numbers.map{|x| x + x}
[3] In Dart: result = arrayOfNumbers.map((x) => x + x).toList();
My school (Macalester College) recently started introducing some fp constructs/concepts in our intro class such as map, reduce like you mentioned.
It was long after I took it and now I am TA-ing. Oddly enough, I am more comfortable approaching this style in Kotlin.
https://developer.ibm.com/technologies/java/series/java-8-id...
List of articles relating to idiomatic Java 8 code. Some of these touch on using lambdas and functional idioms.
https://developer.ibm.com/articles/j-java8idioms3/
This one shows a few of the functional-styled methods that can be used (foreach, takewhile, iterate, etc.).
https://developer.ibm.com/articles/j-java8idioms2/
Shows the collection pipeline pattern.
I have experience with the same things in C# and other languages, the way they're using them in these articles are what I'd expect from a comparable API.