All Projects → RPallas92 → Swiftz-Validation

RPallas92 / Swiftz-Validation

Licence: MIT License
A data structure for validations. It implements the applicative functor interface

Programming Languages

swift
15916 projects
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to Swiftz-Validation

Language Ext
C# functional language extensions - a base class library for functional programming
Stars: ✭ 3,964 (+26326.67%)
Mutual labels:  functor, semigroup, applicative
functional-structures-refactoring-kata
Starting code and proposed solution for Functional Structures Refactoring Kata
Stars: ✭ 31 (+106.67%)
Mutual labels:  functional, functor, applicative
Deep Waters
🔥Deep Waters is an easy-to-compose functional validation system for javascript developers 🔥
Stars: ✭ 188 (+1153.33%)
Mutual labels:  functional, validation
kudojs
A utility library to write code in functional programming style in Javascript
Stars: ✭ 22 (+46.67%)
Mutual labels:  functor, applicative
function-composition-cheatsheet
Composition of Functions
Stars: ✭ 24 (+60%)
Mutual labels:  fp, functor
Sup
Composable, purely functional healthchecks in Scala.
Stars: ✭ 138 (+820%)
Mutual labels:  functional, fp
Kotlin Openapi Spring Functional Template
🍃 Kotlin Spring 5 Webflux functional application with api request validation and interactive api doc
Stars: ✭ 159 (+960%)
Mutual labels:  functional, validation
elixir-control
An exploratory look into functors, applicatives, and monads for Elixir
Stars: ✭ 21 (+40%)
Mutual labels:  functor, applicative
Remeda
A utility library for JavaScript and TypeScript.
Stars: ✭ 774 (+5060%)
Mutual labels:  functional, programming
apropos
Fast strong typed 'Either' data structure for typescript and flow
Stars: ✭ 20 (+33.33%)
Mutual labels:  functional, fp
polyrpc
PolyRPC, A multi-tier functional programming language
Stars: ✭ 16 (+6.67%)
Mutual labels:  functional, programming
cpsfy
🚀 Tiny goodies for Continuation-Passing-Style functions, fully tested
Stars: ✭ 58 (+286.67%)
Mutual labels:  functor, applicative
validation
Validation in Ruby objects
Stars: ✭ 18 (+20%)
Mutual labels:  functional, validation
Arare
Lightweight curried functional programming library
Stars: ✭ 127 (+746.67%)
Mutual labels:  functional, programming
Openapi Spring Webflux Validator
🌱 A friendly kotlin library to validate API endpoints using an OpenApi 3.0 and Swagger 2.0 specification
Stars: ✭ 67 (+346.67%)
Mutual labels:  functional, validation
fnts
λ Minimal Functional Programming Utilities for TypeScript & JavaScript
Stars: ✭ 75 (+400%)
Mutual labels:  functional, fp
pyroclastic
Functional dataflow through composable computations
Stars: ✭ 17 (+13.33%)
Mutual labels:  functional, fp
Kotlin Result
A multiplatform Result monad for modelling success or failure operations.
Stars: ✭ 369 (+2360%)
Mutual labels:  functional, fp
Fkit
A functional programming toolkit for JavaScript.
Stars: ✭ 588 (+3820%)
Mutual labels:  functional, fp
Functor
Mappable objects
Stars: ✭ 20 (+33.33%)
Mutual labels:  fp, functor

Swiftz-Validation

A data structure that typically models form validations, and other scenarios where you want to aggregate all failures, rather than short-circuit if an error happens (for which Swiftx's Either is better suited). A Validation may either be a Success(value), which contains a successful value, or a Failure(value), which contains an error.

Docs: Swiftz-Validation docs

Example

    func isPasswordLongEnough(_ password:String) -> Validation<[String], String> {
        if password.characters.count < 8 {
            return Validation.Failure(["Password must have more than 8 characters."])
        } else {
            return Validation.Success(password)
        }
    }
    
    func isPasswordStrongEnough(_ password:String) -> Validation<[String], String> {
        if (password.range(of:"[\\W]", options: .regularExpression) != nil){
            return Validation.Success(password)
        } else {
            return Validation.Failure(["Password must contain a special character."])
        }
    }
    
    func isPasswordValid(password:String) -> Validation<[String], String> {    
        return isPasswordLongEnough(password)
            .sconcat(isPasswordStrongEnough(password))
    }
    

Valid value

   let result = isPasswordValid(password: "Ricardo$")

   /*
       ▿ Validation<Array<String>, String>
           - Success : "Ricardo$"
   */

Invalid value

    let result = isPasswordValid(password: "Richi")
    
    /* ▿ Validation<Array<String>, String>
           ▿ Failure : 2 elements
                - 0 : "Password must have more than 8 characters."
                - 1 : "Password must contain a special character."
    */
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].