Chain of Map method references

Nope, these are the two ways of doing it. Anything else would end up being only less clear.

But, since you asked, here are some options.

static<T,U,R> Function<T,R> chain(
        Function<? super T, ? extends U> f1,
        Function<? super U, ? extends R> f2) {
    return t -> f2.apply(f1.apply(t));
}

stream.map(chain(Status::getUser, User::getId))

Or

static<T,R> Function<T,R> func(Function<T,R> f) {
    return f;
}

stream.map(func(Status::getUser).andThen(User::getId))

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)