Kotlin/collection functional api - search, sort, aggregate type api#20
Merged
Kotlin/collection functional api - search, sort, aggregate type api#20
Conversation
map, flatMap, associate methods
associateTo, associateWithTo, associateByTo
remove flattening test in MappingTest.kt
…in List and Map structures
…larations for type clarity
first, find, firstOrNull, last, findLast, lastOrNull, indexOf, all, any, none method
lastIndexOf, indexOfFirst, indexOfLast
sorted, sortedDescending, sortedBy, sortedByDescending, reversed
compareBy, thenBy, thenByDescending, naturalOrder, reverseOrder 추가
sort, sortDescending, sortBy, sortWith, reverse
toSortedMap
count, sum, sumOf, average, max, maxOfOrNull, reduce, fold, runningReduce, runningFold
There was a problem hiding this comment.
Pull Request Overview
This PR adds a comprehensive suite of tests to demonstrate and validate the Kotlin collection functional API for aggregation, sorting, searching, mapping, flattening, and filtering.
- Introduces new test cases covering various Kotlin collection operations and their edge cases.
- Provides practical examples to reinforce functional programming principles using immutable collections and accumulator functions.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| SortingTest.kt | Added test cases for list sorting using various comparator strategies including stable sorts. |
| SearchingTest.kt | Introduced tests for list searching and index-based operations with proper null handling. |
| MappingTest.kt | Provided tests for transforming collections and associating list elements with keys/values. |
| FlatteningTest.kt | Added tests demonstrating the flattening of nested lists and maps. |
| FilteringTest.kt | Introduced various filtering tests for lists and maps using different predicate strategies. |
| AggregationTest.kt | Added tests for aggregation functions such as count, sum, reduce, fold, runningReduce, and runningFold. |
| val words: List<String> = listOf("a", "b", "c") | ||
|
|
||
| val runningWordsFolded: List<String> = words.runningFold("Start: ") { acc, word -> acc + word } | ||
| runningWordsFolded shouldBe listOf("Start: a", "Start: ab", "Start: abc") |
There was a problem hiding this comment.
runningFold includes the initial value in its result; update the expected output to include the initial value, for example: listOf("Start: ", "Start: a", "Start: ab", "Start: abc").
Suggested change
| runningWordsFolded shouldBe listOf("Start: a", "Start: ab", "Start: abc") | |
| runningWordsFolded shouldBe listOf("Start: ", "Start: a", "Start: ab", "Start: abc") |
| emptyList<User>().maxOfOrNull(User::age) shouldBe null | ||
| } | ||
|
|
||
| "maxOfOrNull - 특정 속성 기준으로 컬렉션에서 가장 작은 요소 (없으면 null)" { |
There was a problem hiding this comment.
The test description mentions maxOfOrNull but the test actually uses minOfOrNull; update the description to 'minOfOrNull - 특정 속성 기준으로 컬렉션에서 가장 작은 요소 (없으면 null)'.
Suggested change
| "maxOfOrNull - 특정 속성 기준으로 컬렉션에서 가장 작은 요소 (없으면 null)" { | |
| "minOfOrNull - 특정 속성 기준으로 컬렉션에서 가장 작은 요소 (없으면 null)" { |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎉 Kotlin 컬렉션 함수형 API 학습 테스트 (Aggregation, Sorting, Searching) 추가
💡 함수형 API 학습 목표
Kotlin 컬렉션 함수형 API의 다양한 활용법을 배우고 숙달하여, 보다 간결하고 가독성 높은 코드를 작성하는 능력 향상
컬렉션 데이터를 효과적으로 집계, 정렬, 탐색하는 패턴 이해 및 적용
불변성 유지, 부수 효과 최소화 등 함수형 프로그래밍의 원칙을 실제 코드에 반영
✨ 작업 내용 요약
Kotlin 컬렉션의 데이터를 집계(Aggregation), 정렬(Sorting), 탐색(Searching)하는 함수들의 사용법을 학습하기 위한 테스트 코드를 추가했습니다. 각 함수가 어떤 상황에서 유용하게 사용될 수 있는지 다양한 케이스를 통해 검증합니다.
주요 컬렉션 대상: List, Map
파일별 작업 요약:
✅ AggregationTest.kt
count,sum,sumOf,average등 기본적인 집계 함수 테스트max,min,maxOf,minOfmaxOrNull,minOrNull등 최대/최소값 탐색 함수 테스트 보강reduce,fold,runningReduce,runningFold와 같은 누적 연산 함수 테스트✅ SortingTest.kt
sorted,sortedDescending등 기본 정렬 함수 테스트sortedBy,sortedByDescending등 특정 속성 기준 정렬 함수 테스트sortedWith와 다양한Comparator(compareBy, thenBy 등)를 활용한 복합 정렬 테스트 추가toList().sorted...패턴 활용) 테스트✅ SearchingTest.kt
first,find,last,findLast등 요소 탐색 함수 테스트all,any,none등 조건 만족 여부 확인 함수 테스트indexOf,lastIndexOf,indexOfFirst,indexOfLast등 인덱스 탐색 함수 테스트 및takeIf를 활용하여-1대신null처리하는 패턴 학습firstNotNullOf,firstNotNullOfOrNull등 null이 아닌 첫 값 탐색 함수 테스트