Skip to content
This repository has been archived by the owner on Jun 1, 2021. It is now read-only.

(Minor) Not obvious how to check for list membership #113

Open
omnilinguist opened this issue Jul 14, 2016 · 1 comment
Open

(Minor) Not obvious how to check for list membership #113

omnilinguist opened this issue Jul 14, 2016 · 1 comment

Comments

@omnilinguist
Copy link

omnilinguist commented Jul 14, 2016

After looking at the language reference and the compiler (https://github.com/facebook/planout/blob/master/planout-editor/js/utils/planout_compiler.js), the way to check for existence of something in a list is not well documented.

One use case I can think of is in case I want to implement whitelists and/or custom targeting. This is a completely fabricated example (though intended to mimic real world use cases), but let's say I want to show a treatment only to users in certain countries, and I am able to pass the country in as an argument. Here is a workaround that worked when quickly playing with the PlanOut editor:

whitelist = @{'US': 1, 'UK': 1};
if (whitelist[country] != null) {
  result = "a";
} else {
  result = uniformChoice(choices=['b', 'c', 'd'], unit=country);
}

Basically, I just create a dictionary containing (as keys) the values I want to whitelist and set their (dictionary) values to any (non-null) value. This seems like it works, and is probably more performant than having to iterate through a list to check for existence of an element, especially if the list is very long. One could argue that this benefit outweighs the awkwardness of having to use a dictionary with dummy values just to check for simple existence, but seems like a relatively minor issue.

If this seems reasonable to recommend as an approach for this situation, I could make a pull request to update the documentation at some point. Or, does anyone have better ideas in mind?

@bric3
Copy link

bric3 commented Nov 15, 2017

@omnilinguist I agree that Planout DSL is missing a few things in that regard

  • an operator ==
  • an operator in and/or a set data structure.

For beta-testers I was able to avoid the if/else using the dictionary directly :

beta_users = @{ '1242354':'beta', 'qwqewwe':'beta', '00t634986':'beta' };
is_beta = beta_users[user_guid];

But this can be a bit tedious to type, but more importantly it is error prone.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants