mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-06-13 14:48:54 +02:00
prefer fold over map followed by getOrElse
`fold` combinator is a shorthand way of encoding `map` + `getOrElse` pattern.
This commit is contained in:
parent
ec83d01dca
commit
ae9602c3cb
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user