Last active
April 1, 2020 08:33
-
-
Save woat/90448968586c01e62f3ff5f05edbfe9e to your computer and use it in GitHub Desktop.
side effect import golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
WARNING: This product can expose you to chemicals including abestos, | |
which is known to the State of California to cause cancer and birth | |
defects or other reproductive harm. | |
For more information go to www.P65Warnings.ca.gov. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"side-effect/me" | |
// force gofmt to respect | |
_ "side-effect/infect" // ordering by using line | |
// breaks | |
_ "side-effect/cure" | |
) | |
func main() { | |
fmt.Println(me.State) // "cured" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me | |
import "side-effect/me" | |
var State = "empty" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package infect | |
import "side-effect/me" | |
// runs first | |
func init() { | |
me.State = "infected" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package cure | |
import "side-effect/me" | |
// runs second | |
func init() { | |
me.State = "cured" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment