-
Notifications
You must be signed in to change notification settings - Fork 0
/
koans.html
343 lines (336 loc) · 7.28 KB
/
koans.html
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<table border="1" cellspacing="0" cellpadding="10">
<tbody>
<tr>
<td><strong>USE</strong></td>
<td><strong>TO MEDITATE ON ...</strong></td>
</tr>
<tr>
<td>AboutAsserts</td>
<td>How Scala koans work</td>
</tr>
<tr>
<td>AboutValAndVar</td>
<td>How val and var declarations differ</td>
</tr>
<tr>
<td>AboutClasses</td>
<td>How to specify class arguments and fields</td>
</tr>
<tr>
<td>AboutRange</td>
<td>How to use a convenient class for generating sequences</td>
</tr>
<tr>
<td>AboutLiteralBooleans</td>
<td>How to specify boolean values</td>
</tr>
<tr>
<td>AboutLiteralNumbers</td>
<td>How to specify values for the common numeric data types</td>
</tr>
<tr>
<td>AboutLiteralStrings</td>
<td>How to write literal values for character and string data</td>
</tr>
<tr>
<td>About Tuples</td>
<td>How to use a convenient class for unnamed structures</td>
</tr>
<tr>
<td>AboutTuples</td>
<td>How to write a literal tuple value</td>
</tr>
<tr>
<td></td>
<td>How to access the values in a tuple</td>
</tr>
<tr>
<td></td>
<td>Whether all values in a tuple must have the same type</td>
</tr>
<tr>
<td>AboutLists</td>
<td>How Nil lists compare</td>
</tr>
<tr>
<td></td>
<td>How to write a literal list</td>
</tr>
<tr>
<td></td>
<td>How to access the values in a list</td>
</tr>
<tr>
<td></td>
<td>How to alter the contents of a list</td>
</tr>
<tr>
<td></td>
<td>Discovering some common List methods</td>
</tr>
<tr>
<td></td>
<td>Transforming, filtering, and summarizing lists</td>
</tr>
<tr>
<td></td>
<td>Quickly creating a list of consecutive integers</td>
</tr>
<tr>
<td></td>
<td>Sharing content between lists</td>
</tr>
<tr>
<td>AboutMaps</td>
<td>How to write a literal map</td>
</tr>
<tr>
<td></td>
<td>What happens if a key appears more than once</td>
</tr>
<tr>
<td></td>
<td>Iterating through the contents of a map</td>
</tr>
<tr>
<td></td>
<td>Whether all keys or values in a map must have the same type</td>
</tr>
<tr>
<td></td>
<td>How to access the values in a map</td>
</tr>
<tr>
<td></td>
<td>How to remove entries from a map</td>
</tr>
<tr>
<td>AboutSets</td>
<td>How to write a literal set value</td>
</tr>
<tr>
<td></td>
<td>What happens if a value appears more than once</td>
</tr>
<tr>
<td></td>
<td>Whether all values in a set must have the same type</td>
</tr>
<tr>
<td></td>
<td>How to test for the presence of a value in a set</td>
</tr>
<tr>
<td></td>
<td>How to alter the content of a set</td>
</tr>
<tr>
<td></td>
<td>How to iterate through the values in a set</td>
</tr>
<tr>
<td></td>
<td>How to perform familiar operations on a set</td>
</tr>
<tr>
<td>AboutMutableMaps</td>
<td>How to create maps whose contents can be altered</td>
</tr>
<tr>
<td></td>
<td>How to add and remove map content</td>
</tr>
<tr>
<td>AboutMutableSets</td>
<td>How to create sets whose contents can be altered</td>
</tr>
<tr>
<td></td>
<td>How to add and remove set content</td>
</tr>
<tr>
<td>AboutFormatting</td>
<td>How to use character literals and escaped sequences</td>
</tr>
<tr>
<td>AboutPatternMatching</td>
<td>How to use pattern matching to replace complex conditional logic</td>
</tr>
<tr>
<td></td>
<td>How to ignore part of the data being pattern matched</td>
</tr>
<tr>
<td></td>
<td>How to "capture" matched data for later use</td>
</tr>
<tr>
<td></td>
<td>How to use pattern matching to simplify working with regular expressions</td>
</tr>
<tr>
<td></td>
<td>How to refer to the contents of existing variables when pattern matching</td>
</tr>
<tr>
<td>AboutCaseClasses</td>
<td>How to use case classes to write less boilerplate</td>
</tr>
<tr>
<td></td>
<td>Discovering which methods are automatically provided with case classes</td>
</tr>
<tr>
<td></td>
<td>How to create a mutable case class</td>
</tr>
<tr>
<td></td>
<td>How to avoid using a mutable case class</td>
</tr>
<tr>
<td></td>
<td>How to use named parameters to simplify working with case classes even further</td>
</tr>
<tr>
<td></td>
<td>How to "deconstruct"" an instance of a case class</td>
</tr>
<tr>
<td>AboutOptions</td>
<td>How to avoid using raw nulls</td>
</tr>
<tr>
<td></td>
<td>How to safely deal with "missing" or optional data</td>
</tr>
<tr>
<td></td>
<td>How to operate on an optional value</td>
</tr>
<tr>
<td></td>
<td>How to work with a list of optional values</td>
</tr>
<tr>
<td>AboutSequencesAndArrays</td>
<td>How to write a literal array value</td>
</tr>
<tr>
<td></td>
<td>How to convert between various kinds of sequences</td>
</tr>
<tr>
<td></td>
<td>How to transform and filter lists</td>
</tr>
<tr>
<td>AboutNamedAndDefaultArguments</td>
<td>How to specify defaults for parameters and how to specify arguments in any order by using names</td>
</tr>
<tr>
<td>AboutForExpressions</td>
<td>How to iterate sequences, create Ranges, use guards, and nest</td>
</tr>
<tr>
<td>AboutEmptyValues</td>
<td>How to use None, Some, and Option</td>
</tr>
<tr>
<td>AboutParentClasses</td>
<td>How to use classes for inheritances and how to use abstract classes</td>
</tr>
<tr>
<td>AboutTypeSignatures</td>
<td>How to specify generics</td>
</tr>
<tr>
<td>AboutTraits</td>
<td>How to create self-contained definitions that can be combined with inheritance</td>
</tr>
<tr>
<td>AboutPreconditions</td>
<td>How to ensure that conditions are met</td>
</tr>
<tr>
<td>AboutUniformAccessPrinciple</td>
<td>How to interchangeably use fields and methods to hide implementation details</td>
</tr>
<tr>
<td>AboutHigherOrderFunctions</td>
<td>How to write and use anonymous functions</td>
</tr>
<tr>
<td></td>
<td>How a closure differs from a "pure" function</td>
</tr>
<tr>
<td></td>
<td>How to return a function as a result</td>
</tr>
<tr>
<td></td>
<td>How to compose new functions from existing ones</td>
</tr>
<tr>
<td></td>
<td>How to use currying to "specialize" functions</td>
</tr>
<tr>
<td></td>
<td>How to create a function from a class method</td>
</tr>
<tr>
<td>AboutPartialFunctions</td>
<td>How to safely create functions that are only defined for subsets of their arguments</td>
</tr>
<tr>
<td></td>
<td>How to easily combine these partial functions to create new functions</td>
</tr>
<tr>
<td>AboutPartiallyAppliedFunctions</td>
<td>How to create a function by specifying only some of the arguments to another function</td>
</tr>
<tr>
<td>About Iterables</td>
<td>How to do fun stuff with basic Scala collections while affecting state</td>
</tr>
<tr>
<td>About Traversables</td>
<td>How to do fun stuff with basic Scala collections without affecting state</td>
</tr>
<tr>
<td>AboutInfixPrefixAndPostfixOperators</td>
<td>How to know what the compiler is doing with your expressions</td>
</tr>
<tr>
<td>AboutInfixTypes</td>
<td>How to make expressions read nicely</td>
</tr>
<tr>
<td>AboutImplicits</td>
<td>How to add to the language to improve readability</td>
</tr>
<tr>
<td>AboutInteroperability</td>
<td>How to work with Java classes</td>
</tr>
<tr>
<td>AboutManifests</td>
<td>How to provide meta information about classes</td>
</tr>
<tr>
<td>AboutEnumerations</td>
<td>How to create and generated values, access index and name, and how to create your own</td>
</tr>
<tr>
<td>AboutConstructors</td>
<td>How to create auxiliary constructors</td>
</tr>
<tr>
<td>AboutImportsAndPackages</td>
<td>How to declare packages of your own and how to import other packages</td>
</tr>
</tbody>
</table>