Skip to content

Instantly share code, notes, and snippets.

@Daenyth
Last active December 20, 2016 00:05
Show Gist options
  • Save Daenyth/ebffd62a49a8a7aad6763fedda9d2340 to your computer and use it in GitHub Desktop.
Save Daenyth/ebffd62a49a8a7aad6763fedda9d2340 to your computer and use it in GitHub Desktop.

Running HTTP

  • sbt run - Run the http service on localhost:8989.
  • sbt ~re-start - Run the http service as above, but whenever the code changes, recompile and relaunch the service.

Tests

<project specific env setup>

Once the environment is configured, run

  • sbt test:compile - Compile the tests without running them
  • sbt test - Run the tests once
  • sbt ~test - As above, but rerun the tests whenever the code changes
  • sbt ~test-quick - As above, but only run the tests affected by recompilation or tests which failed.

Libraries used

  • Scalaz - An extended standard library for common FP patterns and types.
  • http4s - http library (client and server)
  • doobie - database library
  • argonaut - json library
  • ScalaTest - For testing

I am confused by...

  • ConnectionIO[A] - A description of a query or set of queries that when run will return values of some type A
  • Task[A] - A description of a computation or async operation that when run will return values of type A
  • |@| - aka "tie fighter operator" - You can think of (a |@| b) { f } as "with all of these together, do f"

Example:

/** Repeats a string n times, for example `repeat("a", 2) == "aa"` */
def repeat(s: String, n: Int) = {
   var result = ""
   for (_ <- 0 until n) { result += s }
   result
}  
val hihihi = (Some("hi") |@| Some(3)) { case (s, n) => repeat(s, n) }
val hihihi_ = (Some("hi") |@| Some(3)) { repeat }
val nothing = (Some("hi") |@| None) { repeat }
nothing == None
organization := "com.example"
name := "project"
scalaVersion := "2.12.1"
scalacOptions ++= Seq(
"-deprecation",
"-encoding", "UTF-8", // yes, this is 2 args
"-feature",
"-unchecked",
"-Xfatal-warnings",
"-Xlint",
"-Yno-adapted-args",
// "-Ywarn-dead-code", // N.B. doesn't work well with the ??? hole
"-Ywarn-numeric-widen",
"-Ywarn-value-discard",
"-Ywarn-unused",
"-Ywarn-unused-import",
"-Xfuture",
"-Ypartial-unification"
)
// Remove these options in 'sbt console' because they're not nice for interactive usage
scalacOptions in (Compile, console) ~= (_.filterNot(Set("-Xfatal-warnings", "-Ywarn-unused-import").contains))
val http4sVersion = "0.15.0a"
val doobieVersion = "0.3.1-M3"
val argonautVersion = "6.2-RC2"
resolvers +=
"Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
libraryDependencies ++= Seq(
// Testing
"org.scalatest" %% "scalatest" % "3.0.1" % "test",
"org.tpolecat" %% "doobie-scalatest" % doobieVersion % "test",
"org.scalacheck" %% "scalacheck" % "1.13.4" % "test",
// HTTP serving and requesting
"org.http4s" %% "http4s-dsl" % http4sVersion,
"org.http4s" %% "http4s-blaze-server" % http4sVersion,
"org.http4s" %% "http4s-blaze-client" % http4sVersion,
"org.http4s" %% "http4s-argonaut" % http4sVersion,
// DB access
"org.tpolecat" %% "doobie-core" % doobieVersion,
"org.tpolecat" %% "doobie-postgres" % doobieVersion,
// JSON
"io.argonaut" %% "argonaut" % argonautVersion,
"io.argonaut" %% "argonaut-scalaz" % argonautVersion,
"io.argonaut" %% "argonaut-monocle" % argonautVersion,
// Logging
"ch.qos.logback" % "logback-classic" % "1.1.7"
// Config
// "oncue.knobs" %% "core" % "3.9.16"
)
initialCommands :=
"""
|import doobie.imports._
|import java.time.LocalDate
|import argonaut.JsonPath.root
""".stripMargin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment