YAPC::EU 2018 Glasgow Update!
This commit is contained in:
parent
22f33d4004
commit
4e2d22a71d
1170 changed files with 15042 additions and 3047 deletions
30
Task/Inverted-syntax/Go/inverted-syntax.go
Normal file
30
Task/Inverted-syntax/Go/inverted-syntax.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type ibool bool
|
||||
|
||||
const itrue ibool = true
|
||||
|
||||
func (ib ibool) iif(cond bool) bool {
|
||||
if cond {
|
||||
return bool(ib)
|
||||
}
|
||||
return bool(!ib)
|
||||
}
|
||||
|
||||
func main() {
|
||||
var needUmbrella bool
|
||||
raining := true
|
||||
|
||||
// normal syntax
|
||||
if raining {
|
||||
needUmbrella = true
|
||||
}
|
||||
fmt.Printf("Is it raining? %t. Do I need an umbrella? %t\n", raining, needUmbrella)
|
||||
|
||||
// inverted syntax
|
||||
raining = false
|
||||
needUmbrella = itrue.iif(raining)
|
||||
fmt.Printf("Is it raining? %t. Do I need an umbrella? %t\n", raining, needUmbrella)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue