fun withTransformedRoute(transform: (Route).() -> Route) =
copy(route = transform(route))
...
}
결과적으로, 변환한
Route
를 새로 만드는 것과 거의 비슷한 정도로 쉽게 변환된
Itinenary
를
만들 수 있다.
예제
15.38
[
encapsulated
-
collections
.
15
:
src
/
main
/
java
/
travelator
/
itinerary
/
itineraries
.
kt
]
fun Itinerary.withoutJourneysBy(travelMethod: TravelMethod) =
withTransformedRoute {
filterNot { it.method == travelMethod }
}
fun Itinerary.withoutLastJourney() =
withTransformedRoute { dropLast(1) }
15.4
다음으로 ...
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.