trackler 2.1.0.36 → 2.1.0.37
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/common/CONTRIBUTING.md +1 -1
- data/lib/trackler/version.rb +1 -1
- data/lib/trackler.rb +0 -5
- data/tracks/c/config.json +0 -5
- data/tracks/clojure/config.json +177 -59
- data/tracks/clojure/exercises/kindergarten-garden/src/example.clj +10 -8
- data/tracks/elisp/config.json +60 -24
- data/tracks/elixir/exercises/poker/poker_test.exs +1 -1
- data/tracks/fortran/config.json +6 -0
- data/tracks/fortran/exercises/pangram/example.f90 +33 -0
- data/tracks/fortran/exercises/pangram/pangram.fun +42 -0
- data/tracks/go/config.json +10 -4
- data/tracks/go/exercises/acronym/acronym.go +1 -1
- data/tracks/groovy/{SETUP.md → docs/EXERCISE_README_INSERT.md} +0 -0
- data/tracks/haskell/config.json +1 -1
- data/tracks/java/bin/journey-test.sh +3 -0
- data/tracks/java/config.json +14 -14
- data/tracks/java/exercises/binary-search/src/test/java/BinarySearchTest.java +20 -20
- data/tracks/java/exercises/binary-search-tree/src/test/java/BSTTest.java +32 -32
- data/tracks/java/exercises/build.gradle +57 -31
- data/tracks/java/exercises/hello-world/GETTING_STARTED.md +4 -0
- data/tracks/java/exercises/pythagorean-triplet/src/test/java/PythagoreanTripletTest.java +8 -8
- data/tracks/java/exercises/scrabble-score/src/example/java/Scrabble.java +1 -1
- data/tracks/java/exercises/scrabble-score/src/test/java/ScrabbleScoreTest.java +10 -5
- data/tracks/java/exercises/series/src/test/java/SeriesTest.java +20 -20
- data/tracks/java/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/tracks/java/gradle/wrapper/gradle-wrapper.properties +2 -2
- data/tracks/julia/runtests.jl +1 -6
- data/tracks/kotlin/.gitignore +0 -5
- data/tracks/kotlin/.travis.yml +21 -1
- data/tracks/kotlin/bin/build-jq.sh +11 -0
- data/tracks/kotlin/bin/fetch-configlet +1 -1
- data/tracks/kotlin/bin/journey-test.sh +34 -14
- data/tracks/kotlin/bin/unit-tests.sh +2 -2
- data/tracks/kotlin/config.json +230 -160
- data/tracks/kotlin/exercises/build.gradle +3 -0
- data/tracks/kotlin/exercises/collatz-conjecture/src/test/kotlin/CollatzCalculatorTest.kt +7 -1
- data/tracks/kotlin/exercises/gradle.properties +1 -0
- data/tracks/kotlin/exercises/list-ops/HINTS.md +5 -0
- data/tracks/kotlin/exercises/list-ops/build.gradle +28 -0
- data/tracks/kotlin/exercises/list-ops/src/example/kotlin/CustomListExtensions.kt +43 -0
- data/tracks/kotlin/exercises/list-ops/src/main/kotlin/.keep +0 -0
- data/tracks/kotlin/exercises/list-ops/src/test/kotlin/ListExtensionsTest.kt +157 -0
- data/tracks/kotlin/exercises/settings.gradle +13 -12
- data/tracks/kotlin/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/tracks/kotlin/gradle/wrapper/gradle-wrapper.properties +6 -0
- data/tracks/kotlin/gradlew +172 -0
- data/tracks/kotlin/gradlew.bat +84 -0
- data/tracks/lfe/config.json +90 -30
- data/tracks/ocaml/.travis-ci.sh +1 -1
- data/tracks/ocaml/.travis.yml +1 -1
- data/tracks/ocaml/README.md +1 -1
- data/tracks/perl5/.travis.yml +3 -2
- data/tracks/perl6/bin/exercise-gen.pl6 +6 -3
- data/tracks/racket/config.json +63 -21
- data/tracks/ruby/exercises/bob/bob_test.rb +0 -1
- data/tracks/ruby/lib/generator/command_line.rb +7 -3
- data/tracks/ruby/lib/generator/exercise.rb +19 -0
- data/tracks/ruby/lib/generator/files/generator_cases.rb +0 -4
- data/tracks/ruby/lib/generator/files/metadata_files.rb +1 -1
- data/tracks/ruby/lib/generator/files/track_files.rb +3 -3
- data/tracks/ruby/lib/generator/implementation.rb +7 -11
- data/tracks/ruby/lib/generator/template_values.rb +5 -9
- data/tracks/ruby/lib/generator/underscore.rb +4 -0
- data/tracks/ruby/lib/generator.rb +2 -2
- data/tracks/ruby/test/fixtures/xruby/lib/generator/test_template.erb +3 -3
- data/tracks/ruby/test/generator/exercise_test.rb +20 -0
- data/tracks/ruby/test/generator/files/generate_cases_test.rb +0 -4
- data/tracks/ruby/test/generator/files/metadata_files_test.rb +2 -2
- data/tracks/ruby/test/generator/files/track_files_test.rb +4 -5
- data/tracks/ruby/test/generator/implementation_test.rb +12 -20
- data/tracks/ruby/test/generator/template_values_test.rb +2 -33
- data/tracks/ruby/test/generator/underscore_test.rb +4 -0
- data/tracks/ruby/test/generator_test.rb +2 -2
- data/tracks/rust/exercises/gigasecond/Cargo.lock +58 -13
- data/tracks/rust/exercises/gigasecond/Cargo.toml +1 -1
- data/tracks/scala/exercises/acronym/src/test/scala/AcronymTest.scala +32 -12
- data/tracks/scala/exercises/hamming/example.scala +1 -1
- data/tracks/scala/exercises/hamming/src/test/scala/HammingTest.scala +55 -19
- data/tracks/scala/exercises/phone-number/example.scala +10 -20
- data/tracks/scala/exercises/phone-number/src/test/scala/PhoneNumberTest.scala +28 -81
- data/tracks/scala/testgen/src/main/scala/AcronymTestGenerator.scala +16 -0
- data/tracks/scala/testgen/src/main/scala/HammingTestGenerator.scala +34 -0
- data/tracks/scala/testgen/src/main/scala/PhoneNumberTestGenerator.scala +34 -0
- data/tracks/scheme/config.json +43 -16
- metadata +21 -5
- data/lib/trackler/problem.rb +0 -7
- data/lib/trackler/problems.rb +0 -7
data/tracks/kotlin/config.json
CHANGED
@@ -4,15 +4,10 @@
|
|
4
4
|
"repository": "https://github.com/exercism/xkotlin",
|
5
5
|
"active": true,
|
6
6
|
"deprecated": [
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
"
|
11
|
-
"bin",
|
12
|
-
".gradle",
|
13
|
-
"docs",
|
14
|
-
"img",
|
15
|
-
"build"
|
7
|
+
"accumulate",
|
8
|
+
"binary",
|
9
|
+
"hexadecimal",
|
10
|
+
"strain"
|
16
11
|
],
|
17
12
|
"foregone": [
|
18
13
|
|
@@ -21,260 +16,335 @@
|
|
21
16
|
{
|
22
17
|
"difficulty": 1,
|
23
18
|
"slug": "hello-world",
|
24
|
-
"topics": [
|
25
|
-
|
26
|
-
|
27
|
-
"difficulty": 1,
|
28
|
-
"slug": "gigasecond",
|
29
|
-
"topics": []
|
19
|
+
"topics": [
|
20
|
+
|
21
|
+
]
|
30
22
|
},
|
31
23
|
{
|
32
|
-
"difficulty":
|
24
|
+
"difficulty": 2,
|
33
25
|
"slug": "rna-transcription",
|
34
|
-
"topics": [
|
26
|
+
"topics": [
|
27
|
+
|
28
|
+
]
|
35
29
|
},
|
36
30
|
{
|
37
|
-
"difficulty":
|
38
|
-
"slug": "
|
39
|
-
"topics": [
|
31
|
+
"difficulty": 3,
|
32
|
+
"slug": "pangram",
|
33
|
+
"topics": [
|
34
|
+
|
35
|
+
]
|
40
36
|
},
|
41
37
|
{
|
42
|
-
"difficulty":
|
43
|
-
"slug": "
|
44
|
-
"topics": [
|
38
|
+
"difficulty": 3,
|
39
|
+
"slug": "hamming",
|
40
|
+
"topics": [
|
41
|
+
|
42
|
+
]
|
45
43
|
},
|
46
44
|
{
|
47
|
-
"difficulty":
|
48
|
-
"slug": "
|
49
|
-
"topics": [
|
45
|
+
"difficulty": 3,
|
46
|
+
"slug": "gigasecond",
|
47
|
+
"topics": [
|
48
|
+
|
49
|
+
]
|
50
50
|
},
|
51
51
|
{
|
52
|
-
"difficulty":
|
53
|
-
"slug": "
|
54
|
-
"topics": [
|
52
|
+
"difficulty": 3,
|
53
|
+
"slug": "space-age",
|
54
|
+
"topics": [
|
55
|
+
|
56
|
+
]
|
55
57
|
},
|
56
58
|
{
|
57
|
-
"difficulty":
|
58
|
-
"slug": "
|
59
|
-
"topics": [
|
59
|
+
"difficulty": 3,
|
60
|
+
"slug": "acronym",
|
61
|
+
"topics": [
|
62
|
+
|
63
|
+
]
|
60
64
|
},
|
61
65
|
{
|
62
|
-
"difficulty":
|
63
|
-
"slug": "
|
64
|
-
"topics": [
|
66
|
+
"difficulty": 3,
|
67
|
+
"slug": "scrabble-score",
|
68
|
+
"topics": [
|
69
|
+
|
70
|
+
]
|
65
71
|
},
|
66
72
|
{
|
67
|
-
"difficulty":
|
68
|
-
"slug": "
|
69
|
-
"topics": [
|
73
|
+
"difficulty": 3,
|
74
|
+
"slug": "raindrops",
|
75
|
+
"topics": [
|
76
|
+
|
77
|
+
]
|
70
78
|
},
|
71
79
|
{
|
72
|
-
"difficulty":
|
73
|
-
"slug": "
|
74
|
-
"topics": [
|
80
|
+
"difficulty": 3,
|
81
|
+
"slug": "difference-of-squares",
|
82
|
+
"topics": [
|
83
|
+
|
84
|
+
]
|
75
85
|
},
|
76
86
|
{
|
77
|
-
"difficulty":
|
87
|
+
"difficulty": 3,
|
78
88
|
"slug": "perfect-numbers",
|
79
|
-
"topics": [
|
89
|
+
"topics": [
|
90
|
+
|
91
|
+
]
|
80
92
|
},
|
81
93
|
{
|
82
|
-
"difficulty":
|
83
|
-
"slug": "
|
84
|
-
"topics": [
|
94
|
+
"difficulty": 4,
|
95
|
+
"slug": "sum-of-multiples",
|
96
|
+
"topics": [
|
97
|
+
"Ranges",
|
98
|
+
"Collections",
|
99
|
+
"Lambdas"
|
100
|
+
]
|
85
101
|
},
|
86
102
|
{
|
87
|
-
"difficulty":
|
88
|
-
"slug": "
|
89
|
-
"topics": [
|
103
|
+
"difficulty": 4,
|
104
|
+
"slug": "luhn",
|
105
|
+
"topics": [
|
106
|
+
|
107
|
+
]
|
90
108
|
},
|
91
109
|
{
|
92
|
-
"difficulty":
|
93
|
-
"slug": "
|
94
|
-
"topics": [
|
110
|
+
"difficulty": 4,
|
111
|
+
"slug": "triangle",
|
112
|
+
"topics": [
|
113
|
+
|
114
|
+
]
|
95
115
|
},
|
96
116
|
{
|
97
|
-
"difficulty":
|
98
|
-
"slug": "
|
99
|
-
"topics": [
|
117
|
+
"difficulty": 4,
|
118
|
+
"slug": "largest-series-product",
|
119
|
+
"topics": [
|
120
|
+
|
121
|
+
]
|
100
122
|
},
|
101
123
|
{
|
102
|
-
"difficulty":
|
103
|
-
"slug": "
|
104
|
-
"topics": [
|
124
|
+
"difficulty": 4,
|
125
|
+
"slug": "sieve",
|
126
|
+
"topics": [
|
127
|
+
|
128
|
+
]
|
105
129
|
},
|
106
130
|
{
|
107
|
-
"difficulty":
|
108
|
-
"slug": "
|
109
|
-
"topics": [
|
131
|
+
"difficulty": 4,
|
132
|
+
"slug": "collatz-conjecture",
|
133
|
+
"topics": [
|
134
|
+
|
135
|
+
]
|
110
136
|
},
|
111
137
|
{
|
112
|
-
"difficulty":
|
113
|
-
"slug": "
|
114
|
-
"topics": [
|
138
|
+
"difficulty": 4,
|
139
|
+
"slug": "nth-prime",
|
140
|
+
"topics": [
|
141
|
+
|
142
|
+
]
|
115
143
|
},
|
116
144
|
{
|
117
|
-
"difficulty":
|
118
|
-
"slug": "
|
119
|
-
"topics": [
|
145
|
+
"difficulty": 4,
|
146
|
+
"slug": "diamond",
|
147
|
+
"topics": [
|
148
|
+
|
149
|
+
]
|
120
150
|
},
|
121
151
|
{
|
122
|
-
"difficulty":
|
123
|
-
"slug": "
|
124
|
-
"topics": [
|
152
|
+
"difficulty": 4,
|
153
|
+
"slug": "isogram",
|
154
|
+
"topics": [
|
155
|
+
|
156
|
+
]
|
125
157
|
},
|
126
158
|
{
|
127
|
-
"difficulty":
|
128
|
-
"slug": "
|
129
|
-
"topics": [
|
159
|
+
"difficulty": 5,
|
160
|
+
"slug": "flatten-array",
|
161
|
+
"topics": [
|
162
|
+
|
163
|
+
]
|
130
164
|
},
|
131
165
|
{
|
132
|
-
"difficulty":
|
133
|
-
"slug": "
|
134
|
-
"topics": [
|
166
|
+
"difficulty": 5,
|
167
|
+
"slug": "pig-latin",
|
168
|
+
"topics": [
|
169
|
+
|
170
|
+
]
|
135
171
|
},
|
136
172
|
{
|
137
|
-
"difficulty":
|
138
|
-
"slug": "
|
139
|
-
"topics": [
|
173
|
+
"difficulty": 5,
|
174
|
+
"slug": "phone-number",
|
175
|
+
"topics": [
|
176
|
+
|
177
|
+
]
|
140
178
|
},
|
141
179
|
{
|
142
|
-
"difficulty":
|
143
|
-
"slug": "
|
144
|
-
"topics": [
|
180
|
+
"difficulty": 5,
|
181
|
+
"slug": "nucleotide-count",
|
182
|
+
"topics": [
|
183
|
+
|
184
|
+
]
|
145
185
|
},
|
146
186
|
{
|
147
|
-
"difficulty":
|
148
|
-
"slug": "
|
149
|
-
"topics": [
|
187
|
+
"difficulty": 5,
|
188
|
+
"slug": "word-count",
|
189
|
+
"topics": [
|
190
|
+
|
191
|
+
]
|
150
192
|
},
|
151
193
|
{
|
152
|
-
"difficulty":
|
153
|
-
"slug": "
|
154
|
-
"topics": [
|
194
|
+
"difficulty": 5,
|
195
|
+
"slug": "robot-name",
|
196
|
+
"topics": [
|
197
|
+
|
198
|
+
]
|
155
199
|
},
|
156
200
|
{
|
157
|
-
"difficulty":
|
158
|
-
"slug": "
|
159
|
-
"topics": [
|
201
|
+
"difficulty": 5,
|
202
|
+
"slug": "allergies",
|
203
|
+
"topics": [
|
204
|
+
|
205
|
+
]
|
160
206
|
},
|
161
207
|
{
|
162
|
-
"difficulty":
|
163
|
-
"slug": "
|
164
|
-
"topics": [
|
208
|
+
"difficulty": 5,
|
209
|
+
"slug": "bob",
|
210
|
+
"topics": [
|
211
|
+
|
212
|
+
]
|
165
213
|
},
|
166
214
|
{
|
167
|
-
"difficulty":
|
168
|
-
"slug": "
|
169
|
-
"topics": [
|
215
|
+
"difficulty": 5,
|
216
|
+
"slug": "pascals-triangle",
|
217
|
+
"topics": [
|
218
|
+
|
219
|
+
]
|
170
220
|
},
|
171
221
|
{
|
172
|
-
"difficulty":
|
173
|
-
"slug": "
|
174
|
-
"topics": [
|
222
|
+
"difficulty": 5,
|
223
|
+
"slug": "bracket-push",
|
224
|
+
"topics": [
|
225
|
+
|
226
|
+
]
|
175
227
|
},
|
176
228
|
{
|
177
|
-
"difficulty":
|
229
|
+
"difficulty": 5,
|
178
230
|
"slug": "series",
|
179
|
-
"topics": [
|
231
|
+
"topics": [
|
232
|
+
|
233
|
+
]
|
180
234
|
},
|
181
235
|
{
|
182
|
-
"difficulty":
|
183
|
-
"slug": "
|
184
|
-
"topics": [
|
236
|
+
"difficulty": 5,
|
237
|
+
"slug": "atbash-cipher",
|
238
|
+
"topics": [
|
239
|
+
|
240
|
+
]
|
185
241
|
},
|
186
242
|
{
|
187
|
-
"difficulty":
|
188
|
-
"slug": "
|
189
|
-
"topics": [
|
243
|
+
"difficulty": 6,
|
244
|
+
"slug": "roman-numerals",
|
245
|
+
"topics": [
|
246
|
+
|
247
|
+
]
|
190
248
|
},
|
191
249
|
{
|
192
|
-
"difficulty":
|
193
|
-
"slug": "
|
194
|
-
"topics": [
|
250
|
+
"difficulty": 6,
|
251
|
+
"slug": "beer-song",
|
252
|
+
"topics": [
|
253
|
+
|
254
|
+
]
|
195
255
|
},
|
196
256
|
{
|
197
|
-
"difficulty":
|
198
|
-
"slug": "
|
199
|
-
"topics": [
|
257
|
+
"difficulty": 6,
|
258
|
+
"slug": "etl",
|
259
|
+
"topics": [
|
260
|
+
|
261
|
+
]
|
200
262
|
},
|
201
263
|
{
|
202
|
-
"difficulty":
|
264
|
+
"difficulty": 6,
|
203
265
|
"slug": "linked-list",
|
204
|
-
"topics": [
|
205
|
-
|
206
|
-
|
207
|
-
"difficulty": 1,
|
208
|
-
"slug": "binary-search",
|
209
|
-
"topics": []
|
266
|
+
"topics": [
|
267
|
+
|
268
|
+
]
|
210
269
|
},
|
211
270
|
{
|
212
|
-
"difficulty":
|
213
|
-
"slug": "
|
214
|
-
"topics": [
|
271
|
+
"difficulty": 6,
|
272
|
+
"slug": "grade-school",
|
273
|
+
"topics": [
|
274
|
+
|
275
|
+
]
|
215
276
|
},
|
216
277
|
{
|
217
|
-
"difficulty":
|
218
|
-
"slug": "
|
219
|
-
"topics": [
|
278
|
+
"difficulty": 6,
|
279
|
+
"slug": "binary-search",
|
280
|
+
"topics": [
|
281
|
+
|
282
|
+
]
|
220
283
|
},
|
221
284
|
{
|
222
|
-
"difficulty":
|
223
|
-
"slug": "
|
224
|
-
"topics": [
|
285
|
+
"difficulty": 6,
|
286
|
+
"slug": "all-your-base",
|
287
|
+
"topics": [
|
288
|
+
|
289
|
+
]
|
225
290
|
},
|
226
291
|
{
|
227
|
-
"difficulty":
|
228
|
-
"slug": "
|
229
|
-
"topics": [
|
292
|
+
"difficulty": 7,
|
293
|
+
"slug": "anagram",
|
294
|
+
"topics": [
|
295
|
+
|
296
|
+
]
|
230
297
|
},
|
231
298
|
{
|
232
|
-
"difficulty":
|
299
|
+
"difficulty": 7,
|
233
300
|
"slug": "clock",
|
234
|
-
"topics": [
|
301
|
+
"topics": [
|
302
|
+
|
303
|
+
]
|
235
304
|
},
|
236
305
|
{
|
237
|
-
"difficulty":
|
238
|
-
"slug": "
|
239
|
-
"topics": [
|
306
|
+
"difficulty": 8,
|
307
|
+
"slug": "simple-cipher",
|
308
|
+
"topics": [
|
309
|
+
|
310
|
+
]
|
240
311
|
},
|
241
312
|
{
|
242
|
-
"difficulty":
|
243
|
-
"slug": "
|
313
|
+
"difficulty": 8,
|
314
|
+
"slug": "change",
|
244
315
|
"topics": [
|
245
|
-
|
246
|
-
"Collections",
|
247
|
-
"Lambdas"
|
316
|
+
|
248
317
|
]
|
249
318
|
},
|
250
319
|
{
|
251
|
-
"difficulty":
|
252
|
-
"slug": "
|
253
|
-
"topics": [
|
320
|
+
"difficulty": 10,
|
321
|
+
"slug": "react",
|
322
|
+
"topics": [
|
323
|
+
"Reactive programming",
|
324
|
+
"Generics",
|
325
|
+
"Nested classes",
|
326
|
+
"Higher-order functions"
|
327
|
+
]
|
254
328
|
},
|
255
329
|
{
|
256
330
|
"difficulty": 1,
|
257
|
-
"slug": "
|
258
|
-
"topics": [
|
331
|
+
"slug": "leap",
|
332
|
+
"topics": [
|
333
|
+
|
334
|
+
]
|
259
335
|
},
|
260
336
|
{
|
261
337
|
"difficulty": 1,
|
262
|
-
"slug": "
|
263
|
-
"topics": [
|
338
|
+
"slug": "list-ops",
|
339
|
+
"topics": [
|
340
|
+
|
341
|
+
]
|
264
342
|
},
|
265
343
|
{
|
266
|
-
"difficulty":
|
344
|
+
"difficulty": 1,
|
267
345
|
"slug": "bank-account",
|
268
|
-
"topics": ["Concurrency"]
|
269
|
-
},
|
270
|
-
{
|
271
|
-
"difficulty": 10,
|
272
|
-
"slug": "react",
|
273
346
|
"topics": [
|
274
|
-
"
|
275
|
-
"Generics",
|
276
|
-
"Nested classes",
|
277
|
-
"Higher-order functions"
|
347
|
+
"Concurrency"
|
278
348
|
]
|
279
349
|
}
|
280
350
|
]
|
@@ -45,6 +45,9 @@ subprojects {
|
|
45
45
|
}
|
46
46
|
}
|
47
47
|
|
48
|
+
// Note that journey-test.sh also strips @Ignore annotations using sed. The
|
49
|
+
// stripping implementations here and in journey-test.sh should be kept
|
50
|
+
// consistent.
|
48
51
|
task copyTestsFilteringIgnores(type: Copy) {
|
49
52
|
from "src/test/kotlin"
|
50
53
|
into "build/gen/test/kotlin"
|
@@ -5,7 +5,7 @@ import org.junit.rules.ExpectedException
|
|
5
5
|
import kotlin.test.assertEquals
|
6
6
|
|
7
7
|
/*
|
8
|
-
* version: 1.
|
8
|
+
* version: 1.1.0
|
9
9
|
*/
|
10
10
|
class CollatzCalculatorTest {
|
11
11
|
|
@@ -30,6 +30,12 @@ class CollatzCalculatorTest {
|
|
30
30
|
assertEquals(9, CollatzCalculator.computeStepCount(12))
|
31
31
|
}
|
32
32
|
|
33
|
+
@Ignore
|
34
|
+
@Test
|
35
|
+
fun testAVeryLargeInput() {
|
36
|
+
assertEquals(152, CollatzCalculator.computeStepCount(1000000))
|
37
|
+
}
|
38
|
+
|
33
39
|
@Ignore
|
34
40
|
@Test
|
35
41
|
fun testZeroIsConsideredInvalidInput() {
|
@@ -0,0 +1 @@
|
|
1
|
+
kotlin.incremental=false
|
@@ -0,0 +1,5 @@
|
|
1
|
+
## Hints
|
2
|
+
|
3
|
+
The tests for this exercise require you to use extensions, a mechanism for adding new functionality to an existing class whose source you do not directly control without having to subclass it. To learn more about Kotlin's implementations of extensions, check out the [official documentation](https://kotlinlang.org/docs/reference/extensions.html#extensions).
|
4
|
+
|
5
|
+
The `customFoldLeft` and `customFoldRight` methods are "fold" functions, which is a concept well-known in the functional programming world, but less so in the object-oriented one. If you'd like more background information, check out this [fold](https://en.wikipedia.org/wiki/Fold_(higher-order_function)) page.
|
@@ -0,0 +1,28 @@
|
|
1
|
+
buildscript {
|
2
|
+
ext.kotlin_version = '1.1.1'
|
3
|
+
repositories {
|
4
|
+
mavenCentral()
|
5
|
+
}
|
6
|
+
dependencies {
|
7
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
8
|
+
}
|
9
|
+
}
|
10
|
+
|
11
|
+
apply plugin: 'kotlin'
|
12
|
+
|
13
|
+
repositories {
|
14
|
+
mavenCentral()
|
15
|
+
}
|
16
|
+
|
17
|
+
dependencies {
|
18
|
+
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
19
|
+
|
20
|
+
testCompile 'junit:junit:4.12'
|
21
|
+
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
|
22
|
+
}
|
23
|
+
test {
|
24
|
+
testLogging {
|
25
|
+
exceptionFormat = 'full'
|
26
|
+
events = ["passed", "failed", "skipped"]
|
27
|
+
}
|
28
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
fun <T> List<T>.customAppend(list: List<T>): List<T> {
|
2
|
+
val result = mutableListOf<T>()
|
3
|
+
result.addAll(this)
|
4
|
+
result.addAll(list)
|
5
|
+
return result
|
6
|
+
}
|
7
|
+
|
8
|
+
fun <T> List<List<T>>.customConcat(): List<T> {
|
9
|
+
val result = mutableListOf<T>()
|
10
|
+
forEach { result.addAll(it) }
|
11
|
+
return result
|
12
|
+
}
|
13
|
+
|
14
|
+
fun <T> List<T>.customFilter(predicate: (T) -> Boolean): List<T> {
|
15
|
+
val result = mutableListOf<T>()
|
16
|
+
forEach { if (predicate(it)) { result.add(it) } }
|
17
|
+
return result
|
18
|
+
}
|
19
|
+
|
20
|
+
val List<Any>.customSize: Int
|
21
|
+
get() = size
|
22
|
+
|
23
|
+
fun <T, U> List<T>.customMap(transform: (T) -> U): List<U> {
|
24
|
+
val result = mutableListOf<U>()
|
25
|
+
forEach { result.add(transform(it)) }
|
26
|
+
return result
|
27
|
+
}
|
28
|
+
|
29
|
+
fun <T, U> List<T>.customFoldLeft(initial: U, f: (U, T) -> U): U {
|
30
|
+
if (isEmpty()) return initial
|
31
|
+
return drop(1).customFoldLeft(f(initial, first()), f)
|
32
|
+
}
|
33
|
+
|
34
|
+
fun <T, U> List<T>.customFoldRight(initial: U, f: (T, U) -> U): U {
|
35
|
+
if (isEmpty()) return initial
|
36
|
+
return f(first(), drop(1).customFoldRight(initial, f))
|
37
|
+
}
|
38
|
+
|
39
|
+
fun <T> List<T>.customReverse(): List<T> {
|
40
|
+
val result = mutableListOf<T>()
|
41
|
+
forEach { result.add(0, it) }
|
42
|
+
return result
|
43
|
+
}
|
File without changes
|