-
Notifications
You must be signed in to change notification settings - Fork 1
/
X06_StringInterpolation.sc
49 lines (42 loc) · 1.28 KB
/
X06_StringInterpolation.sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/** StringInterpolation */
// https://docs.scala-lang.org/overviews/core/string-interpolation.html
// https://alvinalexander.com/scala/scala-class-object-function-convert-multiline-string-to-list-seq
object Q {
def apply(s: String): Seq[String] =
s.split("\n").toSeq.map(_.trim).filter(_ != "")
}
val list = Q("""
http://angel.co/mile-high-organics
http://angel.co/kindara
http://angel.co/precog
http://angel.co/pivotdesk
""")
implicit class QHelper(val sc: StringContext) {
def Q(args: Any*): Seq[String] = {
val strings = sc.parts.iterator.toSeq
var buf = strings.map { s => pprint.log(s); s }.mkString("\n")
buf.toString.split("\n").toSeq.map(_.trim).filter(_ != "")
}
}
val list = Q"""
http://angel.co/mile-high-organics
http://angel.co/kindara
http://angel.co/precog
http://angel.co/pivotdesk
"""
implicit class JsonHelper(val sc: StringContext) extends AnyVal {
def json(args: Any*): ujson.Value = {
val strings = sc.parts.iterator
val expressions = args.iterator
var buf = new StringBuffer(strings.next)
while (strings.hasNext) {
buf append expressions.next
buf append strings.next
}
pprint.log(buf)
ujson.read(buf)
}
}
val name = "dyno"
val id = "dynofu"
json"""{ "name": "$name", "id": "$id" }"""