Skip to content
This repository was archived by the owner on Aug 5, 2021. It is now read-only.

Commit 36d3c33

Browse files
committed
Formatting
1 parent 59faf6c commit 36d3c33

19 files changed

+65
-60
lines changed

src/i_introduction/_5_String_Templates/n05StringTemplates.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import util.TODO
44
import util.doc5
55

66
fun example1(a: Any, b: Any) =
7-
"This is some text in which variables ($a, $b) appear."
7+
"This is some text in which variables ($a, $b) appear."
88

99
fun example2(a: Any, b: Any) =
10-
"You can write it in a Java way as well. Like this: " + a + ", " + b + "!"
10+
"You can write it in a Java way as well. Like this: " + a + ", " + b + "!"
1111

1212
fun example3(c: Boolean, x: Int, y: Int) = "Any expression can be used: ${if (c) x else y}"
1313

1414
fun example4() =
15-
"""
15+
"""
1616
You can use raw strings to write multiline text.
1717
There is no escaping here, so raw strings are useful for writing regex patterns,
1818
you don't need to escape a backslash by a backslash.

src/i_introduction/_7_Nullable_Types/n07NullableTypes.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ fun todoTask7(client: Client?, message: String?, mailer: Mailer): Nothing = TODO
2323
)
2424

2525
fun sendMessageToClient(
26-
client: Client?, message: String?, mailer: Mailer
26+
client: Client?, message: String?, mailer: Mailer
2727
) {
2828
todoTask7(client, message, mailer)
2929
}
3030

31-
class Client (val personalInfo: PersonalInfo?)
32-
class PersonalInfo (val email: String?)
31+
class Client(val personalInfo: PersonalInfo?)
32+
class PersonalInfo(val email: String?)
3333

3434
interface Mailer {
3535
fun sendMessage(email: String, message: String)

src/i_introduction/_8_Smart_Casts/n08SmartCasts.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import util.doc8
66
// 'sealed' modifier restricts the type hierarchy:
77
// all the subclasses must be declared in the same file
88
sealed class Expr
9+
910
class Num(val value: Int) : Expr()
1011
class Sum(val left: Expr, val right: Expr) : Expr()
1112

1213
fun eval(e: Expr): Int =
13-
when (e) {
14-
is Num -> todoTask8(e)
15-
is Sum -> todoTask8(e)
16-
}
14+
when (e) {
15+
is Num -> todoTask8(e)
16+
is Sum -> todoTask8(e)
17+
}
1718

1819
fun todoTask8(expr: Expr): Nothing = TODO(
1920
"""

src/ii_collections/n16FlatMap.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ fun example() {
77
result == listOf('a', 'b', 'c', '1', '2')
88
}
99

10-
val Customer.orderedProducts: Set<Product> get() {
11-
// Return all products this customer has ordered
12-
todoCollectionTask()
13-
}
10+
val Customer.orderedProducts: Set<Product>
11+
get() {
12+
// Return all products this customer has ordered
13+
todoCollectionTask()
14+
}
1415

15-
val Shop.allOrderedProducts: Set<Product> get() {
16-
// Return all products that were ordered by at least one customer
17-
todoCollectionTask()
18-
}
16+
val Shop.allOrderedProducts: Set<Product>
17+
get() {
18+
// Return all products that were ordered by at least one customer
19+
todoCollectionTask()
20+
}

src/ii_collections/n22Fold.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ fun example9() {
88
// The same as
99
fun whatFoldDoes(): Int {
1010
var result = 1
11-
listOf(1, 2, 3, 4).forEach { element -> result = element * result}
11+
listOf(1, 2, 3, 4).forEach { element -> result = element * result }
1212
return result
1313
}
1414

1515
fun Shop.getSetOfProductsOrderedByEachCustomer(): Set<Product> {
1616
// Return the set of products that were ordered by each of the customers
17-
return customers.fold(allOrderedProducts, {
18-
orderedByAll, customer ->
17+
return customers.fold(allOrderedProducts, { orderedByAll, customer ->
1918
todoCollectionTask()
2019
})
2120
}

src/ii_collections/n24ExtensionsOnCollections.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fun todoTask24(): Nothing = TODO(
88
The function should do the same as '_24_JavaCode.doSomethingStrangeWithCollection'.
99
Replace all invocations of 'todoTask24()' with the appropriate code.
1010
""",
11-
references = { c: Collection<String> -> _24_JavaCode().doSomethingStrangeWithCollection(c) }
11+
references = { c: Collection<String> -> _24_JavaCode().doSomethingStrangeWithCollection(c) }
1212
)
1313

1414
fun doSomethingStrangeWithCollection(collection: Collection<String>): Collection<String>? {

src/ii_collections/todoUtil.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package ii_collections
33
import util.TODO
44

55
fun todoCollectionTask(): Nothing = TODO(
6-
"""
6+
"""
77
Common task for working with collections.
88
Look through the Shop API, which all the tasks are using.
99
Each individual task is described in the function name and the comment.
1010
""",
11-
references = { shop: Shop -> shop.customers }
11+
references = { shop: Shop -> shop.customers }
1212
)

src/iii_conventions/MyDateUtil.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package iii_conventions
22

3-
import iii_conventions.TimeInterval.*
3+
import iii_conventions.TimeInterval.DAY
44
import java.util.*
55

66
fun MyDate.nextDay() = addTimeIntervals(DAY, 1)

src/iii_conventions/n28ForLoop.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@ import util.TODO
44
import util.doc28
55

66
fun iterateOverCollection(collection: Collection<Int>) {
7-
for (element in collection) {}
7+
for (element in collection) {
8+
}
89
}
910

1011
fun iterateOverString() {
1112
// You can iterate over anything that has an 'iterator' method, member or extension.
12-
for (c in "abcd") {}
13+
for (c in "abcd") {
14+
}
1315
"abcd".iterator() //library extension method
1416
}
1517

1618
fun iterateOverRange() {
17-
for (i in 1..10) {}
18-
for (c in 'a'..'z') {}
19+
for (i in 1..10) {
20+
}
21+
for (c in 'a'..'z') {
22+
}
1923
}
2024

2125
fun todoTask28(): Nothing = TODO(

src/iii_conventions/n29OperatorsOverloading.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package iii_conventions
22

3-
import util.TODO
43
import iii_conventions.TimeInterval.*
4+
import util.TODO
55

66
fun todoTask29(): Nothing = TODO(
77
"""

src/iv_properties/n35HowDelegatesWork.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fun todoTask35(): Nothing = TODO(
1616
Store only the time in milliseconds in 'timeInMillis' property.
1717
Use the extension functions 'MyDate.toMillis' and 'Long.toDate'.
1818
""",
19-
references = { date: MyDate -> date.toMillis().toDate()}
19+
references = { date: MyDate -> date.toMillis().toDate() }
2020
)
2121

2222
class D {

src/util/kotlinUtil.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package util
22

33
@Suppress("UNUSED_PARAMETER")
44
fun TODO(
5-
task: String,
6-
documentation: Unit = Unit,
7-
references: Function<Any?> = {}
5+
task: String,
6+
documentation: Unit = Unit,
7+
references: Function<Any?> = {}
88
): Nothing = throw NotImplementedException(task)
99

1010
class NotImplementedException(message: String) : Exception(message)

src/v_builders/data.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ val crocodile = Product("crocodile", 20000.2, 1)
2020
val cushion = Product("cushion", 131.0, 0)
2121

2222
fun getProducts() = listOf(cactus, cake, camera, car, carrot, cellPhone, chimney, certificate, cigar, coffee, coffeeMaker,
23-
cola, cranberry, crocs, crocodile, cushion)
23+
cola, cranberry, crocs, crocodile, cushion)

src/v_builders/html.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,40 @@ open class Tag(val name: String) {
1414
}
1515
}
1616

17-
class Attribute(val name : String, val value : String) {
17+
class Attribute(val name: String, val value: String) {
1818
override fun toString() = """$name="$value""""
1919
}
2020

21-
fun <T: Tag> T.set(name: String, value: String?): T {
21+
fun <T : Tag> T.set(name: String, value: String?): T {
2222
if (value != null) {
2323
attributes.add(Attribute(name, value))
2424
}
2525
return this
2626
}
2727

28-
fun <T: Tag> Tag.doInit(tag: T, init: T.() -> Unit): T {
28+
fun <T : Tag> Tag.doInit(tag: T, init: T.() -> Unit): T {
2929
tag.init()
3030
children.add(tag)
3131
return tag
3232
}
3333

34-
class Html: Tag("html")
35-
class Table: Tag("table")
36-
class Center: Tag("center")
37-
class TR: Tag("tr")
38-
class TD: Tag("td")
39-
class Text(val text: String): Tag("b") {
34+
class Html : Tag("html")
35+
class Table : Tag("table")
36+
class Center : Tag("center")
37+
class TR : Tag("tr")
38+
class TD : Tag("td")
39+
class Text(val text: String) : Tag("b") {
4040
override fun toString() = text
4141
}
4242

4343
fun html(init: Html.() -> Unit): Html = Html().apply(init)
4444

45-
fun Html.table(init : Table.() -> Unit) = doInit(Table(), init)
46-
fun Html.center(init : Center.() -> Unit) = doInit(Center(), init)
45+
fun Html.table(init: Table.() -> Unit) = doInit(Table(), init)
46+
fun Html.center(init: Center.() -> Unit) = doInit(Center(), init)
4747

48-
fun Table.tr(color: String? = null, init : TR.() -> Unit) = doInit(TR(), init).set("bgcolor", color)
48+
fun Table.tr(color: String? = null, init: TR.() -> Unit) = doInit(TR(), init).set("bgcolor", color)
4949

50-
fun TR.td(color: String? = null, align : String = "left", init : TD.() -> Unit) = doInit(TD(), init).set("align", align).set("bgcolor", color)
50+
fun TR.td(color: String? = null, align: String = "left", init: TD.() -> Unit) = doInit(TD(), init).set("align", align).set("bgcolor", color)
5151

52-
fun Tag.text(s : Any?) = doInit(Text(s.toString()), {})
52+
fun Tag.text(s: Any?) = doInit(Text(s.toString()), {})
5353

src/v_builders/htmlDemo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import javax.swing.SwingConstants.CENTER
88

99

1010
fun main(args: Array<String>) {
11-
with (JFrame("Product popularity")) {
11+
with(JFrame("Product popularity")) {
1212
setSize(600, 600)
1313
defaultCloseOperation = JFrame.EXIT_ON_CLOSE
1414
add(JScrollPane(JLabel(renderProductTable(), CENTER)))

src/v_builders/n37StringAndMapBuilders.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package v_builders
22

33
import util.TODO
4-
import java.util.*
54

65
fun buildStringExample(): String {
76
fun buildString(build: StringBuilder.() -> Unit): String {

src/v_builders/n39HtmlBuilders.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import v_builders.data.getProducts
66
import v_builders.htmlLibrary.*
77

88
fun getTitleColor() = "#b9c9fe"
9-
fun getCellColor(row: Int, column: Int) = if ((row + column) %2 == 0) "#dce4ff" else "#eff2ff"
9+
fun getCellColor(row: Int, column: Int) = if ((row + column) % 2 == 0) "#dce4ff" else "#eff2ff"
1010

1111
fun todoTask39(): Nothing = TODO(
1212
"""

src/v_builders/n40BuildersHowItWorks.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fun task40() = linkedMapOf<Int, Answer>(
3232
b. function declaration
3333
c. function invocation
3434
*/
35-
1 to insertAnswerHere(),
35+
1 to insertAnswerHere(),
3636

3737
/*
3838
2. In the Kotlin code
@@ -49,7 +49,7 @@ fun task40() = linkedMapOf<Int, Answer>(
4949
b. argument name
5050
c. argument value
5151
*/
52-
2 to insertAnswerHere(),
52+
2 to insertAnswerHere(),
5353

5454
/*
5555
3. The block
@@ -62,7 +62,7 @@ from the previous question is:
6262
c. something mysterious
6363
6464
*/
65-
3 to insertAnswerHere(),
65+
3 to insertAnswerHere(),
6666

6767
/*
6868
4. For the code
@@ -84,5 +84,5 @@ which of the following is true:
8484
}
8585
}
8686
*/
87-
4 to insertAnswerHere()
87+
4 to insertAnswerHere()
8888
)

src/vi_generics/n41GenericFunctions.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ fun task41(): Nothing = TODO(
1313
You should write a function that splits the collection into two collections given as arguments.
1414
The signature of the 'toCollection()' function from the standard library may help you.
1515
""",
16-
references = { l: List<Int> ->
17-
l.partition { it > 0 }
18-
l.toCollection(HashSet<Int>())
19-
}
16+
references = { l: List<Int> ->
17+
l.partition { it > 0 }
18+
l.toCollection(HashSet<Int>())
19+
}
2020
)
2121

2222
fun List<String>.partitionWordsAndLines(): Pair<List<String>, List<String>> {

0 commit comments

Comments
 (0)