Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Scalaの(俺的)イケてる
ライブラリ紹介LT

 Scalaの(俺的)イケてる
ライブラリ紹介LT

2017/03/21に「Scala x AdTech Studio」というイベントのLTで発表した内容です。

Takayuki Sakai

March 22, 2017
Tweet

More Decks by Takayuki Sakai

Other Decks in Programming

Transcript

  1. Refined type UserId = Int Refined Positive val userId: UserId

    = 0 // compile error type Probability = Double Refined Closed[W.`0.0`.T, W.`1.0`.T] val p: Probability = 1.2 // compile error
  2. PureConfig // development.conf (HOCONܗࣜ)
 include “application.conf” redis { host: “127.0.0.1”

    port: 6379 } // Config.scala case class Config(redis: RedisConfig) case class RedisConfig(host: String, port: Int) val confPath = ConfigFactory.load(“development.conf”) val config = loadConfig[Config](confPath).get assert(config.redis.host == “127.0.0.1”) assert(config.redis.port == 6379)
  3. Finch case class User(name: String, age: Int) val getUser: Endpoint[User]

    = get(“user” :: int) { userId: Int => val user: User = User.getById(userId) user } val createUser: Endpoint[Boolean] = post(“user” :: jsonBody[User]) { user: User => // create user true } Http.server.serve(“:80”, (getUser :+: createUser).toService)
  4. doobie sql”SELECT * FROM users WHERE age = $age” .query[String]

    .process .take(5) .list .transact(xa) .unsafePerformIO .foreach(println)
  5. doobie sql”SELECT * FROM users WHERE age = $age” .query[String]

    .process .take(5) .list .transact(xa) .unsafePerformIO .foreach(println) ͜ͷ෦෼͸Prepared StatementΛ
 ࢖ͬͯจࣈྻૠೖ͞ΕΔͷͰɺ
 SQLΠϯδΣΫγϣϯʹ΋ڧ͍