File tree Expand file tree Collapse file tree 3 files changed +15
-10
lines changed
main/java/travelator/marketing
test/java/travelator/marketing Expand file tree Collapse file tree 3 files changed +15
-10
lines changed Original file line number Diff line number Diff line change 1
1
package travelator.marketing
2
2
3
+ import java.io.Reader
3
4
import java.io.Writer
4
5
5
6
fun main () {
6
7
System .`in `.reader().use { reader ->
7
8
System .out .writer().use { writer ->
8
- writer.appendLines(
9
- generate(
10
- reader.buffered().lineSequence()
11
- )
12
- )
9
+ reader
10
+ .asLineSequence()
11
+ .toHighValueCustomerReport()
12
+ .writeTo(writer)
13
13
}
14
14
}
15
15
}
16
16
17
+ fun Reader.asLineSequence () = buffered().lineSequence()
18
+
19
+ fun Sequence<CharSequence>.writeTo (writer : Writer ) {
20
+ writer.appendLines(this )
21
+ }
22
+
17
23
fun Writer.appendLines (lines : Sequence <CharSequence >): Writer {
18
24
return this .also {
19
25
lines.forEach(this ::appendLine)
Original file line number Diff line number Diff line change 1
1
package travelator.marketing
2
2
3
- fun generate ( lines : Sequence <String >): Sequence <String > {
4
- val valuableCustomers = lines
3
+ fun Sequence<String>. toHighValueCustomerReport ( ): Sequence <String > {
4
+ val valuableCustomers = this
5
5
.withoutHeader()
6
6
.map(String ::toCustomerData)
7
7
.filter { it.score >= 10 }
Original file line number Diff line number Diff line change @@ -50,11 +50,10 @@ class HighValueCustomersReportTests {
50
50
inputLines : List <String >,
51
51
expectedLines : List <String >
52
52
) {
53
+ val lines = inputLines.asSequence().constrainOnce()
53
54
assertEquals(
54
55
expectedLines,
55
- generate(
56
- inputLines.asSequence().constrainOnce()
57
- ).toList()
56
+ lines.toHighValueCustomerReport().toList()
58
57
)
59
58
}
60
59
}
You can’t perform that action at this time.
0 commit comments