Skip to content

Instantly share code, notes, and snippets.

@omidp
Created July 29, 2024 19:32
Show Gist options
  • Save omidp/20bd72f2888bd0ac1e19b3442df6fec7 to your computer and use it in GitHub Desktop.
Save omidp/20bd72f2888bd0ac1e19b3442df6fec7 to your computer and use it in GitHub Desktop.
Java chain result functional way
public static void main(String[] args){
int i = ((ThenResult<String>) ()-> "1")
.then(s->Integer.parseInt(s))
.result()
}
public interface ThenResult<T> {
T result();
default <U> ThenResult<U> then(Function<T, U> mapper) {
return () -> mapper.apply(ThenResult.this.result());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment