8000 collections.11 : Refactor bearable · java-to-kotlin/code@a753fb8 · GitHub
[go: up one dir, main page]

Skip to content

Commit a753fb8

Browse files
Duncan McGregordmcg
authored andcommitted
collections.11 : Refactor bearable
1 parent a9cc497 commit a753fb8

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

src/main/java/travelator/Suffering.kt

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,28 @@
11
package travelator
22

33
import travelator.Other.SOME_COMPLICATED_RESULT
4-
import java.util.stream.Collectors
4+
import travelator.Other.routesFor
55

66
object Suffering {
77
@JvmStatic
8-
fun sufferScoreFor(route: List<Journey>): Int {
9-
return sufferScore(
10-
route.longestJourneys(limit = 3), // <1>
8+
fun sufferScoreFor(route: List<Journey>): Int =
9+
sufferScore(
10+
route.longestJourneys(limit = 3),
1111
Routes.getDepartsFrom(route)
1212
)
13-
}
1413

1514
@JvmStatic
1615
fun List<Journey>.longestJourneys(limit: Int): List<Journey> =
1716
sortedByDescending { it.duration }.take(limit)
1817

19-
fun routesToShowFor(itineraryId: String?): List<List<Journey>> {
20-
return bearable(Other.routesFor(itineraryId))
21-
}
18+
fun routesToShowFor(itineraryId: String?): List<List<Journey>> =
19+
bearable(routesFor(itineraryId))
2220

23-
private fun bearable(routes: List<List<Journey>>): List<List<Journey>> {
24-
return routes.stream()
25-
.filter { route -> sufferScoreFor(route) <= 10 }
26-
.collect(Collectors.toUnmodifiableList())
27-
}
21+
private fun bearable(routes: List<List<Journey>>): List<List<Journey>> =
22+
routes.filter { sufferScoreFor(it) <= 10 }
2823

2924
private fun sufferScore(
3025
longestJourneys: List<Journey>,
3126
start: Location
32-
): Int {
33-
return SOME_COMPLICATED_RESULT()
34-
}
27+
): Int = SOME_COMPLICATED_RESULT()
3528
}

0 commit comments

Comments
 (0)

Footer

© 2025 GitHub, Inc.
0