-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove polymorphic monads #219
Conversation
func NearestVCS(dirname string) (vcsType cli.VCS, vcsDir string, err error) { | ||
vcsDir, err = files.WalkUp(dirname, func(d string) error { | ||
tool, err := vcsIn(d) | ||
func Nearest(dirname string) (VCS, string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 to this and other renames
// containing the directory, or ErrNoNearestVCS if none is found. | ||
func NearestVCS(dirname string) (vcsType cli.VCS, vcsDir string, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the move away from named returns?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just avoid them where possible, because assignment in Go follows unintuitive shadowing rules. I usually only use named returns when returning multiple values of the same type.
Example of weird shadowing:
func Foo() (bar string) {
bar, err := Baz() // This is a _different_ bar, shadowing the original
return // Implicitly returns `bar = ""`, the string type's zero value
}
- Documentation on named returns
- More shadowing examples:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! This is so much cleaner and DRYer. lgtm 👍
ab5c1cd
to
d638517
Compare
Fixes #210.