Skip to content
Permalink
Browse files

Issue #29: Add a more Kotlin idiomatic method for checking experiments

Closes #29: Add a more Kotlin idiomatic method for checking experiments
  • Loading branch information...
fercarcedo committed Jun 20, 2018
1 parent 93b2fb9 commit 1c7ca693e29356d54f6bf354fe7506aab18dca80
Showing with 13 additions and 0 deletions.
  1. +13 −0 fretboard/src/main/java/mozilla/components/service/fretboard/Fretboard.kt
@@ -60,4 +60,17 @@ class Fretboard(
fun isInExperiment(context: Context, descriptor: ExperimentDescriptor): Boolean {
return evaluator.evaluate(context, descriptor, experiments)
}

/**
* Performs an action if the user is part of the specified experiment
*
* @param context context
* @param descriptor descriptor of the experiment to check
* @param block block of code to be executed if the user is part of the experiment
*/
fun withExperiment(context: Context, descriptor: ExperimentDescriptor, block: (Experiment) -> Unit) {
if (evaluator.evaluate(context, descriptor, experiments)) {
block(experiments.first { it.id == descriptor.id })
}
}
}

0 comments on commit 1c7ca69

Please sign in to comment.
You can’t perform that action at this time.