ifEnabledOrElse

inline suspend fun <T> FF4k.ifEnabledOrElse(featureId: String, executionContext: FlippingExecutionContext? = null, enabled: () -> T, disabled: () -> T): T(source)

Execute one block if the feature is enabled, another if disabled.

Returns the result of the appropriate block based on the feature state. Useful for A/B style feature flags where both paths produce a result.

Example:

val result = ff4k.ifEnabledOrElse("feature",
enabled = { runNewCode() },
disabled = { runOldCode() }
)

// With execution context
val price = ff4k.ifEnabledOrElse("dynamic-pricing", context,
enabled = { calculateDynamicPrice(userId) },
disabled = { getStaticPrice() }
)

Return

the result of the executed block

Parameters

T

the return type of both blocks (must be the same)

featureId

the unique identifier of the feature to check

executionContext

optional explicit context for strategy evaluation

enabled

the block to execute if the feature is enabled

disabled

the block to execute if the feature is disabled