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 -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 | |
| } |
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 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 |
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.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] | |
] |
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
[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 |
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.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]] |
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 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ファイルで済むので、 |
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
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> |
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 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) |
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
public java.lang.String x(java.lang.String); | |
descriptor: (Ljava/lang/String;)Ljava/lang/String; | |
flags: (0x0001) ACC_PUBLIC | |
Code: | |
stack=1, locals=2, args_size=2 | |
0: aload_1 | |
1: invokedynamic #27, 0 // InvokeDynamic #0:makeConcatWithConstants:(Ljava/lang/String;)Ljava/lang/String; | |
6: areturn |
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 example | |
trait Functor[F[_]] { | |
def map[A, B](fa: F[A])(f: A => B): F[B] | |
} | |
object Functor { | |
def fromPolyFunction[F[_]](x: [A, B] => (fa: F[A]) => (f: A => B) => F[B]): Functor[F] = | |
new Functor[F] { | |
def map[A, B](fa: F[A])(f: A => B): F[B] = x(fa)(f) |
NewerOlder