withFilter tweak
replace filter followed by map, flatMap or foreach by withFilter when filtered sequence isn't option As a scala compiler do for guards in for loopspull/7218/head
parent
a0c38e140e
commit
b6c222c919
|
@ -40,7 +40,7 @@ final private class EvalCacheUpgrade(scheduler: akka.actor.Scheduler)(implicit
|
|||
(1 to input.eval.multiPv) flatMap { multiPv =>
|
||||
evals get makeSetupId(input.id.variant, input.fen, multiPv)
|
||||
} foreach { sris =>
|
||||
val wms = sris.filter(sri.value !=) flatMap members.get
|
||||
val wms = sris.withFilter(sri.value !=) flatMap members.get
|
||||
if (wms.nonEmpty) {
|
||||
val json = JsonHandlers.writeEval(input.eval, input.fen)
|
||||
wms foreach { wm =>
|
||||
|
|
|
@ -45,9 +45,9 @@ object Statistics {
|
|||
moveTimes(pov) ?? {
|
||||
_.iterator
|
||||
.sliding(14)
|
||||
.map(a => a.toList.sorted.drop(1).dropRight(1))
|
||||
.map(_.toList.sorted.drop(1).dropRight(1))
|
||||
.filter(_.count(instantaneous ==) < 4)
|
||||
.flatMap(a => moveTimeCoefVariationNoDrop(a))
|
||||
.flatMap(moveTimeCoefVariationNoDrop)
|
||||
.some
|
||||
}
|
||||
|
||||
|
|
|
@ -86,8 +86,7 @@ object JsonApi {
|
|||
def medianNodes =
|
||||
Maths.median {
|
||||
evaluations
|
||||
.filterNot(_.mateFound)
|
||||
.filterNot(_.deadDraw)
|
||||
.withFilter(e => !(e.mateFound || e.deadDraw))
|
||||
.flatMap(_.nodes)
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ final private class Monitor(
|
|||
avgOf(_.pv.size.some) foreach { monBy.pvSize(userId).record(_) }
|
||||
|
||||
val significantPvSizes =
|
||||
result.evaluations.filterNot(_.mateFound).filterNot(_.deadDraw).map(_.pv.size)
|
||||
result.evaluations.withFilter(e => !(e.mateFound || e.deadDraw)).map(_.pv.size)
|
||||
|
||||
monBy.pv(userId, isLong = false).increment(significantPvSizes.count(_ < 3))
|
||||
monBy.pv(userId, isLong = true).increment(significantPvSizes.count(_ >= 6))
|
||||
|
|
|
@ -54,7 +54,7 @@ private object HookRepo {
|
|||
}
|
||||
|
||||
def poolCandidates(clock: chess.Clock.Config): Vector[lila.pool.HookThieve.PoolHook] =
|
||||
hooks.filter(_ compatibleWithPool clock).map(_.toPool)
|
||||
hooks.withFilter(_ compatibleWithPool clock).map(_.toPool)
|
||||
|
||||
// keeps hooks that hold true
|
||||
// returns removed hooks
|
||||
|
|
|
@ -63,7 +63,7 @@ final class LobbySocket(
|
|||
case AddHook(hook) =>
|
||||
send(
|
||||
P.Out.tellSris(
|
||||
hookSubscriberSris diff idleSris filter { sri =>
|
||||
hookSubscriberSris diff idleSris withFilter { sri =>
|
||||
members get sri exists { biter.showHookTo(hook, _) }
|
||||
} map Sri.apply,
|
||||
makeMessage("had", hook.render(defaultLang))
|
||||
|
|
|
@ -166,7 +166,7 @@ final class RelayApi(
|
|||
|
||||
private def sendToContributors(id: Relay.Id, t: String, msg: JsObject): Funit =
|
||||
studyApi members Study.Id(id.value) map {
|
||||
_.map(_.contributorIds).filter(_.nonEmpty) foreach { userIds =>
|
||||
_.map(_.contributorIds).withFilter(_.nonEmpty) foreach { userIds =>
|
||||
import lila.hub.actorApi.socket.SendTos
|
||||
import JsonView.idWrites
|
||||
import lila.socket.Socket.makeMessage
|
||||
|
|
|
@ -77,7 +77,7 @@ case class Report(
|
|||
|
||||
def boostWith: Option[User.ID] =
|
||||
(reason == Reason.Boost) ?? {
|
||||
atoms.toList.filter(_.byLichess).map(_.text).flatMap(_.linesIterator).collectFirst {
|
||||
atoms.toList.withFilter(_.byLichess).flatMap(_.text.linesIterator).collectFirst {
|
||||
case Report.farmWithRegex(userId) => userId
|
||||
case Report.sandbagWithRegex(userId) => userId
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ object Stream {
|
|||
case class Result(items: List[Item]) {
|
||||
def streams(keyword: Keyword, streamers: List[Streamer]): List[Stream] =
|
||||
items
|
||||
.filter { item =>
|
||||
.withFilter { item =>
|
||||
item.snippet.liveBroadcastContent == "live" &&
|
||||
item.snippet.title.toLowerCase.contains(keyword.toLowerCase)
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ final private class Streaming(
|
|||
(twitchStreams ::: youTubeStreams) pipe dedupStreamers
|
||||
}
|
||||
}
|
||||
_ <- api.setLiveNow(streamers.filter(streams.has).map(_.id))
|
||||
_ <- api.setLiveNow(streamers.withFilter(streams.has).map(_.id))
|
||||
} yield publishStreams(streamers, streams)
|
||||
|
||||
def publishStreams(streamers: List[Streamer], newStreams: LiveStreams) = {
|
||||
|
|
|
@ -162,7 +162,7 @@ final class StudyApi(
|
|||
private def scheduleTimeline(studyId: Study.Id) =
|
||||
scheduler.scheduleOnce(1 minute) {
|
||||
byId(studyId) foreach {
|
||||
_.filter(_.isPublic) foreach { study =>
|
||||
_.withFilter(_.isPublic) foreach { study =>
|
||||
timeline ! (Propagate(
|
||||
StudyCreate(study.ownerId, study.id.value, study.name.value)
|
||||
) toFollowersOf study.ownerId)
|
||||
|
|
|
@ -53,7 +53,7 @@ final private class SwissScoring(
|
|||
_ <- SwissPlayer.fields { f =>
|
||||
prevPlayers
|
||||
.zip(players)
|
||||
.filter {
|
||||
.withFilter {
|
||||
case (a, b) => a != b
|
||||
}
|
||||
.map {
|
||||
|
|
|
@ -106,7 +106,7 @@ final class PairingRepo(coll: Coll)(implicit ec: scala.concurrent.ExecutionConte
|
|||
coll
|
||||
.list[Pairing](selectTourUser(tourId, userId))
|
||||
.flatMap {
|
||||
_.filter(_ notLostBy userId).map { p =>
|
||||
_.withFilter(_ notLostBy userId).map { p =>
|
||||
coll.update.one(
|
||||
$id(p.id),
|
||||
$set(
|
||||
|
|
Loading…
Reference in New Issue