You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These would allow for multiple enum items to be applied as a single value, with efficient O(1) item detection. Algebraic enums or items with parameters will be allowed.
Example of bitmask types in Go:
typeMyEnumuint8const (
Option1MyEnum=1<<iotaOption2Option3
)
varmyValueMyEnum=Option1|Option3// Check for an option
(myValue&Option3) !=0// Assign an optionmyValue|=Option2// Remove an optionmyValue &^= Option1// JavaScript: myValue &= ~Option1
For Klar:
@flag // or '@flags'
type MyEnum {
.option1
.option2
.option3
}
myValue := MyEnum(.option1, .option3)
myOpts: [MyEnum] := [.option1, .option3]
myValue := MyEnum(myOpts...)
// Possible approaches for checking
myValue.has(.option3)
(.option3 in myValue)
// Possible approaches for setting
myValue.set(.option2, true) // Mutating
myValue.set(.option2) // `true` as a default param
myValue = myValue.with(.option2) // Non-mutating
myValue = MyEnum(myValue..., .option2)
myValue += .option2
// Possible approaches for removing
myValue.set(.option1, false) // Mutating
myValue = myValue.without(.option1, false) // Non-mutating
myValue -= .option1
To consider: If items with parameters are allowed, how can they be checked?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
These would allow for multiple enum items to be applied as a single value, with efficient O(1) item detection. Algebraic enums or items with parameters will be allowed.
Example of bitmask types in Go:
For Klar:
To consider: If items with parameters are allowed, how can they be checked?
All reactions