Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@Lensflare Set of unit has two states; it either contains unit or doesn't.
Set of never has one state, empty. -
@lorentz oh, I like this! Is it Rust? It’s quite similar to Swift and Kotlin.
() == empty tuple == Unit == Void
Never == Nothing
Here is an implementation in Swift:
extension Set where Element == Void {
static var true: Self { [()] }
static var false: Self { [] }
}
let myBoolValue: Set<()> = .true
I could also add some operator overloading for negation and && and || but that’s trivial and boring. -
@lorentz
Implementation with Never.
First I thought it won‘t be possible because you can‘t have instances of Never, but actually I don‘t need any. I just need an empty set of Set<Never>
Implement boolean as `HashSet<()>`
joke/meme