ScalaCheck 1.14.0 was just released with support for deterministic testing using seeds. Some folks have asked for examples, so I wanted to produce a Gist to help people use this feature.
These examples will assume the following imports:
package demo | |
import cats.{Applicative, Functor, Id, Semigroupal, Traverse} | |
import cats.arrow.FunctionK | |
/** | |
* Type-lifting operation to replace the wildcard type (i.e. _). | |
* | |
* In some cases we end up with code like: List[Option[_]]. This is | |
* fine unless you later need to write code in terms of a particular |
package cats.collections | |
sealed abstract class LogicalBitSet { lhs => | |
import LogicalBitSet.{Absent, Present} | |
def apply(n: Int): Boolean = | |
this match { | |
case Present(bits) => bits(n) | |
case Absent(bits) => !bits(n) |
package ack | |
import cats.Eval | |
import spire.math.SafeLong | |
object Ackermann { | |
import SafeLong.{zero, one} | |
// requires m >= 0 and n >= 0 | |
def run(m: SafeLong, n: SafeLong): Eval[SafeLong] = |
package object demo { | |
opaque type Collection[A] = Array[A] | |
object Collection { | |
opaque type Pointer[A] = Int | |
object Pointer { | |
def first(c: Collection[A]): Option[Pointer[A]] = | |
if (c.length > 0) Some(0) else None |
package kronecker | |
import spire.implicits._ | |
/** | |
* Utilities for doing diagonalization in N dimensions. | |
* | |
* The goal here is to be able to support diagonalizations for | |
* arbitrary tuples, e.g. Tuple2, Tuple3, Tuple9, etc. The "dimension" | |
* (or "dim") represents the arity of the tuple: dim=2 would |
package sbtjavap | |
import sbt._ | |
import Keys._ | |
import complete.DefaultParsers.StringBasic | |
import scala.sys.process.Process | |
object Plugin extends AutoPlugin { | |
object autoImport { |
I was asked to consider how specialization should interact with SIP-23. Here is a quick test I did with some thoughts on where we are now versus where we should be.
See tlc.scala
for the code and tlc.bytecode
for the Java
bytecode that code produced (using Typelevel Scala with the
-Yliteral-types
flag enabled).
SIP-ZZ - NewType Classes
This is a proposal to introduce syntax for classes in Scala that can get completely inlined, so operations on these classes have zero overhead compared to external methods. Some use cases for inlined classes are:
scala | |
Array | |
BigDecimal | |
BigInt | |
Boolean | |
Byte | |
Char | |
Double | |
Float | |
FunctionN... |