Skip to content

Kotlin/collection functional api - map, filter, flatten type api#19

Merged
sh1mj1 merged 14 commits intodevfrom
kotlin/collection-functional-api
Apr 18, 2025
Merged

Kotlin/collection functional api - map, filter, flatten type api#19
sh1mj1 merged 14 commits intodevfrom
kotlin/collection-functional-api

Conversation

@sh1mj1
Copy link
Owner

@sh1mj1 sh1mj1 commented Apr 17, 2025

💡 함수형 API의 장점

  • 코드의 간결함과 가독성을 높이고, 컬렉션 처리 흐름을 선언적으로 표현할 수 있음
  • 컬렉션의 불변성 유지, 부수 효과 최소화, 체이닝 처리의 유연함 등 함수형 프로그래밍의 장점을 활용하여 실수나 버그 가능성을 줄임

작업한 내용 요약

  • Kotlin의 컬렉션 함수(map/filter/flatMap/flatten/associate 등) 사용법을 학습하기 위한 테스트 작성
  • 주요 컬렉션: List, Map
  • 각 메서드의 변형 함수들(mapTo, flatMapTo, associateTo, filterKeys, filterValues 등)을 다양한 케이스로 검증

파일별 작업 요약

  • MappingTest.kt: map, mapIndexed, mapNotNullmapTo, flatMapTo, associateTo 등 가변 리스트 대상의 매핑 테스트
  • FilteringTest.kt: Map에 대한 filter, filterKeys, filterValues 테스트 추가
  • FlatteningTest.kt: 중첩 리스트 및 맵에 대한 flatten, flatMap 테스트
  • 변수 선언 시 명확한 타입 지정을 통해 테스트 의도를 더 명확하게 리팩토링
  • ListFunctionalApiTest.kt 제거 (MappingTest 등으로 분리 통합)

@sh1mj1 sh1mj1 requested a review from Copilot April 17, 2025 13:53
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

app/src/test/java/com/example/learningtest/collection/functional/MappingTest.kt:35

  • [nitpick] Consider using a more declarative conditional expression (for example, a when or an if-else expression) in the lambda instead of an early return to improve readability in this test.
if (index == 0) return@mapIndexedNotNull null

app/src/test/java/com/example/learningtest/collection/functional/FlatteningTest.kt:183

  • The test uses an empty map, which makes both the toList() and flatMap() results empty. Consider adding a non-empty map test case to validate that the flattening behavior preserves the key-value relationship as expected.
Map<String, String>.toList().flatten 은 단순 Key-Value Pair 리스트로 변환

@sh1mj1 sh1mj1 merged commit 28e0ba5 into dev Apr 18, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants