Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 뷰 상태복구
- android clean architecture
- 뷰 상태 저장
- 대학톡
- recyclerview
- 특가게시판
- List
- kotlin
- 작성
- todofication
- 카드 내역 공유 앱
- 올인원타이머
- RX
- 특가촌
- fragment
- andorid
- RxJava
- Koin
- Quickly
- Android
- 특가알람
- compileKotlin FAILED
- 카드내역 공유
- onViewCreated
- moveToState
- nvidia-docker
- 안드로이드
- java.lang.OutOfMemoryError: Java heap space
- 안드로이드 클린 아키텍쳐
- 타이머앱
Archives
- Today
- Total
seoft
kotlin extension 응용 본문
기존에 if 로 널처리 혹은 특정 처리 후 코드를 이어갈라면 코드가 길어지고, 뎁스가 깊어지는 경우 도 있다.
다음 처럼 사용하면 더 간결하게, 직관적으로 사용할 수 있다.
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
// 정의 | |
fun String?.exist(completion: (String) -> Unit): String? { | |
return if (this.isNullOrBlank()) { | |
null | |
} else { | |
completion(this) | |
this | |
} | |
} | |
// 사용 | |
"this_is_string_or_null".exist { | |
println(it) | |
} |
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
// 정의 | |
fun <T> SingleEmitter<T>.live(): SingleEmitter<T>? { | |
return if (this.isDisposed) { | |
null | |
} else { | |
this | |
} | |
} | |
// 사용 | |
Single.create<Int> { emitter -> | |
emitter.live()?.onSuccess(123) | |
} |
'android' 카테고리의 다른 글
koin viewModel in activity, fragment (0) | 2020.03.21 |
---|---|
rxjava 이용한 다중 터치 방지하기 (0) | 2020.02.27 |
kotlin list 조합하여 immutable list 만들기 (0) | 2020.01.17 |
RecyclerView item이 아닌 RecyclerView 자체에 onClickListener 붙이기 (0) | 2020.01.12 |
부모 뷰의 onTouchListener가 발생하지 않을 때 해결법 (0) | 2020.01.07 |
Comments