Skip to content

Instantly share code, notes, and snippets.

@nickmoorman
Created August 18, 2014 21:02
Show Gist options
  • Save nickmoorman/610b8164ec4b2e07bf99 to your computer and use it in GitHub Desktop.
Save nickmoorman/610b8164ec4b2e07bf99 to your computer and use it in GitHub Desktop.
Just... -_-
// Define array and a function to return the max of two numbers
val arr = Array(1, 2, 3, 4, 5)
def getMax(a :Int, b :Int) : Int = if (a > b) a else b
// Use foldLeft to find the max in the array
val max1 = (Integer.MIN_VALUE /: arr) { (large, elem) => getMax(large, elem) }
// No need to use sensible variable names, just use underscores!
val max2 = (Integer.MIN_VALUE /: arr) { getMax(_, _) }
// But wait, you can pass all the arguments at the same time!
val max3 = (Integer.MIN_VALUE /: arr) { getMax _ }
// Or fuck it, don't pass anything, and it magically works anyway!
val max4 = (Integer.MIN_VALUE /: arr) { getMax }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment