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
class ExplicitLocale extends SyntacticRule("ExplicitLocale") { | |
override def fix(implicit doc: SyntacticDocument): Patch = | |
doc.tree.collect { | |
case t @ Term.Select(_, tn) if targets.contains(tn.value) => | |
t.parent match { | |
case Some(Term.Apply(Term.Select(_, _), args)) if args.nonEmpty => | |
Patch.empty | |
case _ => | |
Patch.lint(ExplicitLocaleWarn(t.pos)) | |
} |
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 Functor[F[_]] { | |
def map[A, B](fa: F[A])(f: A => B): F[B] | |
} | |
type Id[A] = A | |
object Id { | |
implicit def idFunctor = new Functor[Id] { | |
def map[A, B](fa: Id[A])(f: A => B): Id[B] = f(fa) | |
} | |
} |
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
➜ /tmp scala | |
Welcome to Scala 2.13.6 (OpenJDK 64-Bit Server VM, Java 11.0.8). | |
Type in expressions for evaluation. Or try :help. | |
scala> val b: Byte = 1 | |
val b: Byte = 1 | |
scala> b.toHexString | |
val res0: String = 1 |
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.concurrent.Future | |
import scala.concurrent.duration._ | |
import java.util.concurrent.Executors | |
implicit val ec = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(5)) | |
val r = Future { | |
val ids = (0 to 10) | |
println(ids) | |
ids.toSeq |
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
package tf | |
import scala.concurrent.{ExecutionContext, Future} | |
import scala.util.Try | |
// === Predef | |
trait Monad[F[_]] { | |
def pure[A](f: A): F[A] | |
def flatMap[A, B](fa: F[A])(f: A => F[B]): F[B] |
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.existentials | |
import java.net._ | |
var loader = new URLClassLoader(Array(new URL("file:///tmp/example/"))) | |
val wrCat = new java.lang.ref.WeakReference(loader.loadClass("example.Cat")) | |
println("=== class cat: " + wrCat.get) | |
println("~~~ remove loader ~~~") | |
loader = null |
- Scala 2.13.0 の REPL
- ScalaCheck 1.14.0
- 限定継続...
- エラーハンドリングの実用例みたいなもの
- https://github.com/aoiroaoino/monoton/blob/a4f326bfa0c/core/src/main/scala/monoton/server/Handler.scala
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 Dependencies._ | |
lazy val root = (project in file(".")). | |
settings( | |
inThisBuild(List( | |
organization := "com.example", | |
scalaVersion := "2.11.11", | |
version := "0.1.0-SNAPSHOT" | |
)), | |
name := "vr-lens-demo", |
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 monocle.Lens | |
case class Foo(bar: Option[String]) | |
val _bar = Lens[Foo, Option[String]](_.bar)(s => foo => foo.copy(bar = s)) | |
def いい感じにする(foo: Foo)(s: String): Foo = _bar.modify(bar => bar orElse Some(s))(foo) | |
// scala> いい感じにする(Foo(Some("bbb")))("aaa") | |
// res0: Foo = Foo(Some(bbb)) |
NewerOlder