Awesome Open Source
Awesome Open Source

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"])


Alternative Project Comparisons
Related Awesome Lists
Top Programming Languages
Top Projects

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Javascript (1,058,747
Validation (20,374
Functional Programming (10,963
Fantasy (1,871
Functor (546
Validation Library (485
Applicative (372
Typeclasses (303
Fantasy Land (73