Skip to content

Instantly share code, notes, and snippets.

View Refefer's full-sized avatar

Andrew Stanton Refefer

  • San Francisco
View GitHub Profile
for {
(k, v) <- tiers
n <- filteredData if (n \ "metricPath").text.contains(v)
} yield k -> bts.filter(n \ "metricPath".text.contains).foldLeft(List[Transaction]()) {
case (agg, bt) => {
val trans = Transaction(bt, k)
trans.metricData = Metric(n)
bt :: agg
}
}
def fib: Stream[Int] = {
def loop(i:Int, j:Int):Stream[Int] = {
j #:: loop(j, i+j)
}
loop(1,1)
}
def loopOver(xs: List[Int]) = {
val vs = xs.toStream
def loop(rem:Int):Stream[Stream[Int]] = rem match {
case 0 => for(v <- vs) yield Stream(v)
case n => for(head <- vs; tails <- loop(n-1)) yield head #:: tails
}
for(i <- Stream.from(0); items <- loop(i)) yield items
}
@Refefer
Refefer / GetTC.scala
Last active December 18, 2015 23:29
Unifying to a type class across view bounds and subtyping
trait GetTC[A,B,T[_]] {
type C
implicit def aToC(a:A):C
implicit def bToC(b:B):C
def get: T[C]
}
trait LowPriorityGetTC {
implicit def getTC1[A,B,T[_]](implicit ac: A => B, tc:T[B]) = new GetTC[A,B,T] {
type C = B