Skip to content

Instantly share code, notes, and snippets.

@tototoshi
Created December 23, 2011 08:48
Show Gist options
  • Save tototoshi/1513617 to your computer and use it in GitHub Desktop.
Save tototoshi/1513617 to your computer and use it in GitHub Desktop.
Filters are monoids
scala> val gt10: Int => Boolean = (n: Int) => n > 10
gt10: Int => Boolean = <function1>
scala> val lt5: Int => Boolean = (n: Int) => n < 5
lt5: Int => Boolean = <function1>
scala> 0 to 15 filter (lt5 |+| gt10)
res35: scala.collection.immutable.IndexedSeq[Int] = Vector(0, 1, 2, 3, 4, 11, 12, 13, 14, 15)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment