code / tomo

Lines41.3K C23.7K Markdown9.7K YAML5.0K Tomo2.3K
7 others 763
Python231 Shell230 make212 INI47 Text21 SVG16 Lua6
(43 lines)
2 func all_nums(nums:[Int] -> Text)
3 result := ""
4 for num in nums
5 result ++= "$num,"
6 else
7 return "EMPTY"
8 return result
10 func labeled_nums(nums:[Int] -> Text)
11 result := ""
12 for i,num in nums
13 result ++= "$i:$num,"
14 else
15 return "EMPTY"
16 return result
18 func table_str(t:{Text:Text} -> Text)
19 str := ""
20 for k,v in t
21 str ++= "$k:$v,"
22 else return "EMPTY"
23 return str
25 func table_key_str(t:{Text:Text} -> Text)
26 str := ""
27 for k in t
28 str ++= "$k,"
29 else return "EMPTY"
30 return str
32 func main()
33 assert all_nums([10,20,30]) == "10,20,30,"
34 assert all_nums([]) == "EMPTY"
36 assert labeled_nums([10,20,30]) == "1:10,2:20,3:30,"
37 assert labeled_nums([]) == "EMPTY"
39 >> t := {"key1": "value1", "key2": "value2"}
40 assert table_str(t) == "key1:value1,key2:value2,"
41 assert table_str({}) == "EMPTY"
43 assert table_key_str(t) == "key1,key2,"