Skip to content

Commit

Permalink
[JetNews] fix jetnews empty add or remove issue on MapExtensions.kt (a…
Browse files Browse the repository at this point in the history
…ndroid#1041)

When I clicke any item (topic, people and publication) on Interest
Screen the app crashed because of initial state (emptySet). I changed
the conversion style with .toMutableSet()

![Screenshot 2022-12-07 at 03 48
09](https://user-images.githubusercontent.com/31517818/206060587-521960b6-c761-432b-97bc-0d87274b7330.png)
  • Loading branch information
riggaroo committed Jan 5, 2023
2 parents 203a397 + 7fb8108 commit f36f918
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package com.example.jetnews.utils

internal fun <E> Set<E>.addOrRemove(element: E): Set<E> {
this as MutableSet
if (!add(element)) {
remove(element)
}
return this.toSet()
return this.toMutableSet().apply {
if (!add(element)) {
remove(element)
}
}.toSet()
}

0 comments on commit f36f918

Please sign in to comment.