Alejandro Lujan introduces us to String Interpolation, a feature of Scala that allows us to have placeholders inside of string definitions, and explains why you would want to use them. Video included!
3. WHY?
"Hello " + user + ", the
time is " + now + better
hurry up!"
4. An
example
import System.{currentTimeMillis => now}
val user = "Kevin”
val m = "Hello " + user + ", the time is " + now +
better hurry up!"
// Hello Kevin, the time is 1429017560259
better hurry up!
5. Enter
string
interpola-on
import System.{currentTimeMillis => now}
val user = "Kevin”
val m = s"Hello $user, the time is $now better
hurry up!"
// Hello Kevin, the time is 1429017560259
better hurry up
6. Built-‐in
interpolators
s"Simple string interpolation, $user"
f"Formatted interpolation: $balance%5.2f"
raw"Raw respects t escaped n literals"
7. Slick
implements
interpolators
sql"select * from books where id = $id"
sqlu"""
delete from products
where expiration > $date
"""