Skip to content

Instantly share code, notes, and snippets.

Daniel Spiewak djspiewak

Block or report user

Report or block djspiewak

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View fromCompletableFuture.scala
def fromCompletableFuture[F[_]: Concurrent: ContextShift, A](
fa: F[CompletableFuture[A]])
: F[A] = {
val wrapped = Concurrent cancelableF[F, A] { k =>
fa flatMap { cf =>
val register = Sync[F] delay {
cf handleAsync { (a, e) =>
if (a == null)
View resolve-cats-effect-1.4.0.txt
λ coursier resolve org.typelevel:cats-effect_2.12:1.4.0

Cats Effect 3.0 Proposal

If you're someone for whom code speaks louder than words, here's a branch to ponder:

The following is a proposal for Cats Effect 3, collaboratively devised over the last few months by several of the maintainers and contributors to the library. I will frequently use first-person in this document (because I'm lazy), which is posted under my name (ditto), but it really was a joint effort. As with any joint effort, there has definitely been some healthy debate about several of the concepts in this proposal. For reference, these are the things we're the least sure about:

  • Concurrent now takes two type parameters, and thus is somewhat less ergonomic
  • Region has been added, along with some complex associated machinery
    • One component of that machinery is the Safe.Case type
  • Several existing laws are retained (such as Sync being stack-safe)
View error.txt
[error] ## Exception when compiling 22 sources to /Users/daniel/Development/Scala/cats-effect/laws/jvm/target/scala-2.13/test-classes
[error] java.lang.IllegalArgumentException: Could not find proxy for implicit val cs: cats.effect.ContextShift in List(value cs, method $anonfun$new$5, value <local IOTests>, class IOTests, package effect, package cats, package <root>) (currentOwner= value stabilizer$1 )
View coursier-strict.txt
/tmp λ ./coursier resolve --strict-include 'org.typelevel:*' 'org.typelevel:cats-effect_2.12:[1.0.0,)' 'org.typelevel:cats-core_2.12:1.0.0'
View flatMap2.scala
def flatMap2[F[_]: Monad, A, B, C](fa: F[A], fb: F[B])(f: (A, B) => F[C]): F[C] =
fa.flatMap(a => fb.flatMap(b => f(a, b)))


Benchmark                                      (enableSkips)  (framework)                      (input)  Mode  Cnt     Score    Error  Units
t.csv.ParserBenchmarks.lineCountThroughFs2               N/A     tectonic                          N/A  avgt   10   136.026 ±  2.572  ms/op
t.csv.ParserBenchmarks.parseThroughFs2                   N/A     tectonic                          N/A  avgt   10  1419.537 ± 41.725  ms/op
t.json.ParserBenchmarks.parseThroughFs2                  N/A     tectonic            bar (not wrapped)  avgt   10     0.064 ±  0.001  ms/op
t.json.ParserBenchmarks.parseThroughFs2                  N/A     tectonic           bla2 (not wrapped)  avgt   10     0.318 ±  0.002  ms/op
t.json.ParserBenchmarks.parseThroughFs2                  N/A     tectonic              bla25 (wrapped)  avgt   10    11.628 ±  0.110  ms/op
t.json.ParserBenchmarks.parseThroughFs2                  N/A     tectonic  countries.geo (not wrapped)  avgt   10    19.794 ±  0.151  ms/op
View diamond-typeclasses.scala
// ...get it?
final case class InductT[F[_], A](run: F[A])
// assume InductT is defined in some upstream library, so it knows nothing of the following
trait Functor[F[_]]
object Functor {
implicit def inductTFunctor[F[_]: Functor]: Functor[InductT[F, ?]] = new Functor[InductT[F, ?]]
View welp.txt
~/Development/slamdata λ javap -cp $(coursier fetch -p org.specs2:specs2-core_2.12:4.3.6) 'org.specs2.specification.dsl.mutable.ExampleDsl0$BlockExample0'
Compiled from "ExampleDsl.scala"
public class org.specs2.specification.dsl.mutable.ExampleDsl0$BlockExample0 {
public final org.specs2.specification.dsl.mutable.ExampleDsl0 $outer;
public org.specs2.specification.core.Fragment $greater$greater(scala.Function0<org.specs2.specification.core.Fragment>);
public org.specs2.specification.core.Fragments $greater$greater(scala.Function0<org.specs2.specification.core.Fragments>, org.specs2.control.ImplicitParameters$ImplicitParam1);
public <R> org.specs2.specification.core.Fragment $greater$greater(scala.Function0<R>, org.specs2.specification.core.AsExecution<R>);
public org.specs2.specification.core.Fragment should(scala.Function0<org.specs2.specification.core.Fragment>);
public org.specs2.specification.core.Fragments should(scala.Function0<org.specs2.specification.core.Fragments>, org.specs2.control.Im
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) & '"'
You can’t perform that action at this time.