Skip to content
This repository was archived by the owner on Feb 10, 2021. It is now read-only.

Commit 429e5e6

Browse files
committed
Complete the exercise CrazyLambdas.java
1 parent de0d56a commit 429e5e6

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

crazy-lambdas/src/main/java/com/bobocode/CrazyLambdas.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ public static Supplier<IntUnaryOperator> nMultiplyFunctionSupplier(int n) {
111111
* @return a thread supplier
112112
*/
113113
public static Supplier<Thread> runningThreadSupplier(Runnable runnable) {
114-
throw new UnsupportedOperationException("It's your job to implement this method"); // todo
114+
return () -> {
115+
Thread thread = new Thread(runnable);
116+
thread.start();
117+
return thread;
118+
};
115119
}
116120

117121
/**
@@ -120,12 +124,16 @@ public static Supplier<Thread> runningThreadSupplier(Runnable runnable) {
120124
* @return a runnable consumer
121125
*/
122126
public static Consumer<Runnable> newThreadRunnableConsumer() {
123-
throw new UnsupportedOperationException("It's your job to implement this method"); // todo
127+
return runnable -> new Thread(runnable).start();
124128
}
125129

126130

127131
public static Function<Runnable, Supplier<Thread>> runnableToThreadSupplierFunction() {
128-
throw new UnsupportedOperationException("It's your job to implement this method"); // todo
132+
return runnable -> () -> {
133+
Thread thread = new Thread(runnable);
134+
thread.start();
135+
return thread;
136+
};
129137
}
130138

131139
/**
@@ -138,7 +146,7 @@ public static Function<Runnable, Supplier<Thread>> runnableToThreadSupplierFunct
138146
* @return a binary function that receiver predicate and function and compose them to create a new function
139147
*/
140148
public static BiFunction<IntUnaryOperator, IntPredicate, IntUnaryOperator> functionToConditionalFunction() {
141-
throw new UnsupportedOperationException("It's your job to implement this method"); // todo
149+
return (intOperation, intPredicate) -> a -> intPredicate.test(a) ? intOperation.applyAsInt(a) : a;
142150
}
143151

144152
/**
@@ -147,7 +155,7 @@ public static BiFunction<IntUnaryOperator, IntPredicate, IntUnaryOperator> funct
147155
* @return a supplier instance
148156
*/
149157
public static Supplier<Supplier<Supplier<String>>> trickyWellDoneSupplier() {
150-
throw new UnsupportedOperationException("It's your job to implement this method"); // todo
158+
return () -> () -> () -> "WELL DONE!";
151159
}
152160
}
153161

0 commit comments

Comments
 (0)