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
class A | |
class A2 extends A | |
class B | |
trait M[X] | |
// | |
// Upper Type Bound | |
// | |
def upperTypeBound[AA <: A](x: AA): A = x |
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
case class ElectricCar(b: Battery) { def batteryLevel = b.filledPercentage } | |
case class GasolineCar(g: GasTank) { def gasLevel = g.filledPercentage } | |
case class Battery(filledPercentage: Int) { def fill: Battery = Battery(100) } | |
case class GasTank(filledPercentage: Int) { def fill: GasTank = GasTank(100) } | |
trait Fills[C] { | |
def fill(car: C): C |
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.{Failure => _, _} | |
import Scalaz._ | |
import effects._ | |
import iteratees._ | |
import java.io._ | |
object Head { | |
def main(args: Array[String]) { | |
val enum = enumStream[Seq[Byte], IO]((1 to 50).toStream.map(i => ("line " + i + "\n").getBytes.toSeq)) |
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
package scalaz.example | |
import scalaz.AltDList._ | |
object ExampleAltDList { | |
def main(args: Array[String]) = run | |
import scalaz._, Scalaz._ | |
import IterV._ |
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 MapMonoid[K, V](implicit valueSemigroup: Semigroup[V]): Monoid[Map[K, V]] = new Monoid[Map[K, V]] { | |
override val zero = Map.empty[K, V] | |
override def append(m1: Map[K, V], m2: => Map[K, V]) = { | |
val (from, to, semigroup) = { | |
if (m1.size > m2.size) (m2, m1, (v1: V, v2: V) => valueSemigroup.append(v1, v2)) | |
else (m1, m2, (v1: V, v2: V) => valueSemigroup.append(v2, v1)) | |
} | |
from.foldLeft(to) { | |
case (to, (k, v)) => to + (k -> to.get(k).map(semigroup(_, v)).getOrElse(v)) |
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.{Failure => _, _} | |
import Scalaz._ | |
import effects._ | |
import iteratees._ | |
import java.io._ | |
object Head { | |
def main(args: Array[String]) { | |
val enum = enumStream[Seq[Byte], IO]((1 to 50).toStream.map(i => ("line " + i + "\n").getBytes.toSeq)) |
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
;; An example of the "accounts" program for Venkat Subramaniam's | |
;; Programming Concurrency Workshop, part 1 | |
;; | |
;; Original Java code by Venkat Subramaniam (@venkat_s) | |
;; available at http://www.agiledeveloper.com/downloads.html | |
;; under "Workshop: Programming Concurrency" | |
;; | |
;; This code example by Stuart Sierra (@stuartsierra) | |
;; | |
;; Überconf 2011, Denver, Colorado |
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
scala> def f[A[_] <: Seq[_]](f: A[Int]) = f.head | |
f: [A[_] <: Seq[_]](f: A[Int])A | |
scala> def f[A[_] <: Seq[t] forSome { type t }](f: A[Int]) = f.head | |
f: [A[_] <: Seq[_]](f: A[Int])A | |
scala> def f[A[t] <: Seq[_] forSome { type t}](f: A[Int]) = f.head | |
f: [A[t] <: Seq[_] forSome { type t }](f: A[Int])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
trait ApplicativeMagic[F[_]] { | |
def apply[C](f: ApplicativeMagicFunctionHolder[FunctionArg => C]): F[C] | |
type FunctionArg | |
} | |
class ApplicativeMagicFunctionHolder[F](val f: F) | |
object ApplicativeMagicFunctionHolder { | |
implicit def fix2[A,B,C](f: (A,B) => C): ApplicativeMagicFunctionHolder[Tuple2[A,B] => C] = | |
new ApplicativeMagicFunctionHolder({ case (a,b) => f(a,b) }) | |
implicit def fix3[A,B,C,D](f: (A,B,C) => D): ApplicativeMagicFunctionHolder[Tuple2[Tuple2[A,B],C] => D] = | |
new ApplicativeMagicFunctionHolder({ case ((a,b),c) => f(a,b,c) }) |
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
// Is this even faintly novel? The closest I've seen is | |
// | |
// http://stackoverflow.com/questions/2618891/using-lazy-evaluation-functions-in-varargs | |
// | |
// which is a bit clunky by comparison. But this is so trivial someone must have | |
// done it this way before. | |
// UPDATE: | |
// Thanks to the Twittersphere (@etorreborre, @pchiusano and @loverdos) for a few sightings of related things, | |
// |
OlderNewer