'is there a way to declare a variable with the value of a function which takes this declaring variable as a parameter?

i am wondering is there some syntax in Kotlin for declaring a variable which will be equal to a function which takes several parameters 1 of which is said variable?

class Player(var deck: MutableList<String> = Deck().deck) {

var playerHand = Deck().deal(deck, playerHand, 6)

}

class Deck {

var deck = mutableListOf<String>()

fun deal( from: MutableList<String>, to: MutableList<String>, num: Int ){
        var temp = from.slice(0 .. num).toMutableList()
        to.addAll(temp)
        from.removeAll(temp)
    } 
}

So i basically want to transfer N amount of cards from a deck inside a Deck class to a variable playerHand in Player class. I know there are numerous other ways of doing it, i just wanted to know is there a way to create a var and assign a value to it using a function that takes that var as a parameter..



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source