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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adding a Not() function for bool and bool pointer outputs #12503

Open
justinvp opened this issue Mar 25, 2023 · 4 comments
Open

Consider adding a Not() function for bool and bool pointer outputs #12503

justinvp opened this issue Mar 25, 2023 · 4 comments
Labels
area/sdks Pulumi language SDKs customer/feedback Feedback from customers kind/enhancement Improvements or new features language/go

Comments

@justinvp
Copy link
Member

Hello!

  • Vote on this issue by adding a 馃憤 reaction
  • If you want to implement this feature, comment to let us know (we'll work with you on design, scheduling, etc.)

Issue details

A useful quality of life improvement would be to have a Not() function that chains onto Bool outputs and Bool pointer outputs, and will invert them - very common to need the inverse of a disable on a component to pass to an enable on an inner resource or similar.

This would simplify variants like the following:

var enableFoo p.BoolInput = p.Bool(true)
if args.DisableFoo != nil {
	enableFoo = args.DisableFoo.ToBoolPtrOutput().Elem().ApplyT(func(v interface{}) bool { return !v.(bool) }).(p.BoolOutput)
}
@justinvp justinvp added area/sdks Pulumi language SDKs kind/enhancement Improvements or new features language/go customer/feedback Feedback from customers labels Mar 25, 2023
@justinvp
Copy link
Member Author

Related to #11939

@Frassle
Copy link
Member

Frassle commented Mar 25, 2023

Wondering if this makes sense for other SDKs as well? It's much less painful for every other language because it would just be something like args.DisableFoo.Apply(b => !b) but we could still save the apply call here with Output.Not(args.DisableFoo).

Do we want to consider other basic operators as well (especially for Go)? Like Negate, Add, Subtract, etc?

@dixler
Copy link
Contributor

dixler commented Mar 25, 2023

Wondering if this makes sense for other SDKs as well? It's much less painful for every other language because it would just be something like args.DisableFoo.Apply(b => !b) but we could still save the apply call here with Output.Not(args.DisableFoo).

Since it's easy to do in other languages without helpers, I don't think it's worth increasing the surface area of the public API we have to maintain.

I do like the idea for Go.

@abhinav
Copy link
Contributor

abhinav commented Mar 27, 2023

Since it's easy to do in other languages without helpers, I don't think it's worth increasing the surface area of the public API we have to maintain.

I have mixed feelings about this; I agree that adding things that aren't necessary is wasteful.
But it would be nice to have some consistency on what we expose between languages (as long as it's similarly idiomatic).
If we're adding the helper to Go, it wouldn't be terrible to also add it to everything else where this is currently an apply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/sdks Pulumi language SDKs customer/feedback Feedback from customers kind/enhancement Improvements or new features language/go
Projects
None yet
Development

No branches or pull requests

4 participants