0% found this document useful (0 votes)
101 views1 page

Positive Sum

This document contains code written in the Kotlin programming language. It defines a sum function that takes an array of integers and a lambda function as parameters. The lambda function specifies how to combine (add) the accumulator and each element. It also defines a getLambda function that returns a sample lambda. The main function serves as the entry point but does not contain any additional code.

Uploaded by

Rishika Agrawal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views1 page

Positive Sum

This document contains code written in the Kotlin programming language. It defines a sum function that takes an array of integers and a lambda function as parameters. The lambda function specifies how to combine (add) the accumulator and each element. It also defines a getLambda function that returns a sample lambda. The main function serves as the entry point but does not contain any additional code.

Uploaded by

Rishika Agrawal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.io.

*
import java.math.*
import java.security.*
import java.text.*
import java.util.*
import java.util.concurrent.*
import java.util.function.*
import java.util.regex.*
import java.util.stream.*
import kotlin.collections.*
import kotlin.comparisons.*
import kotlin.io.*
import kotlin.jvm.*
import kotlin.jvm.functions.*
import kotlin.jvm.internal.*
import kotlin.ranges.*
import kotlin.sequences.*
import kotlin.text.*

fun sum(nums:Array<Int>,add: (acc:Int,ele:Int) -> Int):Int {


var res=0
for(i in nums){
res = add(res,i)
}
return res
}

fun getLambda(): (acc:Int,ele:Int) -> Int {


var lambda = { acc: Int, ele: Int -> if (acc>=0 && ele>=0) acc+ele else 0 }
return lambda
}

fun main(args: Array<String>) {

You might also like