Question: Please look at the TODO part and help me with this following code package fp; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Comparator; import java.util.Map; import java.util.function.
Please look at the TODO part and help me with this following code
package fp;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Map;
import java.util.function.;
import java.util.List;
class ExerciseNotCompletedException extends RuntimeException
public ExerciseNotCompletedException
superExercise is not completed yet";
@link HW is an exercise class. Each method returns a functional interface and it should be implemented
using either lambda or a method reference. Every method that is not implemented yet throws
@link ExerciseNotCompletedException
TODO: remove exception and implement each method of this class using lambda or method reference
TODO: to get the most out of your learning, visit our website
record pair U u V v
public class HW
precondition: l and l have the same length
static List zipList l List l
walk through the Us and Vs
construct list of pairs
ArrayList l new ArrayList;
for int i ; i lsize; i
laddnew pairlgetilgeti;
return l;
ArrayList l new ArrayList;
for int i ; i lsize; i laddi;
return mapl i new pairlgeti lgeti;
postcondition: result has the same length as l
static List mapList l Function f
walk through the Us
use f at every stage fapply
construct list of Vs
ArrayList l new ArrayList;
for U x: l
laddfapplyx;
return l;
static List flatmapList l Function f
walk through the Us
use f at every stage fapply
construct list of Vs
ArrayList res new ArrayList;
for U x: l
List l fapplyx;
for V y: l
res.addy;
return res;
foldleftxy xy
U V Integer
fpldleftxy xy
static V foldLeftV e Iterablel, BiFunction f
walk through the Us uuun
e
use f at every stage v fapplyeu
v fapplyvu
v fapplyvu
return the last v
V v e;
for U x: l
v fapplyvx;
return v;
similar to above
but from the right
vn fune
vn funvn
return the first v
static V foldRightV e Listl, BiFunction f
walk through the Us uuun
e
use f at every stage v fapplyue
v fapplyuv
v fapplyuv
return the last v
V v e;
for int i lsize; i ; i
v fapplylgetiv;
return v;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
