aleksandarskrbic / async-assignment

For educational purposes, or for interviewing Java / Scala developers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Async Assignment (in Java)

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 😎

  1. see Async and Main
  2. read the source code already in place
  3. implement the functions marked with throw UnsupportedOperationException
  4. make sure the tests are passing, see AsyncTest

To run the provided test suite:

$ mvn test

NOTE: the build tool used is Apache Maven.

Details

The described Async data type resembles Java's CompletableFuture, except that it behaves like a function instead of a variable. In other words, it does not do memoization, being a more "pure" abstraction (in the Functional Programming sense).

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);
});

About

For educational purposes, or for interviewing Java / Scala developers.


Languages

Language:Java 100.0%