This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val dockerPublish = taskKey[Unit]("ダミーのタスク。本来sbt-native-packagerのやつ") | |
lazy val commonSettings = Def.settings( | |
dockerPublish := { | |
import java.time.LocalTime | |
println(s"${LocalTime.now()} ${name.value} のpublish開始") | |
// 並列で実行されるのがわかりやすいように、途中sleepする | |
Thread.sleep(3000) | |
println(s"${LocalTime.now()} ${name.value} のpublish終了") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> scala -Xlog-implicits | |
Welcome to Scala 2.12.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_172). | |
Type in expressions for evaluation. Or try :help. | |
scala> object A { | |
| import scala.language.implicitConversions | |
| implicit val int: Int = 1 | |
| def a[A]: A = ??? | |
| implicit def asString[A](implicit i: Int): Long => A = _ => a[A] | |
| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> class Hoge { | |
| def m1: this.type = this // OK | |
| def m2: this.type = new Hoge // NG | |
| } | |
<console>:9: error: type mismatch; | |
found : Hoge | |
required: Hoge.this.type | |
def m2: this.type = new Hoge // NG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2017/06/08 06:49 | |
ブックマーク数100以上 | |
連載中 | |
文字数10万文字以上 | |
all novel count = 30060 | |
unique novel count = 12320 | |
filtered novel count = 2759 | |
順位 URL 文字数 ポイント評価 ブックマーク数 (ポイント評価 / ブックマーク数) title keyword |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.language.experimental.macros | |
import scala.reflect.macros.whitebox.Context | |
/** | |
*/ | |
object MethodsMacro { | |
def apply[T]: Seq[String] = macro genMethods[T] | |
def genMethods[T: c.WeakTypeTag](c: Context): c.Tree = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import upickle.{Js, Api} | |
trait UseUpickle { | |
val mJsonApi: upickle.Api | |
def write[T: mJsonApi.Writer](a: T): String = mJsonApi.write(a) | |
def writeHoge(aHoge: Hoge): String = { | |
import mJsonApi._ | |
mJsonApi.write(aHoge) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class State[S, +A](run: S => (A, S)) { | |
def map[B](f: A => B): State[S, B] = State { s0 => | |
val (a, s1) = run(s0) | |
(f(a), s1) | |
} | |
def map2[B, C](that: State[S, B])(f: (A, B) => C): State[S, C] = State { s0 => | |
val (a, s1) = this.run(s0) | |
val (b, s2) = that.run(s1) | |
(f(a, b), s2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait RNG { | |
def nextInt: (Int, RNG) | |
} | |
object RNG { | |
case class Simple(seed: Long) extends RNG { | |
def nextInt: (Int, RNG) = { | |
val newSeed = (seed * 0x5DEECE66DL + 0xBL) & 0xFFFFFFFFFFFFL // `&` is bitwise AND. We use the current seed to generate a new seed. | |
val nextRNG = Simple(newSeed) // The next state, which is an `RNG` instance created from the new seed. | |
val n = (newSeed >>> 16).toInt // `>>>` is right binary shift with zero fill. The value `n` is our new pseudo-random integer. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def unfold[A, S](s: S)(f: S => Option[(A, S)]): Stream[A] = f(s) match { | |
case Some((a, s1)) => a #:: unfold(s1)(f) | |
case _ => Stream.empty[A] | |
} | |
def fibs: Stream[Int] = 0 #:: 1 #:: unfold((0, 1)) { | |
case (n0, n1) => | |
val n2 = n0 + n1 | |
Option((n2, (n1, n2))) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def foldRight[A, B](s: Stream[A])(z: => B)(f: (A, => B) => B): B = s match { | |
case x #:: xs => f(x, foldRight(xs)(z)(f)) | |
case _ => z | |
} | |
def headOptionViaFoldRight[A](s: Stream[A]): Option[A] = foldRight(s)(None: Option[A]) { | |
(e, acc) => Some(e) | |
} | |
def map[A, B](s: Stream[A])(f: A => B): Stream[B] = foldRight(s)(Stream.empty[B]) { |
NewerOlder