Created
April 15, 2014 10:13
-
-
Save JakeCoxon/10720090 to your computer and use it in GitHub Desktop.
Print stdin without duplicates
This file contains hidden or 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
object Unique { | |
def main(args: Array[String]) { | |
val h = collection.mutable.Set[String]() | |
def uniq(ln : String) = Some(ln) filter (h.add(_)) | |
for (ln <- io.Source.stdin.getLines; | |
ln <- uniq(ln)) { | |
println(ln) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment