Skip to content

Instantly share code, notes, and snippets.

@JakeCoxon
Created April 15, 2014 10:13
Show Gist options
  • Save JakeCoxon/10720090 to your computer and use it in GitHub Desktop.
Save JakeCoxon/10720090 to your computer and use it in GitHub Desktop.
Print stdin without duplicates
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