Skip to content

Instantly share code, notes, and snippets.

@xuwei-k
xuwei-k / big3.scala
Created May 29, 2019 00:18 — forked from mpilquist/big3.scala
Example encoding of Functor / Applicative / Monad using dotty 0.15
/* Example of encoding Functor/Applicative/Monad from cats with Dotty 0.15 features.
* Derived in part from Cats -- see https://github.com/typelevel/cats/blob/master/COPYING for full license & copyright.
*/
package structures
import scala.annotation._
trait Functor[F[_]] {
def (fa: F[A]) map[A, B](f: A => B): F[B]
def (fa: F[A]) as[A, B](b: B): F[B] =
package io.github.retronym
import sbt._
import Keys._
object RawCompile extends AutoPlugin {
override def trigger = allRequirements
override def requires = sbt.plugins.JvmPlugin
val compileRaw = taskKey[Unit]("Compile directly, bypassing the incremental compiler")
val cleanClasses = taskKey[Unit]("clean the classes directory")
@xuwei-k
xuwei-k / scala-2.13.0-M5.md
Created August 22, 2018 03:06 — forked from SethTisue/scala-2.13.0-M5.md
Scala 2.13.0-M5 draft release notes

Scala 2.13 is getting closer and closer!

We've been polishing the improved and simplified Scala collections library that first shipped in 2.13.0-M4. We expect the API to remain stable now, though there may still be minor changes in RC1.

M5 is our feature-freeze release for 2.13. From here forward, we’ll close existing open loops but not embark on or accept new work.

Collections changes

The major collections changes already landed in M4. See the M4 release notes for a summary.

@xuwei-k
xuwei-k / doc.md
Created June 9, 2018 12:22 — forked from retronym/doc.md
Scripts for convenient access to Scala pre-release builds
@xuwei-k
xuwei-k / patchScalikejdbcStringBinder.scala
Created November 30, 2017 13:51 — forked from bancek/patchScalikejdbcStringBinder.scala
Monkey patch scalikejdbc String binder to support UTF8 for MySQL VARBINARY columns
import scalikejdbc._
package object models {
val stringUTF8: Binders[String] = Binders((rs, index) => new String(rs.getBytes(index), "UTF-8"))((rs, label) => new String(rs.getBytes(label), "UTF-8"))(v => (ps, idx) => ps.setBytes(idx, v.getBytes("UTF-8")))
{ // patch TypeBinder.string
val field = TypeBinder.getClass.getDeclaredField("string")
field.setAccessible(true)
field.set(TypeBinder, stringUTF8)
}
@xuwei-k
xuwei-k / lmdb.tcl
Created April 28, 2017 15:43 — forked from antirez/lmdb.tcl
LMDB -- First version of Redis written in Tcl
# LVDB - LLOOGG Memory DB
# Copyriht (C) 2009 Salvatore Sanfilippo <antirez@gmail.com>
# All Rights Reserved
# TODO
# - cron with cleanup of timedout clients, automatic dump
# - the dump should use array startsearch to write it line by line
# and may just use gets to read element by element and load the whole state.
# - 'help','stopserver','saveandstopserver','save','load','reset','keys' commands.
# - ttl with milliseconds resolution 'ttl a 1000'. Check ttl in dump!
@xuwei-k
xuwei-k / ASample.scala
Created December 16, 2016 03:01 — forked from mandubian/ASample.scala
Encoding Category Theory Laws (à-la-scalaz/cats) using kind-polymorphic List and compare/manipulate laws of structure
/**
* In classic Scala implementation of hierarchies of Category theory laws (scalaz/cats), the dependency between
* different laws is encoded using inheritance (https://github.com/typelevel/cats/blob/master/core/src/main/scala/cats/Monad.scala#L14)
*
* This approach creates well-known issues: for example, a Monad is able to _derive_ an Applicative.
* So sometimes, you don't have the Applicative you want but the one derived from the Monad or it doesn't
* compile because you have 2 Applicatives in your implicit scope.
*
* Alois Cochard has proposed a new model to represent that in (scato project)[https://github.com/aloiscochard/scato] or
* (scalaz/8.0.x)[https://github.com/scalaz/scalaz/blob/series/8.0.x/base/src/main/scala/typeclass/Monad.scala] branch.
@xuwei-k
xuwei-k / ListBufferTest.scala
Created December 15, 2016 14:32 — forked from jrudolph/ListBufferTest.scala
ListBuffer / List mutability fail
import scala.collection.mutable.ListBuffer
object ListBufferTest extends App {
new X().runTest()
}
class X extends Runnable {
var x: List[String] = List("", "")
def run() {
import scalaz.std.string._
import scalaz.std.list._
import scalaz.{Semigroup, Monoid, Functor, Applicative}
trait Foo[A] {
override def toString: String = "Foo"
}
trait Foo2[A] extends Foo[A] {
override def toString: String = "Foo2"
class TC[A](val x: String)
object TC {
def getX[A: TC](a: A): String = implicitly[TC[A]].x
implicit def anyTC[A]: TC[A] = new TC[A]("*")
implicit val stringTC: TC[String] = new TC[String]("String")
}
object Example {