Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/justinwoo/purescript-home-run-ball
A library for applying a row of rules for validation to refine a value
https://github.com/justinwoo/purescript-home-run-ball
purescript refinement row-types validation
Last synced: about 2 months ago
JSON representation
A library for applying a row of rules for validation to refine a value
- Host: GitHub
- URL: https://github.com/justinwoo/purescript-home-run-ball
- Owner: justinwoo
- License: mit
- Created: 2017-09-04T18:22:27.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-06-20T20:19:16.000Z (over 6 years ago)
- Last Synced: 2024-10-11T23:44:39.842Z (2 months ago)
- Topics: purescript, refinement, row-types, validation
- Language: PureScript
- Homepage:
- Size: 10.7 KB
- Stars: 12
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Purescript Home Run Ball
[![Build Status](https://travis-ci.org/justinwoo/purescript-home-run-ball.svg)](https://travis-ci.org/justinwoo/purescript-home-run-ball)
A library for applying a row of rules for validation on any values, returning the original data with the rules applied or a list of the rules that failed.
![](http://i.imgur.com/VOYNDVW.png)
See the [blog post](https://qiita.com/kimagure/items/eeb40541fc56b8dba2cc) about this library.
## Example
@joneshf made a cool demo [here](https://github.com/joneshf/purescript-home-run-ball-demo) showing off this library and [Sparkle](https://github.com/sharkdp/purescript-sparkle).
Here's some selected excerpts from the tests:
```hs
onlyOnApples ::
ValidatedValue (beginsApple :: BeginsWith "Apple") String
-> String
onlyOnApples _ = "U R COOL"validOf :: forall a errors rules rl
. RowToList rules rl
=> CheckRules rl errors rules a
=> RProxy rules
-> a
-> V (NonEmptyList (Variant errors)) a
validOf _ s = pure srules = RProxy :: RProxy (beginsApple :: BeginsWith "Apple")
expected :: V (NonEmptyList (Variant (beginsApple :: String))) String
expected = validOf rules "U R COOL"main :: _
main = run [consoleReporter] do
describe "purescript-home-run-ball" do
it "works with valid string" do
let
checkedString = checkRules rules "AppleSDdf"
isValid checkedString `shouldEqual` true
expected `shouldEqual` (onlyOnApples <$> checkedString)
```