1

I have done C/Java/C3/Python/JS all my life. Since yesterday I am looking at some scala code, now i m super confused about everything..

The snippet goes:

// Parse the input file
  val lines = fromTextFile(input)

    // Iterate on every element to generate the keys, and then aggregate it
  val counts = lines.mapFlatten{
        line =>
        val rowSplit = line.split(",",-1)

.... }

the signature of the method mapFlatten in scoobi api is :

def mapFlatten[B](f: (A) ⇒ Iterable[B])(implicit arg0: WireFormat[B]): DList[B]

Why do we call mapFlatten with

  • mapFlatten{

instead of

  • mapFlatten({

Is it because the function is taking a predicate as a paramater?

in this sense, are while, else, if functions too?

Orkun
  • 6,998
  • 8
  • 56
  • 103

2 Answers2

1

According to this answer

Why use curly braces over parentheses?

there are cases when you do need to use curl braces(multiline expressions) and cases when you don't.

Indeed, they are all functions that receive functions inside.

In this situation:

def mapFlatten[B](f: (A) ⇒ Iterable[B])(implicit arg0: WireFormat[B]): DList[B]

You pass a function f:(A) that should result in Iterable[B]

Community
  • 1
  • 1
Thiago Pereira
  • 1,724
  • 1
  • 17
  • 31
1

From Programing in Scala, Fist Edition, Version 7 (yeah, a little dated):

In any method invocation in Scala in which you're passing in exactly one argument, you can opt to use curly braces to surround the argument instead of parentheses.

And then later:

The purpose of this ability ... is to enable client programmers to write function literals between curly braces. This can make the method call feel more like a control abstraction.

jwvh
  • 50,871
  • 7
  • 38
  • 64
  • horrible.. just standardize these things already.. :) anyway, thanks for the answer. i had read this smwhere, i couldnT make sense of it. – Orkun Jun 11 '15 at 15:24