Going through a tutorial on Spray, I encountered this:
entity(as[Quiz]) { quiz => requestContext =>
val responder = createResponder(requestContext)
createQuiz(quiz) match {
case true => responder ! QuizCreated
case _ => responder ! QuizAlreadyExists
}
}
This specific line is where the confusion lies:
entity(as[Quiz]) { quiz => requestContext =>
What in the world is with the second =>
sign??? What does this syntax mean and where can I find the documentation for further reading??
If I put the parenthesis like this, does it make more sense?
entity(as[Quiz]) { quiz => (requestContext =>
...
)
}
}
This is just a curried function with two arguments, and mechanically it is a function that returns another function. Example:
val test: Int => Int => Int = a => b => a + b // the same as a => (b => a + b)
println(test(2)(3)) //5
You can think of it as (a, b) => a + b
, but with the added benefit so you can partially apply it easier:
val t: Int => Int = test(2)
println(t(3)) // 5
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments