I am just getting started with functional programming in Java. I'd like some help with a simple exercise to get up to speed.
Suppose one has the following two interfaces:
interface P {
boolean filter(int v);
}
interface F {
int apply(int v);
}
and one is required to create a map function that takes a function f as an argument and returns a Node that applies f to all elements. Secondly, one is required to create a filter function that returns a Node with all elements that match a predicate p within the Following class:
public class Node {
private int item;
private Node next;
public Node(int item, Node next){
this.item = item;
this.next = next;
}
/* Create a new Node that applies function f to all elements */
public Node map(F f){
}
/* Creates a new Node with all elements that match predicate p */
public Node filter(P p){
}
}