This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object SJ extends App { | |
trait Getter[T] { | |
def get(s: String): T | |
} | |
object Getter { | |
implicit val getInt = new Getter[Int] { | |
def get(s: String) = s.toInt // unsafe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.io.Source | |
import System.{ currentTimeMillis => now } | |
object Inv extends App { | |
// An int set that knows how many members are greater than a given number. | |
sealed trait GSet { | |
def ngt(n: Int): Int // number greater than `n` | |
def +(n: Int): GSet | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.collection.convert.Wrappers.JMapWrapper | |
import java.util.Collections | |
object MapTest extends App { | |
val m = new JMapWrapper(Collections.synchronizedMap(new java.util.HashMap[String,String])) | |
new Thread { | |
override def run { | |
while (true) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalaz.State // the State[S,A] type itself | |
import scalaz.State._ // primitives like get and put are here | |
object StateExample extends App { | |
// A computation that produces a String | |
val action1: State[Int, String] = | |
for { | |
n <- get | |
_ <- put(n + 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import annotation.implicitNotFound | |
@implicitNotFound(msg = "This message can never appear!") | |
trait ~>[A, B] { self => | |
def apply(a: A): B | |
def invert(b: B): A = inverse.apply(b) | |
def inverse: B ~> A = new ~>[B, A] { | |
def apply(b: B) = self.invert(b) | |
override def invert(a: A) = self(a) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Tuples { | |
trait HT { | |
type H | |
type T | |
def hd: H | |
def tl: T | |
} | |
implicit class T3[A, B, C](t: (A, B, C)) extends HT { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Nafg { | |
object Tuples { | |
trait HT[A] { | |
type H | |
type T | |
def hd(a: A): H | |
def tl(a: A): T | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit def mv[F] = new Monad[({ type λ[a] = Validation[F, a] })#λ] { | |
def bind[A, B](fa: Validation[F, A])(f: A => Validation[F, B]): Validation[F, B] = fa.flatMap(f) | |
def point[A](a: => A): Validation[F, A] = a.success | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object stuff { | |
import scala.util.parsing.combinator._ | |
class Parser extends RegexParsers { | |
def parseTop(s: String): Stuff = parse(top(""), s) match { | |
case Success(value, _) => value | |
case _ => throw new RuntimeException("...") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import language.higherKinds | |
object FooExample extends App { | |
// Slice of comonad is where this came up | |
trait Foo[F[_]] { | |
def coflatMap[A, B](f: F[A] => B): F[A] => F[B] | |
} | |
// A non-empty list |