addzo
addzo

Reputation: 867

Kotlin Map with If statement

Trying to write some Functional code and use map - maybe filter too? - to replace something like:

for (something in somethingList) {
    if (something.value == someOtherThing.value)
        result = true
} 

With something more functional like found here: https://grokonez.com/kotlin/kotlin-filter-map-examples

But I don't want to return a new map I want to set result to the condition of something.value == someOtherThing.value being true or not.

But I'm getting lost in my neophyte world of Functional Kotlin.

Can anyone nudge me in the right direction?

Thanks

Upvotes: 1

Views: 2175

Answers (1)

Animesh Sahu
Animesh Sahu

Reputation: 8106

You can use any for this purpose.

val result = somethingList.any { it.value == someOtherThing.value }

Upvotes: 1

Related Questions