ashwanthkumar / predicates   0.0.2


Missing methods on (T => Boolean) functions.

Scala versions: 2.11 2.10

Build Status


Wouldn't it be so nice if we can do something like (validUserName and validPassword and validCaptcha) thenDo Success where validUserName, validPassword and validCaptcha are functions of type T => Boolean. predicates helps you do exactly that. It provides simple wrapper methods to pimp your T => Boolean functions with and, or and not so that we can write more expressive[subjective] code.


predicates is published for the following scala versions: 2.11, 2.10, 2.9.3, 2.9.2, 2.9.1.

For Maven


For SBT,

libraryDependencies += "in.ashwanthkumar" %% "predicates" % "0.0.2"


I prefer to use predicates while writing data validators.

import in.ashwanthkumar.predicates._

case class Model(id: Int, name: String)

class ModelValidator {
    def hasId = (model: Model) => > 0
    def hasName = (model: Model) => != null && !

    def all = hasId and hasName
    def any = hasId or hasName

    def validate = (all thenDo Success) orElse (not(all) thenDo Failure)


$ git clone
$ cd predicates
$ sbt test


Apache 2.0