Skip to content

Commit

Permalink
Merge pull request #45 from http4s/flake
Browse files Browse the repository at this point in the history
Adopt common scalafmt rules and add flake
  • Loading branch information
cquiroz authored Nov 30, 2024
2 parents 6c6835a + 6d9c030 commit ed34b90
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use flake
layout node
eval "$shellHook"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ metals.sbt

# npm
node_modules/
.direnv/
6 changes: 6 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ rewrite.sortModifiers.order = [

rewrite.trailingCommas.style = multiple

project.excludeFilters = [
"scalafix/*",
"scalafix-internal/input/*",
"scalafix-internal/output/*"
]

runner.dialect = scala212

fileOverride {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import java.nio.ByteBuffer
import scala.util.Failure
import scala.util.Success

/** Generic factories for http4s encoders/decoders for boopickle
* Note that the media type is set for application/octet-stream
/** Generic factories for http4s encoders/decoders for boopickle Note that the media type is set
* for application/octet-stream
*/
trait BooPickleInstances {
private def booDecoderByteBuffer[F[_]: Concurrent, A](
Expand All @@ -57,8 +57,6 @@ trait BooPickleInstances {
*/
def booEncoderOf[F[_], A: Pickler]: EntityEncoder[F, A] =
chunkEncoder[F]
.contramap[A] { v =>
Chunk.ByteBuffer(Pickle.intoBytes(v))
}
.contramap[A](v => Chunk.ByteBuffer(Pickle.intoBytes(v)))
.withContentType(`Content-Type`(MediaType.application.`octet-stream`))
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ class BoopickleSuite extends CatsEffectSuite with ScalaCheckSuite {
}

implicit val fruitPickler: Pickler[Fruit] =
compositePickler[Fruit].addConcreteType[Banana].addConcreteType[Kiwi].addConcreteType[Carambola]
compositePickler[Fruit]
.addConcreteType[Banana]
.addConcreteType[Kiwi]
.addConcreteType[Carambola]

implicit val encoder: EntityEncoder[IO, Fruit] = booEncoderOf[IO, Fruit]
implicit val decoder: EntityDecoder[IO, Fruit] = booOf[IO, Fruit]
Expand Down Expand Up @@ -91,8 +94,8 @@ class BoopickleSuite extends CatsEffectSuite with ScalaCheckSuite {
}

test("decode a class from a boopickle decoder") {
val result = booOf[IO, Fruit]
.decode(Request[IO]().withEntity(Banana(10.0): Fruit), strict = true)
val result =
booOf[IO, Fruit].decode(Request[IO]().withEntity(Banana(10.0): Fruit), strict = true)
result.value.map(assertEquals(_, Right(Banana(10.0))))
}

Expand Down
120 changes: 120 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
inputs = {
typelevel-nix.url = "github:typelevel/typelevel-nix";
nixpkgs.follows = "typelevel-nix/nixpkgs";
flake-utils.follows = "typelevel-nix/flake-utils";
};

outputs = { self, nixpkgs, flake-utils, typelevel-nix }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ typelevel-nix.overlay ];
};
in
{
devShell = pkgs.devshell.mkShell {
imports = [ typelevel-nix.typelevelShell ];
name = "http4s-boopickle";
typelevelShell = {
jdk.package = pkgs.jdk17;
nodejs.enable = true;
nodejs.package = pkgs.nodejs;
};
};
}
);
}

0 comments on commit ed34b90

Please sign in to comment.