From 08575f8b9168ae4d7dcab942641874541cf8cbb3 Mon Sep 17 00:00:00 2001 From: Phil Burrows Date: Thu, 17 Oct 2024 15:37:20 -0500 Subject: [PATCH] add array comparison operators these aren't tested (because I need to get an updated expected results test spec), but the implementation matches the node sdk --- lib/statsig_ex/evaluator.ex | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/statsig_ex/evaluator.ex b/lib/statsig_ex/evaluator.ex index 631a7ac..2e0c033 100644 --- a/lib/statsig_ex/evaluator.ex +++ b/lib/statsig_ex/evaluator.ex @@ -341,6 +341,29 @@ defmodule StatsigEx.Evaluator do end end + # all array comparisons require a list for both value & target + defp compare(val, target, <<"array_contains_", _type::binary>>) + when not is_list(val) or not is_list(target), + do: false + + defp compare(val, target, "array_contains_any") do + val_m = MapSet.new(val) + target_m = MapSet.new(target) + MapSet.intersection(val_m, target_m) |> MapSet.size() > 0 + end + + defp compare(val, target, "array_contains_none"), + do: !compare(val, target, "array_contains_any") + + defp compare(val, target, "array_contains_all") do + val_m = MapSet.new(val) + target_m = MapSet.new(target) + MapSet.subset?(val_m, target_m) + end + + defp compare(val, target, "not_array_contains_all"), + do: !compare(val, target, "array_contains_all") + defp compare(val, target, "eq"), do: val == target defp compare(val, target, "neq"), do: val != target