Created
January 7, 2020 07:07
-
-
Save adamw/fac9f5b476bf38455c2c92a642bc3cc2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import java.util.UUID | |
import cats._ | |
import cats.implicits._ | |
class Points[F[_]: Monad](dao: Dao[F]) { | |
def increase(userId: UUID): F[Unit] = | |
for { | |
current <- dao.currentPoints(userId) | |
updated = calculatePointsIncrease(current) | |
_ <- dao.updatePoints(userId, updated) | |
} yield () | |
private def calculatePointsIncrease(points: Int): Int = { | |
if (points % 2 == 0) points + 3 else points + 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment