SCALA PARA COMPRENSIÓN SINTAXIA
-
30-10-2019 - |
Pregunta
En el siguiente código, dentro del for
Comprensión, puedo referirme a la cadena y al índice utilizando un Tuple Desreference:
val strings = List("a", "b", "c")
for (stringWithIndex <- strings.zipWithIndex) {
// Do something with stringWithIndex._1 (string) and stringWithIndex._2 (index)
}
¿Hay alguna forma en la sintaxis de Scala para tener el stringWithIndex
dividirse en las partes (cadena e índice) dentro de for
encabezado de comprensión, para que los lectores del código no tengan que preguntarse los valores de stringWithIndex._1
y stringWithIndex._2
?
Intenté lo siguiente, pero no compilaría:
for (case (string, index) <- strings.zipWithIndex) {
// Do something with string and index
}
No hay solución correcta
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow