-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathList.strict
127 lines (127 loc) · 2.96 KB
/
List.strict
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
has iterator
has elements Generics
to Text
Numbers to Text is ""
(1, 2) to Text is "(1, 2)"
GetElementsText.SurroundWithParentheses
GetElementsText Text
(1, 3).GetElementsText is "1, 3"
for elements
(index is 0 ? "" else ", ") + value
for Iterator
for (1, 2, 3) is (1, 2, 3)
elements
Length Number
(1, 2).Length is 2
elements.Length
is(other) Boolean
(1, 2) is (1, 2)
(1, 2, 3) is not (1, 2)
elements is other.elements
+(other) List
(1, 2, 3) + (4, 5) is (1, 2, 3, 4, 5)
("Hello", "World") + (1, 2) is ("Hello", "World", "1", "2")
("1", "2") + (3, 4) is ("1", "2", "3", "4")
("1", "2") to Numbers + (3, 4) is ("1", "2", "3", "4")
("3", "4") + (1, 2) to Text is ("3", "4", "(1, 2)")
("3", "4") + (1, 2) to Texts is ("3", "4", "1", "2")
(1 + 2) * 3 is not 1 + 2 * 3
(("1", "2") + (3, 4)) to Numbers is (1, 2, 3, 4)
3 + (4) is (3, 4)
(1) + ("Hi") is Error("Cannot downcast Texts to fit to Numbers")
elements + other.elements
+(addElement Generic) List
(1, 2, 3) + 4 is (1, 2, 3, 4)
("Hello", "World") + 5 is ("Hello", "World", "5")
elements + addElement
-(other) List
(1, 2, 3) - (3) is (1, 2)
elements - other.elements
-(removeElement Generic) List
(1, 2, 3) - 3 is (1, 2)
(1, 2, 3) - 4 is (1, 2, 3)
elements - removeElement
/(other) List
(2, 4, 6) / (2) is (1, 2, 3)
(1, 2) / (2, 4) is (0.5, 0.5)
(1) / (20, 10) is (0.05, 0.1)
elements / other.elements
/(divider Generic) List
(2, 4, 6) / 2 is (1, 2, 3)
(20, 10) / 1 is (0.05, 0.1)
elements / divider
*(other) List
(1, 2) * (3, 5) is (3, 10)
constant listsHaveDifferentDimensions = Error
(1) * (1, 2) is listsHaveDifferentDimensions
if Length is not other.Length
listsHaveDifferentDimensions
elements * other.elements
*(multiplier Generic) List
(1, 2) * 3 is (3, 6)
elements * multiplier
Sum Generic
(1, 2, 3).Sum is 6
for elements
+ value
X Generic
(1, 2, 3).X is 1
().X is Error
elements(0)
Y Generic
(1, 2).Y is 2
(1).Y is Error
elements(1)
Z Generic
(1, 2, 3).Z is 3
(1, 2).Z is Error
elements(2)
W Generic
(1, 2, 3, 4).W is 4
(1, 2, 3).W is Error
elements(3)
First Generic
(1, 2, 3).First is 1
elements(0)
Last Generic
(1, 2, 3).Last is 3
elements(-1)
in(other) Boolean
3 is in (1, 2, 3)
3 is not in (1, 2)
5 is not in (1, 8)
5 is in (11, 7, 5, 3, 2)
"b" is in ("a", "b", "c")
"d" is not in ("a", "b", "c")
for elements
if value is other
return true
false
Index(other Generic) Number
(1, 2, 3).Index(2) is 1
(1, 2, 3).Index(9) is -1
for elements
if value is other
return index
-1
Add(element Generic) Mutable(List)
mutable someList = List(Mutable(Number))
someList.Add(1)
someList.Add(2)
someList is (1, 2)
someList(0) = 5
someList is (5, 2)
someList.Add(3) is (5, 2, 3)
value = value + element
Remove(element Generic) Mutable(List)
(1, 2, 3).Remove(2) is (1, 3)
value = value - element
Count(element Generic) Number
(1, 2).Count(1) is 1
(1, 3).Count(2) is 0
("Hi", "Hello", "Hi").Count("Hi") is 2
mutable count = 0
for elements
if element is value
count.Increment
count