Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Kamil Podsiadło <[email protected]>
  • Loading branch information
dos65 and kpodsiad authored Mar 9, 2022
1 parent 7cc949d commit eacab93
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions tests/mtest/src/main/scala/tests/Compat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ object Compat {

/**
* Cases might be described as:
* - Starts swith: "3.0.1" -> value | "3.0" -> value | "3"
* - Starts with: "3.0.1" -> value OR "3.0" -> value OR "3" -> value
* - Greater or equal: ">=3.0.0" -> value
*/
def forScalaVersion[A](
scalaVersion: String,
cases: Map[String, A]
): Option[A] = {
val (startsWith, gt) =
cases.partition({ case (v, _) => !v.startsWith(">=") })
cases.partition { case (v, _) => !v.startsWith(">=") }

val fromStartWith = startsWith.collectFirst({
val fromStartWith = startsWith.collectFirst {
case (v, a) if scalaVersion.startsWith(v) => a
})
matchesGte(scalaVersion, gt) orElse fromStartWith
}

matchesGte(scalaVersion, gt).orElse(fromStartWith)
}

private def matchesGte[A](
Expand Down

0 comments on commit eacab93

Please sign in to comment.