Skip to content

Instantly share code, notes, and snippets.

@adamw
Created January 7, 2020 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamw/fac9f5b476bf38455c2c92a642bc3cc2 to your computer and use it in GitHub Desktop.
Save adamw/fac9f5b476bf38455c2c92a642bc3cc2 to your computer and use it in GitHub Desktop.
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