Scala - can 'for-yield' clause yields nothing for some condition?
In Scala language, I want to write a function that yields odd numbers within a given range. The function prints some log when iterating even numbers. The first version of the function is: def getOdds(N: Int): Traversable[Int] = { val list = new mutable.MutableList[Int] for (n <- 0 until N) { if (n % 2 == 1) { list += n } else { println("skip even number " + n) } } return list } If I omit printing logs, the implementation become very simple: def getOddsWithoutPrint(N: Int) = for (n <- 0 until N if (n % 2 == 1)) yield n However, I don't want to miss the logging part. How do I rewrite the first