A simple example like following:
val set = Set(0, 1, 2)
Stream.from(0).filterNot(set).head
it seems loop forever; but the following code works:
Stream.from(0).filter(!set(_)).head
I am using
Scala code runner version 2.11.4 -- Copyright 2002-2013, LAMP/EPFL
Is this a bug? or any reason for this?
According to the ticket: https://issues.scala-lang.org/browse/SI-8627 the implementation of filterNot which applies to Streams is not lazy, which would manifest in what you are seeing.
So, appears to be a bug and according to the ticket, no way has been found to fix it without either significant performance penalties to other collections or else breaking binary compatibility, hence it seems to be targeted at a major release (2.12)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.