3 ms·
Go effectively has Option types for database query results: https://golang.org/pkg/database/sql/#NullBool https://golang.org/pkg/database/sql/#NullBool
by brobinson 10y ago
Go effectively has Option types for database query results: https://golang.org/pkg/database/sql/#NullBool https://golang.org/pkg/database/sql/#NullBool
- unscaled 10y agoThis is not a generic option type, but rather a tri-state bool, or an Option<bool>. Go has no user-defined generics, so you can't have a bool type. It does have built-in "magical" generics, namely arrays, slices maps and channels, but no option/maybes. Language-level option types are not unheard of (C#, Swift and Kotlin all have a notion of this sort, although they all support proper user-defined generics as well).
- masklinn 10y ago> Language-level option types are not unheard of (C#, Swift and Kotlin all have a notion of this sort) Swift's Optional is a library type: https://github.com/apple/swift/blob/master/stdlib/public/core/Optional.swift#L122 https://github.com/apple/swift/blob/master/stdlib/public/cor... Though the compiler is aware of it and it does have language-level support (nil, !, ?, if let)