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.io.Source | |
//read a file and build a concordance list of the tokens in the file | |
//there's gotta be a nicer way to do this | |
def two(fileName:String) = { | |
val chunkSize = 1024 | |
Source.fromFile(fileName).getLines() | |
// read in chunkSize lines into memory at once | |
// From: http://stackoverflow.com/questions/6751463/iterate-over-lines-in-a-file-in-parallel-scala | |
.grouped(chunkSize) |
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
object FutureOps extends FutureOps | |
trait FutureOps { | |
def toTry[A](self: Future[A])(implicit ec: ExecutionContext): Future[Try[A]] = { | |
val p = Promise[Try[A]]() | |
self onComplete { case result => p.success(result) } | |
p.future | |
} | |
def takeFirstMatch[A](futures: Traversable[Future[A]], predicate: A => Boolean)(implicit ec:ExecutionContext): Future[Option[A]] = { | |
if(futures.nonEmpty) { | |
val promise = Promise[Option[A]]() |
NewerOlder