Skip to content

Instantly share code, notes, and snippets.

@tixxit
Created April 3, 2013 02:46
Show Gist options
  • Save tixxit/5298038 to your computer and use it in GitHub Desktop.
Save tixxit/5298038 to your computer and use it in GitHub Desktop.
import shapeless._
final class AnyRefCounter[L <: HList, N <: Nat]
object AnyRefCounter {
implicit def empty = new AnyRefCounter[HNil, Nat._0]
implicit def anyRef[H <: AnyRef, T <: HList, N <: Nat](implicit c: AnyRefCounter[T, N]) = new AnyRefCounter[H :: T, Succ[N]]
implicit def anyVal[H <: AnyVal, T <: HList, N <: Nat](implicit c: AnyRefCounter[T, N]) = new AnyRefCounter[H :: T, N]
def countRefs[L <: HList, N <: Nat](xs: L)(implicit c: AnyRefCounter[L, N], n: ToInt[N]): Int = n()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment