Nat Strangerweather
03/16/2022, 4:30 PMfun removeUsedLetters() {
val boardLetters = readBoardLetters.value!!.toMutableList()
val newList = boardLetters.remove(letter.value)
println("remaining = $newList")
}
Why does remove()
act as a Boolean, and how can I get each letter that I click on to be removed from my list?Joffrey
03/16/2022, 4:34 PMremove()
is a mutating operation, it doesn't return a new list. It actually does remove the element from the mutable list, but its return value is a boolean telling you whether or not the element was actually found and removed (true) or if the list didn't have the element and thus wasn't changed (false).
If you want to return a new list, you can use the -
operator instead:
val newList = boardLetters - letter.value
Note that in this case there is no point in converting your original list into a mutable one with toMutableList()
.
Also note that this operation will not change readBoardLetters
.Nat Strangerweather
03/16/2022, 4:41 PMephemient
03/16/2022, 4:51 PM.toMutableList()
returns a mutable copy of the list, so any changes to boardLetters
has no effect on readBoardLetters.value
. what is readBoardLetters
?Kirill Grouchnikov
03/16/2022, 4:51 PMNat Strangerweather
03/16/2022, 4:55 PMreadboardLetters
is a list of letters on the gameBoard and they are saved in a room database.Joffrey
03/16/2022, 5:00 PMremoveUsedLetters()
if you want to access the same collection everytime)Nat Strangerweather
03/16/2022, 5:01 PM