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
                                        
                                    
                                        
                                    - Sqoop
 - Java
 - JavaScript
 - SSL
 - es6
 - SQL
 - MSSQL
 - xPlatform
 - react
 - Eclipse
 - 공정능력
 - Android
 - Python
 - table
 - mapreduce
 - window
 - Spring
 - Kotlin
 - tomcat
 - vaadin
 - mybatis
 - plugin
 - GIT
 - SPC
 - R
 - IntelliJ
 - NPM
 - 보조정렬
 - Express
 - hadoop
 
                                        Archives
                                        
                                    
                                        
                                    - Today
 
- Total
 
DBILITY
kotlin reduce, fold 본문
반응형
    
    
    
  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
}
반응형
    
    
    
  '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
                        
                    
                
            
                
            
				
				
				
				
                
							