Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*We define a list of alien species*/
- val aliens_species = List[String]("gazorpian","supernova","birdman", "sqanchy")
- /*Now we define a function that checks if a string is an alien species*/
- def isAlien(maybe_alien:String) = aliens_species.contains(maybe_alien)
- /*We pass the function isAlien as a parameter to the filter function*/
- var list = List[String]("human","dog","gazorpian","birdman")
- val aliens = list.filter(isAlien) //result : List(gazorpian, birdman)
Add Comment
Please, Sign In to add comment