Skip to content

Instantly share code, notes, and snippets.

@Jazzatola
Last active August 29, 2015 14:19
Show Gist options
  • Save Jazzatola/831bd99e948b221ba57b to your computer and use it in GitHub Desktop.
Save Jazzatola/831bd99e948b221ba57b to your computer and use it in GitHub Desktop.
package org.example
case class PimpMyPredicate[A](f: A => Boolean) {
def &&(g: A => Boolean): A => Boolean = a => g(a) && f(a)
}
object PimpMyPredicate {
implicit def enrichPredicate[A](f: A => Boolean): PimpMyPredicate[A] = PimpMyPredicate(f)
}
object Main {
import PimpMyPredicate._
val isNegative: Int => Boolean = _ < 0
val isEven: Int => Boolean = _ % 2 == 0
def main(args: Array[String]) {
println(List(1, 2, -3, -4, 5, -6).filter(isEven && isNegative))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment