belay icon indicating copy to clipboard operation
belay copied to clipboard

Add take function (similar to takeIf)

Open ngsilverman opened this issue 5 years ago • 0 comments

Rather than:

fun countBananas(): Int {
    // Count the bananas.

    expect(bananaCount >= 0, "Invalid count: $bananaCount.") {
        bananaCount = 0
    }
    return bananaCount
}

Something like:

fun countBananas(): Int {
    // Count the bananas.

    return expect.take(bananaCount, "Invalid count: $bananaCount.") { it >= 0 } ?: 0
}

ngsilverman avatar Nov 19 '20 15:11 ngsilverman