Created
February 15, 2015 18:28
-
-
Save OlegEfrem/02a7ed565619588ab4ba to your computer and use it in GitHub Desktop.
Random quote from URL file
This file contains 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
import scala.collection.mutable.ListBuffer | |
import scala.io.Source | |
import scala.util.Random | |
val sourceLines = Source.fromURL("http://www.coverfire.com/files/quotes.txt","UTF-8").getLines() | |
val quotes = new ListBuffer[String] | |
sourceLines.reduceLeft((a,b) => if (b.nonEmpty) a + " " + b else {quotes.+=(a.trim); ""}) | |
val randomQuote = quotes.apply(Random.nextInt(quotes.size)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment