Skip to content

Instantly share code, notes, and snippets.

@matt-martin
matt-martin / TailRecursion.scala
Created August 12, 2015 23:55
An example of how tail recursion avoids stack overflow errors
// based on https://github.com/matt-martin/fpinscala/blob/05cd5a2b288677ebc67d258fcfb9c06b63052314/exercises/src/main/scala/fpinscala/datastructures/List.scala#L11
def sumNonTailRecursive(ints: List[Int]): Int = ints match {
case Nil => 0
case x :: xs => x + sumNonTailRecursive(xs)
}
@annotation.tailrec
def sumTailRecursiveHelper(ints: List[Int], sumSoFar: Int): Int = ints match {
case Nil => sumSoFar
case x :: xs => sumTailRecursiveHelper(xs, sumSoFar + x)
@matt-martin
matt-martin / keybase.md
Last active February 28, 2016 20:10
keybase.md

Keybase proof

I hereby claim:

  • I am matt-martin on github.
  • I am mattbmartin (https://keybase.io/mattbmartin) on keybase.
  • I have a public key ASAO3e7-fSFUvUVgVopHxOALRXdcjhxAbUPEV6rvlBlNEQo

To claim this, I am signing this object:

@matt-martin
matt-martin / hlist_to_list.scala
Created March 29, 2015 01:06
Why do these implicits only work for single element HLists?
implicit def hNilToList[L <: HNil](l : L) : List[Any] = Nil
implicit def hListToList[H <: Any, T <: HList](l : H :: T)(implicit conv : T => List[Any]) : List[Any] = {
l.head :: conv(l.tail)
}
hListToList("foo" :: HNil)
//res23: List[Any] = List(foo)
hListToList("foo" :: "bar" :: HNil)
@matt-martin
matt-martin / fun_with_scalding_and_shapeless.scala
Last active August 29, 2015 14:17
HList TupleConverter for Scalding
import shapeless._
import shapeless.ops.hlist._
import shapeless.ops.nat._
import cascading.tuple.{Tuple, TupleEntry}
import com.twitter.scalding._
// documentation for cascading:
// http://docs.cascading.org/cascading/2.5/javadoc/cascading/tuple/TupleEntry.html
@matt-martin
matt-martin / 3.0.0-wip-57-fast-planner-stats.txt
Last active August 29, 2015 14:07
Slow compilation in scalding job
cascading version: 3.0.0, build: wip-57
application id: 843F17CE3594477D8C5E536EA2FC4CDE
application name:
application version:
platform: local:3.0.0-wip-57:Concurrent, Inc.
frameworks:
duration 2.114
PreBalanceAssembly 0.553