This is the list I compiled during this time:
1) Type resolution for multiple argument lists
class ResourceManager { type Resource def open: Resource = ??? } class ResourceManagerTest { // Does not compile: def test1(rm: ResourceManager, r: rm.Resource) = ??? // Compiles: This way the type can be resolved def test2(rm: ResourceManager)(r: rm.Resource) = ??? }
2) Type inference where earlier arguments can "block" type parameters for later arguments (thanks to Myserious Dan)
def foo1[A](x: A, f: A => Int) = ??? def foo2[A](x: A)(f: A => Int) = ??? def foo1foo2Demo() { // This will always demand a type annotation on any anonymous function // you pass in: foo1(1, (i: Int) => i * i) // Does not compile: foo1(1, i => i * i) // Type not required foo2(2)(i => i * i) }
3) Language extensions with syntax
object MultipleArgumentListsDemo { // This style of function definition allows syntax-like language extensions @tailrec def myWhile(conditional: => Boolean)(f: => Unit) { if (conditional) { f myWhile(conditional)(f) } } def myWhileDemo() { var count = 0 myWhile(count < 5) { count += 1 println(count) } }
4) Having both implicit and implicit arguments , since implicit is a modifier for the entire list of arguments:
def f[A](x: A)(implicit mf: Manifest[A]) { }
5) A parameter value from one parameter list can be used to calculate the default value in another parameter list, but not in the same one.
def g(x: Int)(y: Int = x * 2) = { x + y }
6) Multiple repeated argument lists ("varargs")
def h(as: Int*)(bs: Int*)(cs: Int*) = as.sum * bs.sum * cs.sum
7) Partial application
def i() { val foop = h(1, 2, 3)(4, 5, 6, 7, 9) _ println(foop(Seq(10, 11))) }
Since I did not track my sources while I was compiling this list over time: it is possible that some or all of the examples are copied from other sources (other questions on SO), so please leave a note and I will add a link from where it came from.