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
- JavaScript
- Express
- 공정능력
- mapreduce
- R
- xPlatform
- 보조정렬
- IntelliJ
- hadoop
- window
- SPC
- es6
- SQL
- GIT
- mybatis
- plugin
- MSSQL
- vaadin
- tomcat
- Kotlin
- Spring
- Java
- Python
- SSL
- Sqoop
- Eclipse
- table
- NPM
- Android
- react
Archives
- Today
- Total
DBILITY
kotlin reduce, fold 본문
728x90
반응형
empty colletion일때 reduce는 오류가 발생한다.
java.lang.UnsupportedOperationException: Empty collection can't be reduced.
가능성이 있을때는 fold를 사용해도 되나?^^
data class Todo(val id: Int, val content: String, val datetime: Long)
...
private val initDataList = mutableListOf<Todo>()
/*val maxId = fold(Todo(0, String(), 0L)) { acc, todo ->
if (acc.id.compareTo(todo.id) == 1) acc else todo
}.id + 1*/
var maxId = 1
if (size>1) {
maxId = reduce { acc, todo ->
if (acc.id.compareTo(todo.id) == 1) acc else todo
}.id + 1
}
728x90
'android > kotlin' 카테고리의 다른 글
안드로이드 recyclerView scroll (0) | 2024.03.11 |
---|---|
안드로이드 RecyclerView 기초 사용법 ( viewMoldel update 적용 ) (0) | 2024.03.11 |
안드로이드 RecyclerView 기초 사용법 ( viewMoldel 적용 ) (0) | 2024.03.07 |
안드로이드 RecyclerView 기초 사용법 (0) | 2024.03.05 |
안드로이드 spinner(combo) 사용법 (0) | 2024.03.04 |
Comments