'Kotlin' 태그의 글 목록 (2 Page) — SH's Devlog

Kotlin

Android/Kotlin(Java)

[Kotlin] Collections API - fold(), reduce()

안녕하세요. 오늘은 fold()와 reduce()에 대해 정리하겠습니다. 1. fold() fold() 함수의 구현 public inline fun IntArray.fold(initial: R, operation: (acc: R, Int) -> R): R { var accumulator = initial for (element in this) accumulator = operation(accumulator, element) return accumulator } fold()함수는 내부 요소들을 모두 돌아가며 operation을 수행한 결과를 반환합니다. reduce()와의 차이점은 초기값을 설정할 수 있고, emptyList여도 Exception을 던지지 않습니다. import org.assertj.cor..

반응형
seunghwaan
'Kotlin' 태그의 글 목록 (2 Page)