Skip to content

Instantly share code, notes, and snippets.

View aoiroaoino's full-sized avatar
🏠
Working from home

Naoki Aoyama aoiroaoino

🏠
Working from home
View GitHub Profile
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))
}
@aoiroaoino
aoiroaoino / _lens.scala
Last active July 15, 2021 08:14
Lens の Getter, Setter
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)
}
}
@aoiroaoino
aoiroaoino / scala2.scala
Last active June 13, 2021 10:48
scala.Predef.intWrapper が機能していない?
/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
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
@aoiroaoino
aoiroaoino / tf_example.scala
Created October 27, 2019 07:31
scala関西Summit 2019 アンカンファレンス
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]
@aoiroaoino
aoiroaoino / a_scala_kansai_summit_2019.md
Last active October 26, 2019 07:40
Scala関西Summit 2019 登壇資料の Appendix
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
@aoiroaoino
aoiroaoino / a.md
Last active September 16, 2019 06:28
Scala秋祭り2019 発表資料内に登場するソースコードの元
@aoiroaoino
aoiroaoino / build.sbt
Last active March 28, 2018 12:40
VL-Lens in Scala
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",
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))