View Source Unleash.Variant (Unleash v3.0.0)

Defines types and functions for representing and working with strategy and feature variants.

Variants extend feature flags beyond simple on/off states, enabling multiple return values for more granular feature control.

Feature flags are designed to let you decide which users have access to a feature. Variants are designed to let you decide which version of the feature are user gets access to.

## Overview

While a basic feature flag exists in either on or off states, variants allow for multiple possible states within an enabled feature. Variants can be defined:

  • Within strategies (recommended approach)
  • Directly on the feature flag (deprecated)

Variants have a weight which determines the likelihood of users receiving a specific variant.

## Common Use Case

A typical pattern involves:

  1. Using a feature flag to control access to an entire feature
  2. Applying strategies to target specific user segments
  3. Using variants to customise the feature experience for different segments

For example, you might use strategies to determine which user segments can access a new UI component, then use variants to show different button colors to different segments within that group for A/B testing.

## Documentation

Summary

Types

@type result() :: %{
  :enabled => boolean(),
  :name => String.t(),
  optional(:payload) => map()
}
@type t() :: %{enabled: boolean(), name: String.t(), payload: map()}

Functions

Link to this function

select_feature_variant(feature, context)

View Source
Link to this function

select_strategy_variant(feature, variants, context)

View Source
Link to this function

to_map(variant, enabled \\ false)

View Source