yield keyword - Convert a traversable to another at run time in scala -


i able go through bs of traversable of a. tried following code:

object test {   class   class b extends   class c extends   var someas: traversable[a] = ...   def thebofsomeas: traversable[b] = for(a <- someas) {     match {       case b:b => yield b       case _ =>     }   } } 

but not compile, because says expression has type unit. how achieve ?

compiler thinks return type unit because if go not b case you're returning nothing.

use collect, easier read:

def thebofsomeas: traversable[b] = someas.collect { case b: b => b } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -