Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Spiewak djspiewak

View GitHub Profile
View Dispatcher.scala
/*
* Copyright 2020 Typelevel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
View Soviet3.scala
trait Exists[F[_]] {
type E
def apply(): F[E]
}
object Exists {
def apply[F[_], A](fa: F[A]): Exists[F] = new Exists[F] {
type E = A
def apply() = fa
}
View Soviet2.scala
object Soviet {
def repeated[F[_]: Async, A, B, R](runner: (A => B) => F[R])(body: A => F[B]): F[R] =
for {
ref <- Sync[F].delay(new AtomicReference[A => B])
result <- Sync[F].delay(new AtomicReference[B])
latch <- Sync[F].delay(new Semaphore(1))
_ <- Sync[F].delay(latch.acquire())
r <- {
View Soviet.scala
object Soviet {
def repeated[F[_]: Async, A, B](runner: (A => B) => F[Unit])(body: A => F[B]): F[Unit] =
for {
ref <- Sync[F].delay(new AtomicReference[A => B])
result <- Sync[F].delay(new AtomicReference[B])
latch <- Sync[F].delay(new Semaphore(1))
_ <- Sync[F].delay(latch.acquire())
_ <- {
View Converter.scala
/*
* Copyright 2020 Daniel Spiewak
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
View schedulers.md

Schedulers

As Cats Effect is a runtime system, it ultimately must deal with the problem of how best to execute the programs which are defined using its concrete implementation (IO). Fibers are an incredibly powerful model, but they don't map 1:1 or even 1:n with any JVM or JavaScript construct, which means that some interpretation is required. The fashion in which this is achieved has a profound impact on the performance and elasticity of programs written using IO.

This is true across both the JVM and JavaScript, and while it seems intuitive that JavaScript scheduling would be a simpler problem (due to its single-threaded nature), there are still some significant subtleties which become relevant in real-world applications.

JVM

IO programs and fibers are ultimately executed on JVM threads, which are themselves mapped directly to kernel threads and, ultimately (when scheduled), to processors. Determining the optimal method of mapping a real-world, concurrent application down to kernel-level thr

View static_cast.scala
// we really want to vectorize something like this:
val bytes: Array[Byte] = ???
val results: Array[Byte] = new Array[Byte](bytes.length)
var i = 0
while (i < bytes.length) { // assume bytes.length % 4 == 0
results(i) |= bytes(i) & '"'
}
View soe.txt
2020-08-18T00:03:45.3752812Z [error] java.lang.StackOverflowError
2020-08-18T00:03:45.3753387Z [error] at dotty.tools.dotc.core.Types$TypeSizeAccumulator.apply(Types.scala:5523)
2020-08-18T00:03:45.3753970Z [error] at dotty.tools.dotc.core.Types$TypeAccumulator.foldOver(Types.scala:5452)
2020-08-18T00:03:45.3754405Z [error] at dotty.tools.dotc.core.Types$TypeAccumulator.foldOver(Types.scala:5385)
2020-08-18T00:03:45.3754757Z [error] at dotty.tools.dotc.core.Types$TypeSizeAccumulator.apply(Types.scala:5537)
2020-08-18T00:03:45.3755099Z [error] at dotty.tools.dotc.core.Types$TypeSizeAccumulator.apply(Types.scala:5523)
2020-08-18T00:03:45.3755435Z [error] at dotty.tools.dotc.core.Types$TypeAccumulator.foldOver(Types.scala:5404)
2020-08-18T00:03:45.3756064Z [error] at dotty.tools.dotc.core.Types$TypeSizeAccumulator.apply(Types.scala:5537)
2020-08-18T00:03:45.3756430Z [error] at dotty.tools.dotc.core.Types$TypeSizeAccumulator.apply(Types.scala:5535)
2020-08-18T00:03:45.3756767Z [error] at dotty.tools.dotc
View baysick.scala
import scala.collection.mutable
import scala.util.continuations._
object Baysick {
val running = new ThreadLocal[Boolean] {
override val initialValue = true
}
val env = new ThreadLocal[mutable.Map[Symbol, Any]] {
override val initialValue = mutable.Map[Symbol, Any]()
View specs3-wishlist.md

My Specs3(?) Wishlist

Prescriptive Structural Syntax

I like the mutable DSL. What I don't like is the fact that there are so many variants of it. This makes Specs a very difficult framework to teach to newcomers (similar to ScalaTest), since there are so many options. I personally prefer should/to, but there are a lot of caveats with that syntax. Instead, I think it's better to just settle on >> (or some variant thereof). It keeps the best feature of the mutable fragments construction (easy arbitrary nesting) without generating the linguistic or API ambiguity of the current menagerie.

I would remove the immutable specification definitions entirely.

Better Matcher Construction

You can’t perform that action at this time.