From 22c78d20992967e24ec8c8cf5adaf7466d3d0fd7 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Fri, 21 Apr 2017 12:56:34 +0200 Subject: Unify file / stdin input processing --- source/app.d | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'source') diff --git a/source/app.d b/source/app.d index dd7be6d..b9f68c4 100644 --- a/source/app.d +++ b/source/app.d @@ -1,23 +1,24 @@ +import std.conv : to; import std.string : split; import std.range : dropOne; import std.algorithm : map, each; -import std.stdio : stdin, File, lines; +import std.stdio : stdin, File; static import machine; +void process(string line) { + line.split.each!(machine.process); +} + void process(ref File file) { - foreach ( string line; lines(file) ) { - line.split.each!(machine.process); - } + file.byLine.map!(to!string).each!process; } void main(string[] args) { args .dropOne - .map!(File) + .map!File .each!((File file) => file.process); - while ( !stdin.eof ) { - stdin.readln.split.each!(machine.process); - } + stdin.process; } -- cgit v1.2.3