I have two functions (not these have been edited since the original -- some of the answers below are responding to the original ones which returned a sequence of ()):
1) The second one does not produce a warning probably because you are constructing the list (or the pattern) by prepending elements to the Nil
object, which extends List
parameterising it with Nothing
. And since everything is Nothing
, there is nothing to be worried about ;) But I'm not sure, really guessing here.
2) Why don't you just use:
def foo[A](ls: Iterable[A]) =
for (list <- ls sliding 2) yield ()