prefer fold over map followed by getOrElse

`fold` combinator is a shorthand way of encoding `map` + `getOrElse` pattern.
This commit is contained in:
Anzori (Nika) Ghurtchumelia 2023-04-01 04:23:59 +04:00 committed by GitHub
parent ec83d01dca
commit ae9602c3cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,12 +7,7 @@ import com.twitter.visibility.models.LabelSource
object ExperimentBase {
val sourceToParamMap: Map[LabelSource, LabelSourceParam] = Map.empty
final def shouldFilterForSource(params: Params, labelSourceOpt: Option[LabelSource]): Boolean = {
final def shouldFilterForSource(params: Params, labelSourceOpt: Option[LabelSource]): Boolean =
labelSourceOpt
.map { source =>
val param = ExperimentBase.sourceToParamMap.get(source)
param.map(params.apply).getOrElse(true)
}
.getOrElse(true)
}
.fold(true)(source => ExperimentBase.sourceToParamMap.get(source).fold(true)(params.apply))
}