Christian Yonathan S. Christian Yonathan S. - 3 months ago 8
Scala Question

what is the different between map{} with map()




im newbie on scala, from this link
http://spark.apache.org/docs/latest/mllib-collaborative-filtering.html



what is the different between map{} with map()


val ratings = data.map(_.split(',') match { case Array(user, item, rate) =>
Rating(user.toInt, item.toInt, rate.toDouble)
})

val usersProducts = ratings.map { case Rating(user, product, rate) =>
(user, product)
}

Answer
val a = list.map(_.split(','))

// the above is a shorthand for
val a = list.map({ case _ => _.split(',') })

// Now lets consider this
val a = list.map { case (a, b) => a + b }

// or this
val a = list map { case (a, b) => a + b }

// some people like the above ways of writing
// because they consider of less brackets as cleaner code.
// but the above two are another way to write
val a = list.map({ case (a, b) => a + b })
Comments