private fun Sequence<Event>.allEventsInSameInteractions() =
flatMap { event ->
eventStore.queryAsSequence(
“interactionId=${event.interactionId}”
)
}
}
inline fun <T> Collection<T>.averageBy(selector: (T) -> Int): Double =
sumBy(selector) / size.toDouble()
fun EventStore.queryAsSequence(query: String) =
this.queryAsStream(query).asSequence()
지나가는 말로,
allEventsInSameInteractions
는
10
장에서 설명한 확장 함수인 메서
드에 속한다. 그래서
allEventsInSameInteractions
는 (
eventStore
에 접근할 때)
MarketingAnalytics
와
Sequence
<
Event
>
를
this
로 접근할 수 있다.
13.8
다음으로 나아가기
이 예제에서 리팩터링한 코틀린 코드가 아름답다고 ...
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.