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 PhantomTypes { | |
trait State; trait Closed extends State; trait Open extends State | |
class SingleCallOps[A <: State, B <: State] { | |
def a(implicit a: A =:= Open) = SingleCallOps.as[Closed, B] | |
def b(implicit b: B =:= Open) = SingleCallOps.as[A,Closed] | |
} | |
object SingleCallOps { |
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
read L as Left, R as Right, C as Center | |
moveN | |
m1:Move[Succ[_0],L,C,R] | |
m2:Move[_0,L,R,C] production side effect "Move from Left to Right" via move0 | |
m3:Move[Succ[_0],C,R,L] | |
produces Move[Succ[_1](_2),L,R,C] | |
moveN | |
m1:Move[_0,L,R,C] production side effect "Move from Left to Right" via move0 |
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 util.Random | |
object RandomGeneratorProjection { | |
// in : size of the input generator | |
// out : size of the output generator | |
def d(in: Int, out: Int): Int = { | |
assert(in > 1, "in must be greater than 1") | |
assert(out > 0, "out must be greater than 0") |
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 Common { | |
trait I[A, B] { | |
def apply(a: A): B | |
} | |
def i[A, B](f: A => B): I[A, B] = new I[A,B] { | |
def apply(a: A) = f(a) | |
} | |
case class Z(boz: String) |
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.Lens | |
object FocusOnScalaz { | |
// A pair of ordinary case classes ... | |
case class Address(street : String, city : String, postcode : String) | |
case class Person(name : String, age : Int, address : Address) | |
// Some lenses over Person/Address ... | |
val nameLens = Lens.lensu[Person, String]((u, newName) => u.copy(name = newName), _.name) |
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 TypeClassExample { | |
trait UnicodeOrdered[T] { | |
def ≤(i:T,j:T): Boolean | |
} | |
object UnicodeOrdered { | |
implicit object UnicodeOrderedInt extends UnicodeOrdered[Int] { | |
def ≤(i:Int,j:Int): Boolean = i <= j | |
} |
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 shapeless._, Poly._ | |
import scala.concurrent._, duration._, ExecutionContext.Implicits.global | |
object zoz extends Poly2 { | |
implicit def default[T, U] = at[T, T ⇒ U] { (acc, t) ⇒ t(acc) } | |
} | |
val f1 = (s: Future[String]) ⇒ s.map(1 :: _ :: HNil) | |
val f2 = (i: Future[Int :: String :: HNil]) ⇒ i.map(7L :: _) | |
val f3 = (l: Future[Long :: Int :: String :: HNil]) ⇒ l.map('z' :: _) |
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
S.configAll({ | |
"defaultToCurrentScreen" : true, | |
"secondsBetweenRepeat" : 0.05, | |
"checkDefaultsOnLoad" : true, | |
"focusCheckWidthMax" : 3000, | |
"windowHintsBackgroundColor" : [50, 53, 58, 0.73], | |
"windowHintsDuration" : 7, | |
"windowHintsWidth" : 65, | |
"windowHintsHeight" : 65, | |
"windowHintsFontSize" : 36 |
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.concurrent._, ExecutionContext.Implicits.global | |
import scala.async.Async.{async, await} | |
object AsyncExploration { | |
// hmm, monad transformers are cool and all but for this simple case async might be the winner | |
val α = | |
async { | |
for { |
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
let rec i j = match j with | |
| [] | [_] -> true | |
| a :: b :: c -> a = b && i(b::c);; |
OlderNewer