Higher-order Functions Map And Reduce Assignment

From CSE231 Wiki
Jump to navigation Jump to search

Java

interface Function<T,R>

Code to Investigate

VolleyballMapClient

List<Player> roster = VolleyballRoster.WASHU_2021.players();
List<Integer> heights = MapUtils.map((player) -> {
	return player.height();
}, roster);
heights.forEach((height) -> {
	System.out.println(height);
});

Code to Implement

map

class: MapUtils.java Java.png
methods: map
package: hof.map.exercise
source folder: student/src/main/java

method: <T, R> List<R> map(Function<T, R> f, List<T> list)) Sequential.svg (sequential implementation only)

clients

class: MapClients.java Java.png
methods: mapToLengths
mapToStrictlyLessThan
package: hof.map.exercise
source folder: student/src/main/java

We created a couple of utility methods which invoke map with a custom lambda.

mapToLengths

method: List<Integer> mapToLengths(List<String> texts) Sequential.svg (sequential implementation only)

mapToStrictlyLessThan

method: List<Boolean> mapToStrictlyLessThan(List<Integer> xs, int threshold) Sequential.svg (sequential implementation only)

Test

class: _MapTestSuite.java Junit.png
package: hof.map.group
source folder: testing/src/test/java