w poniższym kodzie wewnątrz for
zrozumienia, że może odnosić się do napisu i indeksu za pomocą dereference krotka:Scala za-pojmowania składni
val strings = List("a", "b", "c")
for (stringWithIndex <- strings.zipWithIndex) {
// Do something with stringWithIndex._1 (string) and stringWithIndex._2 (index)
}
Czy istnieje jakiś sposób, w składni Scala mieć stringWithIndex
podzielone na części (ciąg i indeks) w nagłówku for
ze zrozumieniem, aby czytelnicy kodu nie musieli się zastanawiać nad wartościami stringWithIndex._1
i stringWithIndex._2
?
Próbowałem następujących, ale nie byłoby skompilować:
for (case (string, index) <- strings.zipWithIndex) {
// Do something with string and index
}
Doh! Powinienem tego spróbować :-). – Ralph