https://www.google.com/search?q=暴鯉龍
https://www.google.com/search?q=皮卡丘
https://www.google.com/search?q=夢幻
brew analytics off| public class OptSample { | |
| public void demoOpt() { | |
| String requestBody = sendPost(); | |
| // 頭部 | |
| // of -> 確定不為 Null 的值 | |
| // ofNullable -> 可能為 Null 的值 | |
| Optional.of(requestBody).orElse("Empty Body"); | |
| Optional.ofNullable(requestBody).orElse("Empty Body"); |
| fun <T> T?.catchErrWhenNull(tw: Throwable): Either<Throwable, T> = Either.Companion.catch { this ?: throw tw } | |
| fun <T> Either<Throwable, T?>.flattenCatchErrWhenNull(tw: Throwable): Either<Throwable, T> = | |
| when (this) { | |
| is Either.Left -> this | |
| is Either.Right -> Either.Companion.catch { | |
| this.value ?: throw tw | |
| } | |
| } |
| // _oo0oo_ | |
| // o8888888o | |
| // 88" . "88 | |
| // (| -_- |) | |
| // 0\ = /0 | |
| // ___/`---'\___ | |
| // .' \\| |// '. | |
| // / \\||| : |||// \ | |
| // / _||||| -:- |||||- \ | |
| // | | \\\ - /// | | |