liminal
11/21/2020, 3:08 AM.with(key: String, value: String)
, .with(key: String, value: Boolean)
. i'd like to be able to call these functions conditionally on the call site. i can't think of anything better than simply adding a param .with(key: String, value: String, shouldUse: Boolean)
to determine if a value should be used internally by the builder if shouldUse
is trueNir
11/21/2020, 4:52 AMNir
11/21/2020, 4:55 AMNir
11/21/2020, 4:55 AMNir
11/21/2020, 4:55 AMliminal
11/21/2020, 1:28 PMclass Event(val eventName: String) {
val properties = mutableMapOf<String, Any>()
fun with(key: String, value: Boolean): Event {
properties[key] = value
return this
}
fun with(key: String, value: Int): Event {
properties[key] = value
return this
}
fun with(key: String, value: Float): Event {
properties[key] = value
return this
}
fun with(key: String, value: String): Event {
properties[key] = value
return this
}
}
Nir
11/21/2020, 2:40 PMNir
11/21/2020, 2:42 PMNir
11/21/2020, 3:08 PMval builtEvent = Event("name").apply {
with("foo", 5)
if (condition) with("bar", 1.0)
}
Nir
11/21/2020, 3:08 PMNir
11/21/2020, 3:09 PM