Skip to content

Commit

Permalink
code golf
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jan 29, 2025
1 parent c36239a commit d023de8
Show file tree
Hide file tree
Showing 16 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions app/controllers/Auth.scala
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ final class Auth(
err => renderPasswordReset(err.some, fail = true).map { BadRequest(_) },
data =>
env.user.repo.enabledWithEmail(data.email.normalize).flatMap {
case Some((user, storedEmail)) =>
case Some(user, storedEmail) =>
lila.mon.user.auth.passwordResetRequest("success").increment()
env.security.passwordReset
.send(user, storedEmail)
Expand Down Expand Up @@ -412,7 +412,7 @@ final class Auth(
err => BadRequest.async(renderMagicLink(err.some, fail = true)),
data =>
env.user.repo.enabledWithEmail(data.email.normalize).flatMap {
case Some((user, storedEmail)) =>
case Some(user, storedEmail) =>
env.security.magicLink.rateLimit[Result](user, storedEmail, ctx.req, rateLimited):
lila.mon.user.auth.magicLinkRequest("success").increment()
env.security.magicLink
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/Puzzle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ final class Puzzle(env: Env, apiC: => Api) extends LilaController(env):
next <- env.puzzle.replay(me, replayDays.some, theme)
json <- next match
case None => fuccess(Json.obj("replayComplete" -> true))
case Some((puzzle, replay)) =>
case Some(puzzle, replay) =>
renderJson(puzzle, angle, replay.some).map { nextJson =>
Json.obj(
"round" -> env.puzzle.jsonView.roundJson.web(round, perf)(using
Expand Down Expand Up @@ -411,8 +411,8 @@ final class Puzzle(env: Env, apiC: => Api) extends LilaController(env):
val theme = PuzzleTheme.findOrMix(themeKey)
val checkedDayOpt = lila.puzzle.PuzzleDashboard.getClosestDay(days)
env.puzzle.replay(me, checkedDayOpt, theme.key).flatMap {
case None => Redirect(routes.Puzzle.dashboard(days, "home", none))
case Some((puzzle, replay)) => renderShow(puzzle, PuzzleAngle(theme), replay = replay.some)
case None => Redirect(routes.Puzzle.dashboard(days, "home", none))
case Some(puzzle, replay) => renderShow(puzzle, PuzzleAngle(theme), replay = replay.some)
}
}

Expand Down Expand Up @@ -510,7 +510,7 @@ final class Puzzle(env: Env, apiC: => Api) extends LilaController(env):
.map:
case None =>
Ok(env.puzzle.jsonView.bc.userJson(perf.intRating))
case Some((round, newPerf)) =>
case Some(round, newPerf) =>
env.puzzle.session.onComplete(round, PuzzleAngle.mix)
Ok(env.puzzle.jsonView.bc.userJson(newPerf.intRating))
)
Expand Down
2 changes: 1 addition & 1 deletion modules/fide/src/main/ZipInputStreamSource.scala
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ final class ZipInputStreamSource private (
read(arr) match
case None =>
eof = true
case Some((entry, readBytes)) =>
case Some(entry, readBytes) =>
readBytesTotal += readBytes
val entryData = ZipEntryData(entry.getName, entry.getTime)
val chunk =
Expand Down
4 changes: 2 additions & 2 deletions modules/forum/src/main/ForumPostApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ final class ForumPostApi(

def urlData(postId: ForumPostId, forUser: Option[User]): Fu[Option[PostUrlData]] =
get(postId).flatMap:
case Some((_, post)) if !post.visibleBy(forUser) => fuccess(none[PostUrlData])
case Some((topic, post)) =>
case Some(_, post) if !post.visibleBy(forUser) => fuccess(none[PostUrlData])
case Some(topic, post) =>
postRepo.forUser(forUser).countBeforeNumber(topic.id, post.number).dmap { nb =>
val page = nb / config.postMaxPerPage.value + 1
PostUrlData(topic.categId, topic.slug, page, post.number).some
Expand Down
4 changes: 2 additions & 2 deletions modules/memo/src/main/RateLimit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ final class RateLimit[K](
case None =>
storage.put(k, cost -> makeClearAt)
op
case Some((a, clearAt)) if a < credits =>
case Some(a, clearAt) if a < credits =>
storage.put(k, (a + cost) -> clearAt)
op
case Some((_, clearAt)) if nowMillis > clearAt =>
case Some(_, clearAt) if nowMillis > clearAt =>
storage.put(k, cost -> makeClearAt)
op
case _ if enforce.yes =>
Expand Down
2 changes: 1 addition & 1 deletion modules/puzzle/src/main/PuzzleFinisher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final private[puzzle] class PuzzleFinisher(
.foldM((perf, List.empty[(PuzzleRound, IntRatingDiff)])):
case ((perf, rounds), sol) =>
apply(sol.id, angle, sol.win, sol.mode)(using me, perf).map:
case Some((round, newPerf)) =>
case Some(round, newPerf) =>
val rDiff = IntRatingDiff(newPerf.intRating.value - perf.intRating.value)
(newPerf, (round, rDiff) :: rounds)
case None => (perf, rounds)
Expand Down
2 changes: 1 addition & 1 deletion modules/puzzle/src/main/PuzzleOpening.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ case class PuzzleOpeningCollection(
families.find(_.family.key == op.opening.family.key).so(_.count),
op.opening.ref.variation.isDefined.so(Set(op))
).some
case Some((famCount, ops)) =>
case Some(famCount, ops) =>
(famCount, if op.opening.ref.variation.isDefined then ops.incl(op) else ops).some

val treePopular: TreeList = treeMap.toList
Expand Down
2 changes: 1 addition & 1 deletion modules/relay/src/main/HttpClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private final class HttpClient(
.match
case None =>
fetchBodyAndEtag(url, none)
case Some((prevBody, prevEtag)) =>
case Some(prevBody, prevEtag) =>
fetchBodyAndEtag(url, prevEtag.some).map: (newBody, newEtag) =>
val body = if newBody.isEmpty && newEtag.has(prevEtag) then prevBody.some else newBody
(body, newEtag)
Expand Down
2 changes: 1 addition & 1 deletion modules/relay/src/main/RelayListing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private object RelayListing:
.headOption
.match
case None => trs.rounds.headOption
case Some((_, last)) =>
case Some(_, last) =>
trs.rounds.find(!_.isFinished) match
case None => last.some
case Some(next) =>
Expand Down
2 changes: 1 addition & 1 deletion modules/round/src/main/FarmBoostDetection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final private class FarmBoostDetection(
*/
def botFarming(g: Game): Fu[Boolean] =
g.twoUserIds match
case Some((u1, u2)) if g.finished && g.rated && g.userIds.exists(isBotSync) =>
case Some(u1, u2) if g.finished && g.rated && g.userIds.exists(isBotSync) =>
crosstableApi(u1, u2).flatMap: ct =>
gameRepo
.gamesFromSecondary(ct.results.reverse.take(PREV_GAMES).map(_.gameId))
Expand Down
6 changes: 3 additions & 3 deletions modules/round/src/main/ForecastApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ final class ForecastApi(coll: Coll, roundApi: lila.core.round.RoundApi)(using Ex
case None => fuccess(none)
case Some(fc) =>
fc(g, last) match
case Some((newFc, uciMove)) if newFc.steps.nonEmpty =>
case Some(newFc, uciMove) if newFc.steps.nonEmpty =>
coll.update.one($id(fc._id), newFc).inject(uciMove.some)
case Some((_, uciMove)) => clearPov(pov).inject(uciMove.some)
case _ => clearPov(pov).inject(none)
case Some(_, uciMove) => clearPov(pov).inject(uciMove.some)
case _ => clearPov(pov).inject(none)

private def firstStep(steps: Forecast.Steps) = steps.headOption.flatMap(_.headOption)

Expand Down
2 changes: 1 addition & 1 deletion modules/study/src/main/StudyApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ final class StudyApi(
case None =>
reloadSriBecauseOf(study, who.sri, chapter.id)
fufail(s"Invalid explorerGame insert $studyId $data")
case Some((chapter, path)) =>
case Some(chapter, path) =>
studyRepo.updateNow(study)
chapter.root.nodeAt(path).so { parent =>
for _ <- chapterRepo.setChildren(parent.children)(chapter, path)
Expand Down
4 changes: 2 additions & 2 deletions modules/study/src/main/StudyRepo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ final class StudyRepo(private[study] val coll: AsyncColl)(using
_ <- c.update.one($id(studyId), if v then $addToSet(F.likers -> userId) else $pull(F.likers -> userId))
likes <- countLikes(studyId)
updated <- likes match
case None => fuccess(Study.Likes(0))
case Some((likes, createdAt)) =>
case None => fuccess(Study.Likes(0))
case Some(likes, createdAt) =>
// Multiple updates may race to set denormalized likes and rank,
// but values should be approximately correct, match a real like
// count (though perhaps not the latest one), and any uncontended
Expand Down
2 changes: 1 addition & 1 deletion modules/study/src/main/UciPath.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extension (e: UciPath)
def isMainline(node: Node): Boolean =
e.split match
case None => true
case Some((id, rest)) =>
case Some(id, rest) =>
node.children.mainlineFirst match
case None => false
case Some(child) => child.id == id && rest.isMainline(child)
Expand Down
4 changes: 2 additions & 2 deletions modules/tree/src/main/tree.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ case class Branches(nodes: List[Branch]) extends AnyVal:
def promoteToMainlineAt(path: UciPath): Option[Branches] =
path.split match
case None => this.some
case Some((head, tail)) =>
case Some(head, tail) =>
get(head).flatMap: node =>
node.withChildren(_.promoteToMainlineAt(tail)).map { promoted =>
Branches(promoted :: nodes.filterNot(node ==))
Expand All @@ -74,7 +74,7 @@ case class Branches(nodes: List[Branch]) extends AnyVal:
def promoteUpAt(path: UciPath): Option[(Branches, Boolean)] =
path.split match
case None => Some(this -> false)
case Some((head, tail)) =>
case Some(head, tail) =>
for
node <- get(head)
mainlineNode <- this.first
Expand Down
2 changes: 1 addition & 1 deletion modules/ublog/src/main/UblogRank.scala
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ final class UblogRank(colls: UblogColls)(using Executor, akka.stream.Materialize
yield (id, likes, liveAt, tier, language, title, hasImage, adjust)
.flatMap:
case None => fuccess(UblogPost.Likes(0))
case Some((id, likes, liveAt, tier, language, title, hasImage, adjust)) =>
case Some(id, likes, liveAt, tier, language, title, hasImage, adjust) =>
// Multiple updates may race to set denormalized likes and rank,
// but values should be approximately correct, match a real like
// count (though perhaps not the latest one), and any uncontended
Expand Down

0 comments on commit d023de8

Please sign in to comment.