The assignment is about finishing the implementation of the described Async
data type — for educational purposes, or for interviewing.
This assignment has been used (with mixed results) for spotting Java developers that could make the transition to Scala and Functional Programming 😎
- see Async and Main
- read the source code already in place
- implement the functions marked with
throw UnsupportedOperationException
- make sure the tests are passing, see AsyncTest
To run the provided test suite:
$ mvn test
NOTE: the build tool used is Apache Maven.
The described Async
data type resembles Java's
CompletableFuture,
except that it behaves like a function instead of a variable.
Quick usage sample:
import org.alexn.async.Async;
import java.util.Random;
import java.util.concurrent.*;
Async<Integer> number = Async.eval(
() -> {
Random rnd = new Random(System.currentTimeMillis());
return rnd.nextInt();
});
// Needed for executing tasks
Executor ec = Executors.newCachedThreadPool();
// Actual execution, happens on another thread ;-)
number.run(ec, value -> {
System.out.println("Generated random number: " + value);
});