/**
* Assign the given {@link Function} to transform the incoming value {@code T} into a {@code V} and pass it into
* another {@code Composable}.
*
* @param fn
* the transformation function
* @param <V>
* the type of the return value of the transformation function
*
* @return a new {@code Composable} containing the transformed values
*/
public <V> Composable<V> map(@Nonnull final Function<T, V> fn) {
Assert.notNull(fn, "Map function cannot be null.");
final Deferred<V, ? extends Composable<V>> d = createDeferred();
consumeEvent(new Consumer<Event<T>>() {
@Override
public void accept(Event<T> value) {
try {
V val = fn.apply(value.getData());
d.acceptEvent(value.copy(val));
} catch (Throwable e) {
d.accept(e);
}
}
});
return d.compose();
}