Last active
February 13, 2016 15:17
-
-
Save Locke/0761150d6e933e6ec651 to your computer and use it in GitHub Desktop.
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
package locke.util.matching | |
import scala.util.matching.Regex | |
import scala.concurrent.Future | |
object implicits { | |
implicit class ConcurrentRegex(private val regex: Regex) extends AnyVal { | |
def replaceAllInConcurrent(target: CharSequence, replacer: Regex.Match => Future[String])(implicit ctx: scala.concurrent.ExecutionContext): Future[String] = { | |
val f: Iterator[Future[String]] = regex.findAllMatchIn(target).map(replacer) | |
Future.sequence(f).map( it2 => { | |
regex.replaceAllIn(target, y => it2.next) | |
}) | |
} | |
def replaceSomeInConcurrent(target: CharSequence, replacer: Regex.Match => Future[Option[String]])(implicit ctx: scala.concurrent.ExecutionContext): Future[String] = { | |
val f: Iterator[Future[Option[String]]] = regex.findAllMatchIn(target).map(replacer) | |
Future.sequence(f).map( it2 => { | |
regex.replaceSomeIn(target, y => it2.next) | |
}) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment