Created
October 3, 2021 20:19
-
-
Save lucaspolo/81a51432a489f403f9b3f846b8ec65e9 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
object CasamentoDePadroes extends App { | |
// Pattern matching apicado a recuperação de valores de uma lista | |
val lista = List(1,2,3,4,5) | |
val primeiro :: resto = lista | |
println(primeiro) | |
println(resto) | |
// Utilizando guardas como filtro | |
val pares = for { | |
x <- lista if x % 2 == 0 | |
} yield x | |
print(pares) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment