-
Notifications
You must be signed in to change notification settings - Fork 179
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
Add flatten function that collapses first dimension of an iterable into a list. #413
base: main
Are you sure you want to change the base?
Conversation
This seems like a very low value thing to add. It is basically a wrapper for a one line list comprehsension. |
The use case I have is: flatten([
select({
":%s_enabled" % feature: ["//some/path/%s:deps" % feature],
"//conditions:default": [],
})
for feature in ALL_FEATURES
]) IMO that is a lot clearer than: [target for target in sublist for sublist in [
select({
":%s_enabled" % feature: ["//some/path/%s:deps" % feature],
"//conditions:default": [],
})
for feature in ALL_FEATURES
]] |
What are you actually trying to accomplish with that?
…On Tue, Nov 15, 2022 at 11:36 AM Sami Kalliomäki ***@***.***> wrote:
The use case I have is:
flatten([
select({
":%s_enabled" % feature: ["//some/path/%s:deps" % feature],
"//conditions:default": [],
})
for feature in ALL_FEATURES
])
IMO that is a lot clearer than:
[target for target in sublist for sublist in [
select({
":%s_enabled" % feature: ["//some/path/%s:deps" % feature],
"//conditions:default": [],
})
for feature in ALL_FEATURES
]]
—
Reply to this email directly, view it on GitHub
<#413 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAXHHHBYFTZQJURK73GSL3LWIO3Y7ANCNFSM6AAAAAASBCHZ2M>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
I want to allow passing in a command line argument to allow selecting which features to include. Because the number of "features" is large (around 100 in my case) and changes often, it is not feasible to do this without for loops. |
Actually the list comprehension implementation does not work with selects. Updated implementation. |
It's not my call, but I don't think we should be adding more functions to skylib unless they fill a clear need for many users. I won't be approving or merging this. Anyone else? |
To be fair, I found this PR when looking for "bazel-skylib flatten" in my favorite search engine. :) In general, I agree with not including it as-is, because "flatten" name alone is ambiguous: it does not specify how deep of nesting it will unflatten. E.g. this:
Can be flattened to:
... and all of them will be correct by some definition of flatten. Exercise to the reader: which result is the one in the PR? |
No description provided.