Why can the parameter in this predicate be omitted?

Viewed 74

I just stumbled over this line in the play2-auth samples:

val remember = request.tags.get("rememberme").exists("true" ==) || //...

I understand what it does (check whether the map tags contains the mapping "rememberme" -> "true"), however I found the predicate in exists() interesting and have never seen one written in this way.

After testing this a bit in the REPL I came to the conclusion that it has the same meaning as

.exists("true" == _)
// or even longer:
.exists(s => "true" == s)

This notation apparently also works with other single argument functions, not just predicates:

scala> Some("world").map("Hello " +)
res0: Option[String] = Some(Hello world)

Why can the parameter here be omitted? Ultimately it seems to save one character, the underscore. It seems a bit odd to me to introduce a language feature just for that. Is there some bigger picture related to this?

1 Answers
Related