Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ashwanthkumar/predicates
Missing methods on (T => Boolean) functions.
https://github.com/ashwanthkumar/predicates
Last synced: about 8 hours ago
JSON representation
Missing methods on (T => Boolean) functions.
- Host: GitHub
- URL: https://github.com/ashwanthkumar/predicates
- Owner: ashwanthkumar
- Created: 2014-12-26T22:41:02.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2014-12-27T06:52:12.000Z (almost 10 years ago)
- Last Synced: 2024-04-14T09:19:02.235Z (7 months ago)
- Language: Scala
- Size: 215 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![Build Status](https://snap-ci.com/ashwanthkumar/predicates/branch/master/build_image)](https://snap-ci.com/ashwanthkumar/predicates/branch/master)
# predicates
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.## Dependencies
`predicates` is published for the following scala versions: `2.11`, `2.10`, `2.9.3`, `2.9.2`, `2.9.1`.For Maven
```xmlin.ashwanthkumar
predicates_${scala.version}
0.0.2```
For SBT,
```sbt
libraryDependencies += "in.ashwanthkumar" %% "predicates" % "0.0.2"
```## Usage
I prefer to use predicates while writing data validators.```scala
import in.ashwanthkumar.predicates._case class Model(id: Int, name: String)
class ModelValidator {
def hasId = (model: Model) => model.id > 0
def hasName = (model: Model) => model.name != null && !model.name.isEmptydef all = hasId and hasName
def any = hasId or hasNamedef validate = (all thenDo Success) orElse (not(all) thenDo Failure)
}
```## Dev
```bash
$ git clone https://github.com/ashwanthkumar/predicates.git
$ cd predicates
$ sbt test
```## License
[Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0)