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
Post a Comment