Git Product home page Git Product logo

purescript-validation's Introduction

Module Documentation

Module Data.Validation

This module defines an applicative functor for applicative validation.

Applicative validation differs from monadic validation using Either in that it allows us to collect multiple errors using a Semigroup, whereas Either terminates on the first error.

V

data V err result

The V functor, used for applicative validation

The Applicative instance collects multiple failures in an arbitrary Semigroup.

For example:

validate :: Person -> V [Error] Person
validate person = { first: _, last: _, email: _ }
  <$> validateName person.first
  <*> validateName person.last
  <*> validateEmail person.email

invalid

invalid :: forall err result. err -> V err result

Fail with a validation error

runV

runV :: forall err result r. (err -> r) -> (result -> r) -> V err result -> r

Unpack the V type constructor, providing functions to handle the error and success cases.

isValid

isValid :: forall err result r. V err result -> Boolean

Test whether validation was successful or not

showV

instance showV :: (Show err, Show result) => Show (V err result)

functorV

instance functorV :: Functor (V err)

applyV

instance applyV :: (Semigroup err) => Apply (V err)

applicativeV

instance applicativeV :: (Semigroup err) => Applicative (V err)

Module Data.Validation.Semiring

This module defines an Alternative instances for validations that supports errors with multiple alternatives

This validation works exactly as Data.Validation but uses Semiring instead of Semigroup

V

data V err res

The V functor, used for alternative validation

The Alternative instance collects multiple failures in an arbitrary Semiring.

For example:

import Data.Semiring.Free

validate r :: Person -> V (Free Error) Person 
validate person = { first: _, last: _, contact: _}
  <$> validateName person.first
  <*> validateName person.last
  <*> (validateEmail person.contact <|> validatePhone person.contact)

invalid

invalid :: forall err result. err -> V err result

Fail with a validation error

runV

runV :: forall err result r. (err -> r) -> (result -> r) -> V err result -> r

Unpack the V type constructor, providing functions to handle the error and success cases.

isValid

isValid :: forall err result. V err result -> Boolean

Test whether validation was successful or not

showV

instance showV :: (Show err, Show result) => Show (V err result)

functorV

instance functorV :: Functor (V err)

applyV

instance applyV :: (Semiring err) => Apply (V err)

applicativeV

instance applicativeV :: (Semiring err) => Applicative (V err)

altV

instance altV :: (Semiring err) => Alt (V err)

plusV

instance plusV :: (Semiring err) => Plus (V err)

alernativeV

instance alernativeV :: (Semiring err) => Alternative (V err)

purescript-validation's People

Contributors

paf31 avatar garyb avatar cryogenian avatar

Watchers

James Cloos 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.