Skip to content

Instantly share code, notes, and snippets.

@jmhodges
Created May 9, 2009 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmhodges/109129 to your computer and use it in GitHub Desktop.
Save jmhodges/109129 to your computer and use it in GitHub Desktop.
implicit def clipMinArrayWrapper[A <% Ordered[A]](x: Array[A]) = new {
private def smaller[B <% Ordered[B]](p: B, q: B) : B = {
if (p < q) return(p) else return(q)
}
def min() : A = {
min((p) => p)
}
def min[B <% Ordered[B]](f: A => B) : B = {
return x.slice(1,x.length).foldLeft(f(x(0)))((p,q) => smaller(p, f(q)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment