1 | class Program |
---|
2 | shared |
---|
3 | def createEmptyStream<of T> as T* |
---|
4 | return T[](0) |
---|
5 | |
---|
6 | def numbered<of T>(a as T*) as KeyValuePair<of int, T>* |
---|
7 | i = 0 |
---|
8 | for item in a |
---|
9 | yield KeyValuePair<of int, T>(i, item) |
---|
10 | i += 1 |
---|
11 | |
---|
12 | def reverse<of T>(a as T*) as T* |
---|
13 | return System.Linq.Enumerable.reverse<of T>(a) to ! |
---|
14 | |
---|
15 | def concat<of T>(a as T*, b as T*) as T* |
---|
16 | return System.Linq.Enumerable.concat<of T>(a, b) to ! |
---|
17 | |
---|
18 | def example0 |
---|
19 | a = [1, 2, 3] |
---|
20 | b = .reverse<of int>(a) |
---|
21 | print "source", a |
---|
22 | print "reverse", b |
---|
23 | print |
---|
24 | |
---|
25 | def example1<of T> |
---|
26 | x = .createEmptyStream<of T> |
---|
27 | n = 0 |
---|
28 | for i in x |
---|
29 | n += 1 |
---|
30 | print "empty stream:", x, "count:", n |
---|
31 | print |
---|
32 | |
---|
33 | def example2<of T>(a as T*) |
---|
34 | b = .reverse<of T>(a) |
---|
35 | c = .concat<of T>(a, b) |
---|
36 | d = .numbered<of T>(c) |
---|
37 | print "source:", a |
---|
38 | print "reverse:", b |
---|
39 | print "concat:", c |
---|
40 | print "numbered:", d |
---|
41 | print |
---|
42 | |
---|
43 | def main |
---|
44 | .example0 |
---|
45 | .example1<of int> |
---|
46 | .example2<of int>([1, 2, 3]) |
---|
47 | .example2<of String>(['a', 'b', 'c']) |
---|