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
//> using scala 3.5.2 | |
//> using dep "com.softwaremill.ox::core:0.5.2" | |
object types: | |
opaque type Title = String | |
object Title: | |
def apply(title: String): Either[Exception, Title] = | |
if title.isBlank then Left(Exception("Title must not be blank")) | |
else Right(title) |
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
//> using scala 3.5.1 | |
//> using test.dep org.typelevel::cats-laws:2.12.0 | |
//> using test.dep org.typelevel::discipline-munit:2.0.0 | |
//> using test.dep io.getkyo::kyo-core:0.13.1 | |
//> using test.dep io.getkyo::kyo-cats:0.13.1 | |
//> using test.dep org.scalameta::munit:1.0.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
$ sbt new http4s/http4s.g8 --branch 1.0-scala3 | |
// use all the defaults, just set sbt to 1.9.9 | |
$ cd quickstart | |
$ sbt assembly | |
$ cat Dockerfile # create this file with these contents: | |
FROM ghcr.io/graalvm/jdk-community:22 | |
RUN mkdir /opt/app |
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
//> using scala 3.4.0 | |
import language.experimental.captureChecking | |
class DbCon: | |
def runUpdate(): Unit = println(s"runUpdate on ${Thread.currentThread()}") | |
def close(): Unit = println("closing DbCon") | |
def transact[A](f: DbCon^ => A): A = | |
val dbCon = DbCon() |
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
//> using scala 3.3.3 | |
//> using jvm graalvm-java21:21.0.2 | |
//> using dep com.softwaremill.ox::core:0.0.21 | |
import ox.* | |
import java.util.concurrent.* | |
@main def main = supervised { | |
val queue = ArrayBlockingQueue[Int](5) |
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.quoted.* | |
extension (using quotes: Quotes)(repr: quotes.reflect.TypeRepr) | |
def flatMapResultType(f: quotes.reflect.TypeRepr => Option[quotes.reflect.TypeRepr]): Option[quotes.reflect.TypeRepr] = | |
import quotes.reflect.* | |
repr match | |
case MethodType(paramNames, paramTypes, resultType) => | |
resultType.flatMapResultType(f).map(tp => MethodType(paramNames)(_ => paramTypes, _ => tp)) | |
// case PolyType => // should not appear here | |
case tp => |
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
//> using dep com.github.ghostdogpr::caliban-quick:2.5.0 | |
enum Origin { | |
case EARTH, MARS, BELT | |
} | |
case class Character( | |
name: String, | |
nicknames: List[String], | |
origin: Origin |
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
//> using scala "3.3.1" | |
//> using lib "co.fs2::fs2-io:3.9.3" | |
import scala.util.* | |
import scala.io.Source | |
def safePrintln(s: Any): Either[Throwable, Unit] = | |
try Right(println(s)) | |
catch case err: Throwable => Left(err) |
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
// AppKt.java | |
package hello; | |
import kotlin.Metadata; | |
import kotlin.coroutines.Continuation; | |
import kotlin.coroutines.CoroutineContext; | |
import kotlin.jvm.functions.Function0; | |
import kotlin.jvm.functions.Function2; | |
import kotlin.jvm.internal.Intrinsics; | |
import kotlin.jvm.internal.SourceDebugExtension; |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<project | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" | |
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>org.jetbrains.kotlin.examples</groupId> | |
<artifactId>hello-world</artifactId> | |
<version>1.0-SNAPSHOT</version> |
NewerOlder