21 | | extend String |
22 | | |
23 | | def split(chars as List<of char>) as List<of String> |
24 | | test |
25 | | s = 'a,b:c:d,e,f' |
26 | | assert s.split([c',', c':']) == ['a', 'b', 'c', 'd', 'e', 'f'] |
27 | | |
28 | | def split(chars as IList<of char>) as List<of String> |
| 21 | extend String |
| 22 | |
| 23 | def split(chars as List<of char>) as List<of String> |
| 24 | test |
| 25 | s = 'a,b:c:d,e,f' |
| 26 | assert s.split([c',', c':']) == ['a', 'b', 'c', 'd', 'e', 'f'] |
| 27 | |
| 28 | def split(chars as IList<of char>) as List<of String> |
49 | | extend IList<of T> |
50 | | |
51 | | def get(flexibleIndex as int) as T |
52 | | require |
53 | | .count > 0 |
54 | | (flexibleIndex >= 0 and flexibleIndex < .count) _ |
55 | | or (flexibleIndex < 0 and flexibleIndex >= -.count) |
56 | | |
57 | | def get(flexibleIndex as int, default as T) as T |
58 | | ensure |
59 | | .count == 0 implies result == default |
60 | | (flexibleIndex > .count or flexibleIndex < -.count) _ |
61 | | implies result == default |
62 | | |
63 | | def last as T |
64 | | """ |
65 | | Returns the last element in the list. |
66 | | """ |
67 | | require .count > 0 |
68 | | |
69 | | def numbered as KeyValuePair<of int, T>* |
70 | | """ |
71 | | Returns a stream of pairs of (index, value). |
72 | | Can be used like so: |
73 | | for i, value in someList.numbered |
74 | | ... |
75 | | """ |
76 | | |
77 | | def reversed as List<of T> |
78 | | ensure |
79 | | result is not this |
80 | | result.count == .count |
81 | | |
82 | | def sorted as List<of T> |
83 | | ensure |
84 | | result is not this |
85 | | result.count == .count |
86 | | |
87 | | def sorted(comparison as Comparison<of T>) as List<of T> |
88 | | ensure |
89 | | result is not this |
90 | | result.count == .count |
91 | | |
92 | | def sorted(comparer as Comparer<of T>) as List<of T> |
93 | | ensure |
94 | | result is not this |
95 | | result.count == .count |
96 | | |
97 | | def swap(i as int, j as int) |
98 | | """ |
99 | | Swaps the elements at the given indexes which can be negative to index from the end of the |
100 | | list towards the front (-1 is last element, -2 is second to last, etc.). |
101 | | """ |
102 | | require |
103 | | i >= -.count and i < .count |
104 | | j >= -.count and j < .count |
105 | | ensure |
106 | | old this[i] == this[j] |
107 | | old this[j] == this[i] |
108 | | .count == old.count |
| 49 | extend IList<of T> |
| 50 | |
| 51 | def get(flexibleIndex as int) as T |
| 52 | require |
| 53 | .count > 0 |
| 54 | (flexibleIndex >= 0 and flexibleIndex < .count) _ |
| 55 | or (flexibleIndex < 0 and flexibleIndex >= -.count) |
| 56 | |
| 57 | def get(flexibleIndex as int, default as T) as T |
| 58 | ensure |
| 59 | .count == 0 implies result == default |
| 60 | (flexibleIndex > .count or flexibleIndex < -.count) _ |
| 61 | implies result == default |
| 62 | |
| 63 | def last as T |
| 64 | """ |
| 65 | Returns the last element in the list. |
| 66 | """ |
| 67 | require .count > 0 |
| 68 | |
| 69 | def numbered as KeyValuePair<of int, T>* |
| 70 | """ |
| 71 | Returns a stream of pairs of (index, value). |
| 72 | Can be used like so: |
| 73 | for i, value in someList.numbered |
| 74 | ... |
| 75 | """ |
| 76 | |
| 77 | def reversed as List<of T> |
| 78 | ensure |
| 79 | result is not this |
| 80 | result.count == .count |
| 81 | |
| 82 | def sorted as List<of T> |
| 83 | ensure |
| 84 | result is not this |
| 85 | result.count == .count |
| 86 | |
| 87 | def sorted(comparison as Comparison<of T>) as List<of T> |
| 88 | ensure |
| 89 | result is not this |
| 90 | result.count == .count |
| 91 | |
| 92 | def sorted(comparer as Comparer<of T>) as List<of T> |
| 93 | ensure |
| 94 | result is not this |
| 95 | result.count == .count |
| 96 | |
| 97 | def swap(i as int, j as int) |
| 98 | """ |
| 99 | Swaps the elements at the given indexes which can be negative to index from the end of the |
| 100 | list towards the front (-1 is last element, -2 is second to last, etc.). |
| 101 | """ |
| 102 | require |
| 103 | i >= -.count and i < .count |
| 104 | j >= -.count and j < .count |
| 105 | ensure |
| 106 | old this[i] == this[j] |
| 107 | old this[j] == this[i] |
| 108 | .count == old.count |