Created
September 4, 2019 15:01
-
-
Save NikichXP/db0c55f57a972aaaaa36d8ec95c7ed1c to your computer and use it in GitHub Desktop.
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
import java.util.*; | |
import java.util.function.*; | |
class OptionalHelper<A> { | |
private List<Supplier<A>> suppliers = new LinkedList<>(); | |
private OptionalHelper() {} | |
public static <A> OptionalHelper<A> of(Supplier<A> supplier) { | |
val helper = new OptionalHelper<A>(); | |
helper.suppliers.add(supplier); | |
return helper; | |
} | |
public OptionalHelper<A> orElse(Supplier<A> supplier) { | |
suppliers.add(supplier); | |
return this; | |
} | |
public A get() { | |
for (val supplier : suppliers) { | |
val result = supplier.get(); | |
if (result != null) { | |
return result; | |
} | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment