The Wayback Machine - https://web.archive.org/web/20201212202914/https://github.com/notgiorgi/data.validation
Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Validation library for Algebraic Data Types

data Validation a b = Failure a
                    | Success b

API

Validation type implements Functor and Applicative typeclasses in fantasy-land spec

instance Functor (Validation a)
instance Monoid a => Applicative (Validation a)

additional methods:

fold :: Validation a b ~> (a -> c) -> (b -> c) -> c

isSuccess :: Validation t a ~> bool

fail :: t -> Validation t a

example:

const Person = R.curry(
  daggy.tagged('Person', ['name', 'age'])
)

const checkName = name =>
  name.length > 2
  ? Success(name)
  : Failure(["name should be more then 2 characters long"])

const checkAge = age =>
  age >= 13
  ? Success(age)
  : Failure(["you should be at least 13 years old"])

const lift2 = ctor => x => y => x.map(ctor).ap(y)

const mkPerson = (name, age) => lift2(Person)(name)(age)

mkPerson(
  checkName("George Martin"),
  checkAge(68)
).toString() // Validation.Success(Person("George Martin", 68))

mkPerson(
  checkName("f"),
  checkAge(11),
).toString() // Validation.Failure(["name should be more then 2 characters long", 
             //                     "you should be at least 13 years old"])

About

Fantasy-land compliant Applicative-style validation

Topics

Resources

License

Releases

No releases published

Packages

No packages published
You can’t perform that action at this time.