private val _lines = mutableListOf<CurrencyConversion>()
var total: Money = Money.of(0, userCurrency)
private set
val lines: List<CurrencyConversion>
get() = _lines.toList()
fun addLine(line: CurrencyConversion) {
_lines.add(line)
total += line.toMoney
}
}
이제는 계산이
summarise
에서 한 식 안에 들어있다.
예제
14.20
[
accumulator
.
9
:
src
/
main
/
java
/
travelator
/
itinerary
/
CostSummaryCalculator
.
kt
]
val total = lines
.map { it.toMoney }
.fold(Money.of(0, userCurrency), Money::add)
14.3
한 번 더 해 보자
이와 비슷하게 통화와 관련된 처리가 모두
CostSummaryCalculator ...
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.