forked from jponge/golo-devoxx13-demos
-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo-5.golo
48 lines (40 loc) · 972 Bytes
/
demo-5.golo
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
module data
function main = |args| {
# All literals
let data = [
[1, 2, 3],
tuple[1, 2, 3],
array[1, 2, 3],
set[1, 2, 3, 3, 1],
map[
["a", 10],
["b", 20]
],
vector[1, 2, 3],
list[1, 2, 3]
]
# Dump!
data: each(|element| {
println(element: toString())
println(" type: " + element: getClass())
})
readln("Next when ready...")
# Data model
let contacts = map[
["mrbean", map[
["email", "[email protected]"],
["url", "http://mrbean.com"]
]],
["larry", map[
["email", "[email protected]"]
]]
]
# MrBean and Larry
let mrbean = contacts: get("mrbean")
let larry = contacts: get("larry")
# Illustrates orIfNull
println(mrbean: get("url") orIfNull "n/a")
println(larry: get("url") orIfNull "n/a")
# Querying a non-existent data model because there is no 'address' entry
println(mrbean: get("address")?: street()?: number() orIfNull "n/a")
}