Set data structure in Starlark

841 views
Skip to first unread message

Diego Ortín

unread,
Sep 4, 2023, 9:05:33 AM9/4/23
to bazel-discuss
Is there a data structure similar to the Python "set" in Starlark? 

I have the need to ensure no duplicate values exist in a list, and in Python I would usually accomplish this using a set. What would be the best way to do this in Starlark?

Thanks in advance

Alexandre Rostovtsev

unread,
Sep 4, 2023, 9:25:27 AM9/4/23
to Diego Ortín, bazel-discuss
At the moment, there is no set data type in Starlark. You can use a library (for example, @bazel_skylib//lib:sets.bzl) or do it yourself by representing a set as a dict's keys.

In the long term, a set data type as a language feature probably makes sense; you can propose a Starlark language spec here: https://github.com/bazelbuild/starlark

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/e4382c9f-fb7b-4cc8-944d-4928205a8274n%40googlegroups.com.

Diego Ortín

unread,
Sep 11, 2023, 7:51:09 PM9/11/23
to Alexandre Rostovtsev, bazel-discuss
Thank you, I guess I have to consider if adding a dependency on Skylib is worth it over just using the dictionary keys, which sounds a bit hackish. 

I’ve had a look at the process for making design proposals to Starlark, and created the following issue: 
Reply all
Reply to author
Forward
0 new messages