I'm passing a function with optional parameters as...
# announcements
g
I'm passing a function with optional parameters as a parameter to another function
Copy code
fun addPlayer(
		name: String,
		avatar: Int? = generateRandomAvatar(),
		id: String = UUID.randomUUID().toString()
	) { dostuff }
...
fun PlayerList(players: List<Player>, addPlayer: (String, Int?, String) -> Unit) {
    addPlayer("Player #${players.size}")<----error here
}
But I'm not sure how to convey in the signature that they're optional, maybe this isn't possible?
I thnk lambdas can't be like this, so I guess it can't be done
t
Seems like addPlayer with an avatar and id is adding a player to a list, but addPlayer without an avatar or an id will actually first register a new player and then add it to a list. If you make both cases explicit as (executable) commands it might get you close to your preferred solution.
g
That makes sense, a simple helper one and then the explicit list manipulation one 👍
Thanks @Tim Schraepen
t
🙏👌