Skip to content

Instantly share code, notes, and snippets.

@som-snytt
som-snytt / client.scala
Created May 9, 2020 01:10
post typer unit of work
package p
class Client {
def f = m.M.report("hello, world")
}
@som-snytt
som-snytt / shadowing.scala
Created March 23, 2020 11:53
Shadow implicits
package specsy {
trait Expectable[A]
trait MatchResult[A]
trait Matcher[-T] { outer =>
def apply[S <: T](t: Expectable[S]): MatchResult[S]
}
object Matchers {
def oneMatcher[S1]: Matcher[S1] = OneMatcher.asInstanceOf[Matcher[S1]]
def twoMatcher[S1, S2]: Matcher[(S1, S2)] = TwoMatcher.asInstanceOf[Matcher[(S1, S2)]]
}
@som-snytt
som-snytt / results
Created November 20, 2019 21:44
hot -psource=scalap
[info] Benchmark (corpusPath) (corpusVersion) (extraArgs) (resident) (scalaVersion) (source) Mode Cnt Score Error Units
[info] HotScalacBenchmark.compile ../corpus latest false 2.13.1 scalap sample 179 1888.480 ± 25.408 ms/op
[info] HotScalacBenchmark.compile:compile·p0.00 ../corpus latest false 2.13.1 scalap sample 1694.499 ms/op
[info] HotScalacBenchmark.compile:compile·p0.50 ../corpus latest false 2.13.1 scalap sample 1897.923 ms/op
[info] HotScalacBenchmark.compile:compile·p0.90 ../corpus latest false 2.13.1 scalap sample 1973.420 ms/op
[info] HotScalacBenchmark.compile:compile·p0.95 ../corpus latest false 2.13.1 scalap sample 2004.877 ms/o
@som-snytt
som-snytt / Answer
Created February 3, 2019 09:31
placeholder
There is only one rule for how placeholder syntax is translated to an anonymous function:
The next enclosing Expr, as defined by the syntax summary, is the function body, with the underscores converted to parameters.
This definition is given in section 6.23.2 of the the spec.
An Expr includes any of the control constructs such as if, while, and try, as well as function literal syntax x => f(x).
Function args and tuples (things in parens) are a list of Exprs.
@som-snytt
som-snytt / importance
Last active November 27, 2018 13:35
Various proposals for import syntax, or doing things with qualified things
Ref: https://contributors.scala-lang.org/t/proposed-syntax-for-root/1035
Use package for _root_
import _root_.a // now
import package.a // proposed (alternatively just leading dot)
Use underscore for symbol in scope
import a.b // now and forever, no special syntax
@som-snytt
som-snytt / FutureTest.scala
Created September 21, 2017 18:23
test for firstCompletedOf
package scala.concurrent
import org.junit.Assert._
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import scala.tools.testing.AssertUtil._
import scala.util.Try
@som-snytt
som-snytt / gist:4504281
Last active December 10, 2015 22:48
Future select
package object futurism {
import scala.language.higherKinds
import scala.collection.generic.CanBuildFrom
import scala.collection.{TraversableOnce => Once}
import scala.concurrent._
import scala.util.{Try, Success, Failure}
import scala.util.control.NonFatal
// TraversableOnce.filter results in an iterator that !isTraversableAgain
implicit class NaiveSelectable(val co: Future.type) extends AnyVal {