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
sealed trait TypeBoolean | |
sealed trait True extends TypeBoolean | |
sealed trait False extends TypeBoolean | |
trait Conditional{ | |
type Result <: TypeBoolean | |
} | |
abstract class TypePredicate2[A,B,Cond[_,_] <: Conditional,Implicit[_,_]] extends Conditional{ | |
implicit def pred[Child,Parent](implicit ev:Implicit[Child,Parent]):Cond[Child,Parent] |
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 Change[+A]{ | |
def map[B](f: A => B): Change[B] | |
def flatMap[B](f: A => Change[B]): Change[B] | |
def foreach(f: A => Unit): Unit | |
def filter(pred: A => Boolean): Change[A] | |
} | |
case class Reversible[+A](value: A, undo: List[Undo]) extends Change[A]{ | |
def map[B](f: A => B) = Reversible(f(value), undo) | |
def flatMap[B](f: A => Change[B]) = f(value) match{ |
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 Mapper[Elem,C[_]]{ | |
def onTrue(t: Elem => Elem): FilterTraversable[Elem,C] | |
def onFalse(f: Elem => Elem): FilterTraversable[Elem,C] | |
def on[A](f: Elem => Elem, t: Elem => Elem): FilterTraversable[Elem,C] | |
def apply(collection: C[Elem], condition: Elem => Boolean): C[Elem] | |
} | |
case class MapperIterable[Elem,I[_] <: Iterabable[_]](t: Elem => Elem, f: Elem => Elem) extends Mapper[Elem,I]{ | |
def onTrue(func: Elem => Elem) = copy(t = func) |
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 Query[-A,+B,Cont[_] <: Iterable[_]] extends (A => Try[Cont[B]]){ | |
self => | |
def apply(arg0: A) = Try(unsafe(arg0)) | |
protected def unsafe(arg0: A): Cont[B] | |
def map[C](f: B => C) = new Query[A,C,Cont]{ | |
def unsafe(arg0: A) = self unsafe arg0 map f | |
} |
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._ | |
import Poly._ | |
import TypeOperators._ | |
trait PredF extends (Id ~>> Boolean){ | |
self => | |
def apply[T](arg: T): Boolean | |
def or(that: Id ~>> Boolean) = new PredF{ |
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
asdf//In reality, this is all we need, no? | |
//See https://github.com/jsr107/jsr107spec | |
trait Cache[Key,Value]{ | |
def get(key: Key): Option[Key] | |
def getOrElse(key: Key, value: Value) = get(key) getOrElse value | |
def set(key: Key, value: Value): Value | |
def contains(key: Key): Boolean | |
def replace(key: Key, value: Value): Option[Value] ={ | |
val previous = get(key) | |
set(key, value) |
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
//Haven't even checked if this compiles | |
//Just an idea | |
trait TreeLike[A, This <: IterableLike[TreeLike[A, This], This]]{ | |
def root: A | |
def children: This | |
def map[B, That](f: A => B): TreeLike[A, That] = over(this, f).run | |
protected def over[B, That](tree: TreeLike[A, This], f: A => B): Trampoline[TreeLike[B, That]] = |
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 CTree[@specialized(Double) Value](root: Value, | |
children: Map[Int, ComputedTree[Value]] = Map.empty[Int, CTree[Value]]){ | |
def map[A](f: Value => A): ComputedTree[A] = walk(this, f).run | |
protected def walk[A](tree: CTree[Value], f: Value => A): Trampoline[CTree[A]] = tree match { | |
case CTree(value, childs) if childs.isEmpty => done(CTree(f(value))) | |
case CTree(value, childs) => step(childs.toList, f) map (CTree(f(value), _)) | |
} |
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
var Bullet = { | |
orient: function(arg){ | |
this.chart = this.chart.orient(arg); | |
return this; | |
}, | |
ranges: function(arg){ | |
this.chart = this.chart.ranges(arg); | |
return this; | |
}, | |
markers: function(arg){ |
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
//Assumes jQuery, produces a lazy load template function. | |
var Template = function(el){ | |
var $el = $(el), | |
template = undefined; | |
//Compile template and store once. | |
return function(args){ | |
if(!template){ | |
template = Handlebars.compile($el.html()); | |
} |
OlderNewer