Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/0.23-scala3' into merge-0.23-to-…
Browse files Browse the repository at this point in the history
…0.23-scala3
  • Loading branch information
froth committed Jul 25, 2024
2 parents 0efc364 + 75786aa commit 3abffb1
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 259 deletions.

This file was deleted.

8 changes: 1 addition & 7 deletions src/main/g8/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,16 @@ lazy val root = (project in file("."))
organization := "$organization$",
name := "$name;format="norm"$",
version := "0.0.1-SNAPSHOT",
scalaVersion := "$scala_version$",
scalaVersion := "3.3.3",
libraryDependencies ++= Seq(
"org.http4s" %% "http4s-ember-server" % Http4sVersion,
"org.http4s" %% "http4s-ember-client" % Http4sVersion,
"org.http4s" %% "http4s-circe" % Http4sVersion,
"org.http4s" %% "http4s-dsl" % Http4sVersion,
"io.circe" %% "circe-generic" % CirceVersion,
"org.scalameta" %% "munit" % MunitVersion % Test,
"org.typelevel" %% "munit-cats-effect" % MunitCatsEffectVersion % Test,
"ch.qos.logback" % "logback-classic" % LogbackVersion % Runtime,
$if(graal_native_image.truthy)$
"org.scalameta" % "svm-subs" % "101.0.0"
$endif$
),
addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.13.3" cross CrossVersion.full),
addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"),
assembly / assemblyMergeStrategy := {
case "module-info.class" => MergeStrategy.discard
case x => (assembly / assemblyMergeStrategy).value.apply(x)
Expand Down
6 changes: 0 additions & 6 deletions src/main/g8/default.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
name = quickstart
organization = com.example
package = $organization$.$name;format="norm,word"$

scala_version = 2.13.14
# graal_vm_specific
graal_native_image = true
is_linux_build = false
scala_assembly_target = scala-2.13

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
package $package$

import cats.effect.Sync
import cats.implicits._
import cats.syntax.all.*
import org.http4s.HttpRoutes
import org.http4s.dsl.Http4sDsl

object $name;format="Camel"$Routes {
object $name;format="Camel"$Routes:

def jokeRoutes[F[_]: Sync](J: Jokes[F]): HttpRoutes[F] = {
def jokeRoutes[F[_]: Sync](J: Jokes[F]): HttpRoutes[F] =
val dsl = new Http4sDsl[F]{}
import dsl._
import dsl.*
HttpRoutes.of[F] {
case GET -> Root / "joke" =>
for {
joke <- J.get
resp <- Ok(joke)
} yield resp
}
}

def helloWorldRoutes[F[_]: Sync](H: HelloWorld[F]): HttpRoutes[F] = {
def helloWorldRoutes[F[_]: Sync](H: HelloWorld[F]): HttpRoutes[F] =
val dsl = new Http4sDsl[F]{}
import dsl._
import dsl.*
HttpRoutes.of[F] {
case GET -> Root / "hello" / name =>
for {
greeting <- H.hello(HelloWorld.Name(name))
resp <- Ok(greeting)
} yield resp
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package $package$

import cats.effect.Async
import cats.syntax.all._
import com.comcast.ip4s._
import cats.syntax.all.*
import com.comcast.ip4s.*
import fs2.io.net.Network
import org.http4s.ember.client.EmberClientBuilder
import org.http4s.ember.server.EmberServerBuilder
import org.http4s.implicits._
import org.http4s.implicits.*
import org.http4s.server.middleware.Logger

object $name;format="Camel"$Server {
object $name;format="Camel"$Server:

def run[F[_]: Async: Network]: F[Nothing] = {
for {
Expand Down Expand Up @@ -37,4 +37,3 @@ object $name;format="Camel"$Server {
.build
} yield ()
}.useForever
}
22 changes: 9 additions & 13 deletions src/main/g8/src/main/scala/$package__packaged$/HelloWorld.scala
Original file line number Diff line number Diff line change
@@ -1,35 +1,31 @@
package $package$

import cats.Applicative
import cats.implicits._
import cats.syntax.all.*
import io.circe.{Encoder, Json}
import org.http4s.EntityEncoder
import org.http4s.circe._
import org.http4s.circe.*

trait HelloWorld[F[_]]{
trait HelloWorld[F[_]]:
def hello(n: HelloWorld.Name): F[HelloWorld.Greeting]
}

object HelloWorld {
object HelloWorld:
final case class Name(name: String) extends AnyVal
/**
* More generally you will want to decouple your edge representations from
* your internal data structures, however this shows how you can
* create encoders for your data.
**/
final case class Greeting(greeting: String) extends AnyVal
object Greeting {
implicit val greetingEncoder: Encoder[Greeting] = new Encoder[Greeting] {
object Greeting:
given Encoder[Greeting] = new Encoder[Greeting]:
final def apply(a: Greeting): Json = Json.obj(
("message", Json.fromString(a.greeting)),
)
}
implicit def greetingEntityEncoder[F[_]]: EntityEncoder[F, Greeting] =

given [F[_]]: EntityEncoder[F, Greeting] =
jsonEncoderOf[F, Greeting]
}

def impl[F[_]: Applicative]: HelloWorld[F] = new HelloWorld[F]{
def impl[F[_]: Applicative]: HelloWorld[F] = new HelloWorld[F]:
def hello(n: HelloWorld.Name): F[HelloWorld.Greeting] =
Greeting("Hello, " + n.name).pure[F]
}
}
42 changes: 17 additions & 25 deletions src/main/g8/src/main/scala/$package__packaged$/Jokes.scala
Original file line number Diff line number Diff line change
@@ -1,41 +1,33 @@
package $package$

import cats.effect.Concurrent
import cats.implicits._
import cats.syntax.all.*
import io.circe.{Encoder, Decoder}
import io.circe.generic.semiauto._
import org.http4s._
import org.http4s.implicits._
import org.http4s.*
import org.http4s.implicits.*
import org.http4s.client.Client
import org.http4s.client.dsl.Http4sClientDsl
import org.http4s.circe._
import org.http4s.Method._
import org.http4s.circe.*
import org.http4s.Method.*

trait Jokes[F[_]]{
trait Jokes[F[_]]:
def get: F[Jokes.Joke]
}

object Jokes {
def apply[F[_]](implicit ev: Jokes[F]): Jokes[F] = ev
object Jokes:
def apply[F[_]](using ev: Jokes[F]): Jokes[F] = ev

final case class Joke(joke: String) extends AnyVal
object Joke {
implicit val jokeDecoder: Decoder[Joke] = deriveDecoder[Joke]
implicit def jokeEntityDecoder[F[_]: Concurrent]: EntityDecoder[F, Joke] =
jsonOf
implicit val jokeEncoder: Encoder[Joke] = deriveEncoder[Joke]
implicit def jokeEntityEncoder[F[_]]: EntityEncoder[F, Joke] =
jsonEncoderOf
}
final case class Joke(joke: String)
object Joke:
given Decoder[Joke] = Decoder.derived[Joke]
given [F[_]: Concurrent]: EntityDecoder[F, Joke] = jsonOf
given Encoder[Joke] = Encoder.AsObject.derived[Joke]
given [F[_]]: EntityEncoder[F, Joke] = jsonEncoderOf

final case class JokeError(e: Throwable) extends RuntimeException

def impl[F[_]: Concurrent](C: Client[F]): Jokes[F] = new Jokes[F]{
def impl[F[_]: Concurrent](C: Client[F]): Jokes[F] = new Jokes[F]:
val dsl = new Http4sClientDsl[F]{}
import dsl._
def get: F[Jokes.Joke] = {
import dsl.*
def get: F[Jokes.Joke] =
C.expect[Joke](GET(uri"https://icanhazdadjoke.com/"))
.adaptError{ case t => JokeError(t)} // Prevent Client Json Decoding Failure Leaking
}
}
}
3 changes: 1 addition & 2 deletions src/main/g8/src/main/scala/$package__packaged$/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ package $package$

import cats.effect.{IO, IOApp}

object Main extends IOApp.Simple {
object Main extends IOApp.Simple:
val run = $name;format="Camel"$Server.run[IO]
}
Loading

0 comments on commit 3abffb1

Please sign in to comment.