Created
February 23, 2016 01:01
-
-
Save elisarver/4f3d9b4e2786feb348c9 to your computer and use it in GitHub Desktop.
From Errors are Values (https://blog.golang.org/errors-are-values) – a pretty fantastic use of closures. Each of those writes passes along the result of the write to the next command and exits *before* trying the next step. This may solve an issue I've been having in several languages.
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
var err error | |
write := func(buf []byte) { | |
if err != nil { | |
return | |
} | |
_, err = w.Write(buf) | |
} | |
write(p0[a:b]) | |
write(p1[c:d]) | |
write(p2[e:f]) | |
// and so on | |
if err != nil { | |
return err | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment