Implement flatMap method of JavaScript Future.

Similar to map but it takes function that returns future and the result
is the future returned by the function.
Implement transform method of JavaScript Future.

Create new future. This method takes two function, the first function is
applied when the current future is successful and the second function is
applied when the current future is failed.