Skip to content

Instantly share code, notes, and snippets.

@Miuler
Created April 27, 2014 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Miuler/11339043 to your computer and use it in GitHub Desktop.
Save Miuler/11339043 to your computer and use it in GitHub Desktop.
Un scala workshet donde probé como una clase se puede usar como función en scala
import scala.util.matching.Regex.Match
val a = """Esto es un ejemplo de como ejemplo por que siempre ejemplo"""
val regex = "eje\\w*+" r
class Reemplazar[E](lista:List[E]) {
var i:Int = -1
def apply(replacer: Match) = {
if (i < lista.size - 1) {
i += 1
lista(i).toString
} else {
"BORRAR"
}
}
}
val reemplazar = new Reemplazar(List(1,2))
val _reemplazar: Match => String = reemplazar(_)
regex.replaceAllIn(a, _reemplazar)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment