Last active
January 17, 2018 16:44
-
-
Save pakoito/91c01237217483b7be509996b243cf28 to your computer and use it in GitHub Desktop.
Lightweight Option
This file contains 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
inline fun <A, B> A?.fold(crossinline fn: () -> B, crossinline f: (A) -> B): B = | |
if (this == null) fn() else f(this) | |
inline fun <A, B> A?.map(crossinline f: (A) -> B): B? = fold({ null }, f) | |
inline fun <A> A?.orElse(crossinline fn: () -> A): A = fold(fn, { it }) |
Author
pakoito
commented
Nov 16, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment