Skip to Content
자바에서 코틀린으로
book

자바에서 코틀린으로

by 덩컨 맥그레거, 냇 프라이스, 오현석
November 2022
Beginner to intermediate
544 pages
12h 39m
Korean
Hanbit Media, Inc.
Content preview from 자바에서 코틀린으로
290
자바에서 코틀린으로
실과 로직을 안전하게 그와 동등한 형태로 리팩터링한다는 사실을 알 수 있다.
동등한 형태는 무엇일까? 우리는 이에 대해 생각해봐야만 한다. 하지만
MutableMap
.
merge
가 통화별로 합계를 계산한다는 결론에 이른다. 일단 모든 데이터를 모으고 나면, 지금 우리 코
드가 하는 것처럼 통화별로 그룹을 나누고 각 그룹에 속한 리스트의 합계를 구함으로써 똑같은
계산을 수행할 수 있다.
예제
14.27
[
accumulator
.
14
:
src
/
main
/
java
/
travelator
/
itinerary
/
CostSummaryCalculator
.
kt
]
class CostSummaryCalculator(
private val userCurrency: Currency,
private val exchangeRates: ExchangeRates
) {
fun summarise(costs: Iterable<Money>): CostSummary {
val currencyTotals: List<Money> = costs
.groupBy { it.currency }
.values
.map { moneys -> moneys.reduce(Money::add) }
val lines: List<CurrencyConversion> = currencyTotals ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

고성능 파이썬(2판)

고성능 파이썬(2판)

오현석, 미샤 고렐릭, 이안 오스발트
러닝 타입스크립트

러닝 타입스크립트

조시 골드버그
실리콘밸리 리더십

실리콘밸리 리더십

김정혜, 마이클 롭

Publisher Resources

ISBN: 9791169210447