Last active
September 10, 2022 19:30
-
-
Save zsoltk/e86b839ddb8f18eeabaf792ace1dcc62 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class VoteLike<T : Any> internal constructor() : CardsOperation<T> { | |
// Returns a modified list of elements with new target states applied | |
override fun invoke(elements: CardsElements<T>): CardsElements<T> = | |
elements.map { element -> | |
if (element.targetState == Cards.State.Top) { | |
element.transitionTo( | |
newTargetState = Cards.State.VoteLike, | |
operation = this | |
) | |
} else { | |
element | |
} | |
} | |
} | |
fun <T : Any> Cards<T>.voteLike() { | |
accept(VoteLike()) | |
promoteAll() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment