Skip to content

Instantly share code, notes, and snippets.

@pocmo
Last active October 26, 2017 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pocmo/5b58631770fe02614098482cb7af0f52 to your computer and use it in GitHub Desktop.
Save pocmo/5b58631770fe02614098482cb7af0f52 to your computer and use it in GitHub Desktop.
Experiments - Kotlin - Scribble
// In this scribble the experiments (A/B) library is called "Fretboard"
// Experiments.* are not part of the library but constants in the actual app project
///////////////////////////////////////////////////////////////////////////
// Simple API (Java style):
///////////////////////////////////////////////////////////////////////////
if (Fretboard.isInEperiment(Experiments.BOOKMARKS)) {
// do something
}
val experiment = Fretboard.getExperiment(Experiments.BOOKMARKS)
// do something with the experiments object and the data associated with this experiment.
///////////////////////////////////////////////////////////////////////////
// More DSL-like API (Kotlin style?)
///////////////////////////////////////////////////////////////////////////
Fretboard.withExperiment(Experiments.BOOKMARKS) {
// do something
// do something with the experiment:
System.out.println(it.identifier)
System.out.println(it.payload.buttonColor) // Experiments can have additional data attached.
}
// Or perform the action on the experiment constant:
Experiments.BOOKMARKS.ifActive {
System.out.println(it.identifier)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment