Skip to content

Instantly share code, notes, and snippets.

@mallochine
Last active Aug 29, 2015
Embed
What would you like to do?
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