Skip to content

Instantly share code, notes, and snippets.

@kijuky
Created April 9, 2016 16:53
Show Gist options
  • Save kijuky/ec9451225eb175d426eb7d9ec3a31cdf to your computer and use it in GitHub Desktop.
Save kijuky/ec9451225eb175d426eb7d9ec3a31cdf to your computer and use it in GitHub Desktop.
Scala の filterNot が遅延評価されない (Scala 2.11.8)
$ scala
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_74).
Type in expressions for evaluation. Or try :help.
scala> val s = (1 to 10).toStream
s: scala.collection.immutable.Stream[Int] = Stream(1, ?)
scala> s.map(s => {println(" " + s); s}).filter(_ % 2 == 0).foreach(println)
1
2
2
3
4
4
5
6
6
7
8
8
9
10
10
scala> s.map(s => {println(" " + s); s}).filterNot(_ % 2 == 0).foreach(println)
1
2
3
4
5
6
7
8
9
10
1
3
5
7
9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment