What does ampersand between functions mean in Scala
Asked Answered
C

2

7

I've encountered a strange piece of syntax in Scala, could someone explain it to me what does ampersand mean when aplied bettween functions that are passed as argument to other function?

partialUpdate {
    SetHtml(currentAmountId,
    Text(leadingBid.toString)) &
    SetHtml(nextAmountId,
    Text(minimumBid.toString)) &
    SetHtml(winningCustomerId, winningCustomer) &
    SetValueAndFocus(amountId,"")
}

Thank you for explaining this one to me.

Cliffcliffes answered 25/1, 2012 at 14:17 Comment(1)
Is this related to Lift? If so, please make this clear in your question and maybe the title. This does not seem to be in the scala standard library.Agnosia
Q
12

& is a method on JsCmd in the Lift framework that concatenates two commands. It won't work on normal Scala strings.

Quaquaversal answered 25/1, 2012 at 14:41 Comment(0)
C
1

In this case, it looks like it's concatenating the output of the SetHtml calls.

Does it look clearer like this?

partialUpdate {
    SetHtml(currentAmountId, Text(leadingBid.toString)) &
    SetHtml(nextAmountId, Text(minimumBid.toString)) &
    SetHtml(winningCustomerId, winningCustomer) &
    SetValueAndFocus(amountId,"")
}
Contrite answered 25/1, 2012 at 14:24 Comment(2)
No. & is a method of whatever is returned by SetHtml. If it's a String, then it's a method added by an implicit. This is the problem with implicits and overator overloading.Habitable
@Chocos: tastes vary of course, but in my opinion Lift does a pretty good job of providing clean syntax without the massively obscure behind-the-scenes machinery of something like Specs2, for example. You might need to spend a little more time up front with the documentation, but it's arguably worth it.Quaquaversal

© 2022 - 2024 — McMap. All rights reserved.