Created
July 29, 2024 19:32
-
-
Save omidp/20bd72f2888bd0ac1e19b3442df6fec7 to your computer and use it in GitHub Desktop.
Java chain result functional way
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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