Removed print statements

This commit is contained in:
Anirban Chatterjee 2020-08-24 09:59:39 +02:00
parent f44cc311bd
commit 82203b222e

View File

@ -50,82 +50,58 @@ class AggregateOperations {
} }
fun foldList(): Int { fun foldList(): Int {
println("fold operation") return numbers.fold(100) { total, it ->
val result = numbers.fold(100) { total, it ->
println("total = $total, it = $it") println("total = $total, it = $it")
total - it total - it
} } // ((((100 - 1)-15)-3)-8) = 73
println(result) // ((((100 - 1)-15)-3)-8) = 73
return result
} }
fun foldRightList(): Int { fun foldRightList(): Int {
println("foldRight operation") return numbers.foldRight(100) { it, total ->
val result = numbers.foldRight(100) { it, total ->
println("total = $total, it = $it") println("total = $total, it = $it")
total - it total - it
} } // ((((100-8)-3)-15)-1) = 73
println(result) // ((((100-8)-3)-15)-1) = 73
return result
} }
fun foldIndexedList(): Int { fun foldIndexedList(): Int {
println("foldIndexed operation") return numbers.foldIndexed(100) { index, total, it ->
val result = numbers.foldIndexed(100) { index, total, it ->
println("total = $total, it = $it, index = $index") println("total = $total, it = $it, index = $index")
if (index.minus(2) >= 0) total - it else total if (index.minus(2) >= 0) total - it else total
} } // ((100 - 3)-8) = 89
println(result) // ((100 - 3)-8) = 89
return result
} }
fun foldRightIndexedList(): Int { fun foldRightIndexedList(): Int {
println("foldRightIndexed operation") return numbers.foldRightIndexed(100) { index, it, total ->
val result = numbers.foldRightIndexed(100) { index, it, total ->
println("total = $total, it = $it, index = $index") println("total = $total, it = $it, index = $index")
if (index.minus(2) >= 0) total - it else total if (index.minus(2) >= 0) total - it else total
} } // ((100 - 8)-3) = 89
println(result) // ((100 - 8)-3) = 89
return result
} }
fun reduceList(): Int { fun reduceList(): Int {
println("reduce operation") return numbers.reduce { total, it ->
val result = numbers.reduce { total, it ->
println("total = $total, it = $it") println("total = $total, it = $it")
total - it total - it
} } // (((1 - 15)-3)-8) = -25
println(result) // (((1 - 15)-3)-8) = -25
return result
} }
fun reduceRightList(): Int { fun reduceRightList(): Int {
println("reduceRight operation") return numbers.reduceRight() { it, total ->
val result = numbers.reduceRight() { it, total ->
println("total = $total, it = $it") println("total = $total, it = $it")
total - it total - it
} } // ((8-3)-15)-1) = -11
println(result) // ((8-3)-15)-1) = -11
return result
} }
fun reduceIndexedList(): Int { fun reduceIndexedList(): Int {
println("reduceIndexed operation") return numbers.reduceIndexed { index, total, it ->
val result = numbers.reduceIndexed { index, total, it ->
println("total = $total, it = $it, index = $index") println("total = $total, it = $it, index = $index")
if (index.minus(2) >= 0) total - it else total if (index.minus(2) >= 0) total - it else total
} } // ((1-3)-8) = -10
println(result) // ((1-3)-8) = -10
return result
} }
fun reduceRightIndexedList(): Int { fun reduceRightIndexedList(): Int {
println("reduceRightIndexed operation") return numbers.reduceRightIndexed { index, it, total ->
val result = numbers.reduceRightIndexed { index, it, total ->
println("total = $total, it = $it, index = $index") println("total = $total, it = $it, index = $index")
if (index.minus(2) >= 0) total - it else total if (index.minus(2) >= 0) total - it else total
} } // ((8-3) = 5
println(result) // ((8-3) = 5
return result
} }
} }