Need help understanding usage ->, {} and () in this code

Here is the code snippet in question:

val oauth_params = IMap(
      "oauth_consumer_key" -> consumer.key,
      "oauth_signature_method" -> "HMAC-SHA1",
      "oauth_timestamp" -> (System.currentTimeMillis / 1000).toString,
      "oauth_nonce" -> System.nanoTime.toString
    ) ++ token.map { "oauth_token" -> _.value } ++
      verifier.map { "oauth_verifier" -> _ }

Question 1: Which Scala function is included "oauth_consumer_key" -> consumer.keyfor existence and passed as arguments?

Question 2: Viewing val oauth_params = IMap(...)and token.map {...}in which operations is used {}to transfer values, and not ordinary ()? Are there special rules? And why does the loop forallow the use of both if this is a related issue?

I ask here when I see which functions are used elsewhere. I also believe that both issues are related.

+5
source share
1 answer

OK:

-> Predef.scala, Scala :

final class ArrowAssoc[A](val x: A) {
  @inline def -> [B](y: B): Tuple2[A, B] = Tuple2(x, y)
  def โ†’[B](y: B): Tuple2[A, B] = ->(y)
}
implicit def any2ArrowAssoc[A](x: A): ArrowAssoc[A] = new ArrowAssoc(x)

, , ArrowAssoc [A], โ†’ [B], Tuple2 [A, B].

IMap (...) IMap.apply(...): Scala, , . factory Scala

class MyClass(....) {

}
object MyClass{ 
   def apply(....): MyClass = new MyClass(....)
}

val a = MyClass(a,b,c)

, , Scala : , , ,

, . : List(1,2,3).map ( x => x * 2).() {} Scala case.

+7

All Articles