danbroooks danbroooks - 28 days ago 9
Scala Question

Scala - identifier expected but '=>' found

I'm writing an endpoint in a play scala application that makes a request to spotify, searching across

track
,
album
and
artist
types. I want to make over them and transform the string's into
Future
's of the calls.

This is my code:

def index = Action.async { implicit request =>
val futures = List("track", "album", "artist")
.map { type => performSearch("q" -> param(request, "q"), "type" -> type) }

Future.sequence(futures).onComplete {
Ok
}
}

private def performSearch(criteria: (String, String)): Future = {
ws.url("https://api.spotify.com/v1/search")
.withQueryString(criteria)
.get()
}

private def param(request: Request[AnyContent], name: String): String = {
request.queryString.get(name).flatMap(_.headOption).getOrElse("")
}


However I'm getting the error in my map of:


identifier expected but '=>' found
// .map { type => performSearch("q" -> param(request, "q"), "type" -> type) }

Answer

type is a keyword. Pick something else or put it inside `:

    .map { `type` => performSearch("q" -> param(request, "q"), "type" -> `type`) }