zipWithIndex makes looping in Scala fun

December 23rd, 2017 | #scala #playframework

TIL how to use zipWithIndex in Scala.

@for((element, index) <- list.zipWithIndex) {
    <p>index @index is element @element</p>
}
Read more

Use Scala match expression in Play Scala template

November 6th, 2017 | #scala #playframework #html

TIL how to use Scala match expression in a Play Scala template.

@badgeColor(subscription: String) = {
    @subscription match {
        case "Authorised" => { primary }
        case "Pending" => { secondary }
        case "Confirmed" | "Paid out" => { success }
        case "Failed" | "Cancelled" => { danger }
        case "Expired" => { warning }
        case "Charged back" => { info }
        case _ => { @* applies also if "Open" *@ light }
    }
}
Read more

© 2018 Tonny Garić | With from Nijmegen, The Netherlands