Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ergonomics of ["contains"] expression #5226

Closed
anandthakker opened this issue Sep 1, 2017 · 3 comments
Closed

Improve ergonomics of ["contains"] expression #5226

anandthakker opened this issue Sep 1, 2017 · 3 comments
Labels
cross-platform 📺 Requires coordination with Mapbox GL Native (style specification, rendering tests, etc.)

Comments

@anandthakker
Copy link
Contributor

Quoting @jfirebaugh:

["contains", ["get", "type"], ["literal", ["primary_link"]]]

This seems overly clunky for a very common case. @anandthakker what do you think about two forms:

["in", needle, ...], where the varargs are required to be literals
["in", needle, haystack], where haystack is an array

Of course, writing it as ["match", ["get", "type"], ["primary_link", ...], true, false] is another option, and more efficient.

And a final option I'll throw out here: we could support a 2-arity form of match, ["match", input, [literals...]], which is syntactic sugar for ["match", input, [literals...], true, false]. This would be the recommended and most efficient form for when you're checking inclusion in a set of literals. "contains" would still exist, but you'd only want to use it when the second argument is not an array literal.

@mourner mourner added api 📝 cross-platform 📺 Requires coordination with Mapbox GL Native (style specification, rendering tests, etc.) and removed api 📝 labels Sep 1, 2017
@1ec5
Copy link
Contributor

1ec5 commented Sep 8, 2017

In Objective-C and Swift, NSPredicate has a CONTAINS operator that serves as both an array search operator and a substring search operator (#4113), depending on the type of the first argument. It’s a convenient option even when a MATCHES operator exists for regular expression filters (#4089).

There’s also an IN operator that reverses the order of the arguments, both for array and substring searches.

@nickidlugash
Copy link

This sounds great 👍 Just adding myself to follow the conversation. /cc @aparlato

@jfirebaugh
Copy link
Contributor

We removed contains in #5412; for the common case where the search array is a set of literal values, use ["match", needle, haystack, true, false] as suggested above instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cross-platform 📺 Requires coordination with Mapbox GL Native (style specification, rendering tests, etc.)
Projects
None yet
Development

No branches or pull requests

5 participants