This file contains hidden or 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.* | |
| import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue | |
| @main def demo(): Unit = | |
| val items = Vector.range(1, 9) | |
| val result: Future[Vector[Int]] = items.parMap(parallelism = 4)(_ * 2) | |
| result.foreach: xs => | |
| println(s"parMap result: $xs") |
This file contains hidden or 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
| @main def demo(): Unit = | |
| def slow(i: Int): Int = | |
| Thread.sleep(100) | |
| i * i | |
| val items = Vector.range(1, 33) | |
| def time[A](label: String)(body: => A): A = | |
| val t0 = System.nanoTime() | |
| val r = body |
This file contains hidden or 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.* | |
| object platform: | |
| type R[A] = Future[A] | |
| def parRun[A](parallelism: Int)(body: ExecutionContext => Future[A]): R[A] = | |
| import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue | |
| body(summon[ExecutionContext]) |
This file contains hidden or 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.* | |
| import scala.concurrent.duration.* | |
| import java.util.concurrent.Executors | |
| object platform: | |
| type R[A] = A | |
| def parRun[A](parallelism: Int)(body: ExecutionContext => Future[A]): R[A] = | |
| val pool = Executors.newFixedThreadPool(parallelism.max(1)) | |
| val ec = ExecutionContext.fromExecutorService(pool) |
This file contains hidden or 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.8.3 | |
| import scala.concurrent.* | |
| import scala.collection.BuildFrom | |
| import scala.collection.generic.IsIterable | |
| import java.util.concurrent.atomic.AtomicInteger | |
| extension [Repr](xs: Repr)(using it: IsIterable[Repr]) | |
| def parMap[B, To](parallelism: Int)(f: it.A => B)(using |
This file contains hidden or 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.7.3 | |
| //> using dep com.softwaremill.ox::core:1.0.0 | |
| import scala.concurrent.duration.* | |
| import java.time.Instant | |
| import ox.* | |
| import scala.util.boundary | |
| import java.util.ArrayList | |
| import java.util.concurrent.locks.LockSupport |
This file contains hidden or 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
| ---------------------------------------- | |
| mode lto gc cap ms | |
| ---------------------------------------- | |
| jvm n/a n/a 1024 217 | |
| graalvm-ni n/a n/a 1024 342 | |
| release-full full commix 65534 517 | |
| release-fast full commix 65534 523 | |
| release-size full commix 65534 554 | |
| jvm n/a n/a 65534 555 | |
| release-full full immix 65534 562 |
This file contains hidden or 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 java.util.UUID | |
| import java.time.Instant | |
| import scala.deriving.Mirror | |
| case class MyCaseClass( | |
| intField: Int, | |
| longField: Long, | |
| doubleField: Double, | |
| stringField: String, | |
| booleanField: Boolean, |
This file contains hidden or 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
| // run `go build main.go` | |
| package main | |
| import ( | |
| "fmt" | |
| "os" | |
| "strconv" | |
| ) | |
| func fibonacci(n int) int { |
This file contains hidden or 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) |
NewerOlder