Unleash.Strategy.Utils (Unleash v5.1.2)

View Source

Utilities that might help you create your own strategies.

Automatically aliased when useing Unleash.Strategy

Summary

Functions

Given a comma-separated list and a member, check to see if the member is in the list. An optional transformation function can be passed in to apply to the items in the list.

Given an ID and group ID, normalize them using a Murmur hash. Used in all strategies that provide "stickiness".

Parse a string to a non-negative integer, returning only the number or 0 if it isn't just a number.

Functions

in_list?(list, member, transform \\ &noop/1)

Given a comma-separated list and a member, check to see if the member is in the list. An optional transformation function can be passed in to apply to the items in the list.

Examples

iex> in_list?("a,B,c,D", "b", &String.downcase/1)
true

iex> in_list?("a,B,c,D", "b")
false

normalize(id, group_id, seed \\ 0)

Given an ID and group ID, normalize them using a Murmur hash. Used in all strategies that provide "stickiness".

See the gradualRolloutUserId strategy.

parse_int(x)

@spec parse_int(x :: String.t()) :: non_neg_integer()

Parse a string to a non-negative integer, returning only the number or 0 if it isn't just a number.

Examples

iex> parse_int("5")
5

iex> parse_int("5ab23a")
0

iex> parse_int(5)
5