Skip to content

Instantly share code, notes, and snippets.

@xuwei-k
xuwei-k / disable-pipeline
Created April 20, 2024 12:25
Scala 3.5 nighty pipieline benchmark with scalaz
53
53
53
53
53
53
53
53
53
53
package example;
public class A {
public static void main(String[] args) {
var a = new java.util.concurrent.atomic.AtomicLong();
a.compareAndSet(1L, 2L);
}
}
@xuwei-k
xuwei-k / 3
Created February 28, 2024 07:10
$ scala -Xsource:3
Welcome to Scala 2.13.13 -Xsource:3.0.0 (OpenJDK 64-Bit Server VM, Java 1.8.0_392).
Type in expressions for evaluation. Or try :help.
scala> def f = {
| val x: Boolean = ???
|
| x
| && x
| }
package example
import shapeless.nat._
import shapeless.syntax.std.tuple._
object Main{
def main(args: Array[String]): Unit = {
val t = (2, false, "a")
val x = t.updateAtWith(2)(a => a :: Nil)._2
import scala.compiletime.ops.int.*
object MapTupleNExample {
type TupleMapN[T <: NonEmptyTuple, N <: Int, A] =
N < Tuple.Size[T] match {
case true =>
Tuple.Concat[
Tuple.Take[T, N],
A *: Tuple.Drop[T, N + 1]
]
[info] running (fork) org.openjdk.jmh.Main -i 10 -wi 10 -f1
[info] # JMH version: 1.37
[info] # VM version: JDK 23-ea, OpenJDK 64-Bit Server VM, 23-ea+7-481
[info] # VM invoker: /Library/Java/JavaVirtualMachines/jdk-23.jdk/Contents/Home/bin/java
[info] # VM options: <none>
[info] # Blackhole mode: compiler (auto-detected, use -Djmh.blackhole.autoDetect=false to disable)
[info] # Warmup: 10 iterations, 10 s each
[info] # Measurement: 10 iterations, 10 s each
[info] # Timeout: 10 min per iteration
[info] # Threads: 1 thread, will synchronize iterations
@xuwei-k
xuwei-k / Witness.scala
Last active January 27, 2024 10:40
shapeless.Witness match type
import scala.compiletime.ops.string.Length
import scala.compiletime.ops.string.CharAt
import scala.compiletime.ops.string.Substring
import scala.compiletime.ops.int
import scala.compiletime.ops.long
import scala.language.dynamics
object Witness extends Dynamic {
type StringTail[A <: String] = Substring[A, 1, Length[A]]
import play.api.BuiltInComponents
import play.api.Mode
import play.api.mvc._
import play.api.routing._
import play.api.routing.sird._
import play.core.server.PekkoHttpServer
import play.core.server.ServerConfig
object Main {
// 1つのScalaファイルで済むので、
@xuwei-k
xuwei-k / Scala-2-12
Last active October 5, 2023 05:29
scala xml pattern match
Welcome to Scala 2.12.18 (OpenJDK 64-Bit Server VM, Java 11.0.20).
Type in expressions for evaluation. Or try :help.
scala> val <a>{ b }</a> = <a></a>
scala.MatchError: <a></a> (of class scala.xml.Elem)
... 55 elided
scala> val <a>{ _ }</a> = <a>c</a>
scala> val <a>{ _* }</a> = <a>c</a>
@xuwei-k
xuwei-k / Bench.scala
Last active September 29, 2023 06:56
package p1
import org.openjdk.jmh.annotations.Benchmark
object Bench {
val values: List[Either[Int, Int]] = (1 to 100_000).map{
case n if n % 2 == 0 =>
Right(n)
case n =>
Left(n)