Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add map and mapO methods to extractors #13

Merged
merged 2 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ lazy val http4s = http4sProj(projectMatrix.in(file("http4s")), "http4s")(axis =>
)
))
.settings(publishSettings)
.settings(scalacOptions ~= (_.filterNot(_ == "-Xfatal-warnings")))
.settings(scalacOptions ~= (_.filterNot(_ == "-Wunused:nowarn")))
.dependsOn(core % "compile->compile;test->test")

lazy val play = playProj(projectMatrix.in(file("play")), "play")(axis => _ => _.settings(
Expand Down
18 changes: 16 additions & 2 deletions core/src/main/scala/routing/extractor/PathExtractor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,26 @@ package extractor
import java.util.UUID
import scala.util.Try

trait PathExtractor[A] {
trait PathExtractor[A] { self =>
def extract(path: String): Option[A]

final def mapO[B](f: A => Option[B]): PathExtractor[B] =
new PathExtractor[B] {
def extract(path: String): Option[B] = self.extract(path).flatMap(f)
}

final def map[B](f: A => B): PathExtractor[B] = mapO(a => Some(f(a)))
}

trait RestOfPathExtractor[A] {
trait RestOfPathExtractor[A] { self =>
def extract(path: String): Option[A]

final def mapO[B](f: A => Option[B]): RestOfPathExtractor[B] =
new RestOfPathExtractor[B] {
def extract(path: String): Option[B] = self.extract(path).flatMap(f)
}

final def map[B](f: A => B): RestOfPathExtractor[B] = mapO(a => Some(f(a)))
}

object PathExtractor {
Expand Down
9 changes: 8 additions & 1 deletion core/src/main/scala/routing/extractor/QueryExtractor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ import java.util.UUID
import scala.annotation.tailrec
import scala.util.Try

trait QueryExtractor[A] {
trait QueryExtractor[A] { self =>
def extract(key: String, query: QueryMap): Option[A]

final def mapO[B](f: A => Option[B]): QueryExtractor[B] =
new QueryExtractor[B] {
def extract(key: String, query: QueryMap): Option[B] = self.extract(key, query).flatMap(f)
}

final def map[B](f: A => B): QueryExtractor[B] = mapO(a => Some(f(a)))
}

object QueryExtractor {
Expand Down
8 changes: 4 additions & 4 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import sbtprojectmatrix.ProjectMatrixPlugin.autoImport._
import scala.sys.process._

object Build {
lazy val scalaVersions = Seq("2.13.15", "3.3.4")
lazy val scalaVersions = Seq("2.13.16", "3.3.5")
lazy val latestScalaV = scalaVersions.find(_.startsWith("3.")).get
lazy val kindProjector = compilerPlugin("org.typelevel" % "kind-projector" % "0.13.3" cross CrossVersion.full)

Expand Down Expand Up @@ -266,8 +266,8 @@ object Build {
.getOrElse(Seq())
)

val catsCore = Def.setting("org.typelevel" %%% "cats-core" % "2.12.0")
val izumiReflect = Def.setting("dev.zio" %%% "izumi-reflect" % "2.3.10")
val catsCore = Def.setting("org.typelevel" %%% "cats-core" % "2.13.0")
val izumiReflect = Def.setting("dev.zio" %%% "izumi-reflect" % "3.0.1")
val http4sV1Milestone = "1.0.0-M"

object Http4sAxis extends Enumeration {
Expand Down Expand Up @@ -312,6 +312,6 @@ object Build {

def isHttp4sV1Milestone(version: String): Boolean = version.startsWith(http4sV1Milestone)

def circeDep(proj: String) = Def.setting("io.circe" %%% s"circe-$proj" % "0.14.6")
def circeDep(proj: String) = Def.setting("io.circe" %%% s"circe-$proj" % "0.14.10")
def http4sDep(proj: String, version: String) = Def.setting("org.http4s" %%% s"http4s-$proj" % version)
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.10.6
sbt.version=1.10.7
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % "0.10.1")
addSbtPlugin("com.github.sbt" % "sbt-github-actions" % "0.24.0")
addSbtPlugin("io.spray" % "sbt-revolver" % "0.10.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.17.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.18.2")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.5.6")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.6.1" )
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.6.3" )
addSbtPlugin("org.typelevel" % "sbt-tpolecat" % "0.5.2")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.7")

Expand Down