Skip to content

Instantly share code, notes, and snippets.

@mallochine
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mallochine/9039926 to your computer and use it in GitHub Desktop.
Save mallochine/9039926 to your computer and use it in GitHub Desktop.
class SomeParser {
parse(line) {
// Do some parsing work.
}
dataReady() {
// Easy way for others to figure out if the parser has data that's ready to be collected.
}
}
class SomeWorker {
handle(line) {
SomeParser.parse(line);
// For why dataReady() make good design, see Note 1.
if (SomeParser.dataReady()) {
data = SomeParser.getData();
// Do some stuff with data.
}
}
finish() {
// Write this only if you want to print something out once
// your program is done reading from the stream.
}
// other helper functions here...
}
int main() {
while stdin.hasNextLine():
SomeWorker.handle( stdin.nextLine() );
// Only if you need to output additional data at the end of the stream.
SomeWorker.finish();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment