Code Monkey home page Code Monkey logo

valin's Introduction

Valin

Valin is a validation library for Kotlin, used to validate keys within any type of map.

Usage

Contains the map extension function Validate.kt/Map<K, V>.validate. It uses the following syntax:

map.validate {
validate (key, errorString) Function1
validate (key, errorString) { it == 5 }
validate (key, errorString) Function1
....
}

For each validate call, the key is used to look up a value in the map. The map value is then tested with the predicate function. If the predicate fails, the error message is included in the map of errors returned by the validate extension function. A key may be tested multiple times with different predicates and errors.

If no predicate fails, emptyMap() is returned. If at least one predicate fails, a map of keys to error is returned:

{key1=listOf(error1),
 key2=listOf(error2, error3),
 ...
 keyn=listOf(errorn)} => this is what toString() returns

For example:

val map = mapOf("name" to "Bob")

map.validate {
  validate ("name", "Name must be Joel") { x: String -> x == "Joel" }
  }

=> {name=("Name must be Joel")}

Maven

You must configure your pom.xml file using JCenter repository

<repository>
    <id>central</id>
    <name>bintray</name>
    <url>http://jcenter.bintray.com</url>
</repository>
<dependency>
  <groupId>com.joelws</groupId>
  <artifactId>valin</artifactId>
  <version>1.1</version>
</dependency>

Gradle

        jcenter()
    }```  
```compile 'com.joelws:valin:1.1'```

valin's People

Contributors

jw-s avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.