Created
April 27, 2014 06:41
-
-
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
This file contains hidden or 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.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