Guest User

Untitled

a guest
Jul 20th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. /*We define a list of alien species*/
  2. val aliens_species = List[String]("gazorpian","supernova","birdman", "sqanchy")
  3.  
  4. /*Now we define a function that checks if a string is an alien species*/
  5. def isAlien(maybe_alien:String) = aliens_species.contains(maybe_alien)
  6.  
  7. /*We pass the function isAlien as a parameter to the filter function*/
  8. var list = List[String]("human","dog","gazorpian","birdman")
  9. val aliens = list.filter(isAlien) //result : List(gazorpian, birdman)
Add Comment
Please, Sign In to add comment