1. kimagure

    No comment

    kimagure
Changes in body
Source | HTML | Preview
@@ -1,5 +1,7 @@
+Edit: I updated the usage of Eff to Effect to account for updates to PureScript, but everything else here is largely the same.
+
In many programs that we write, we have the need to validate data before we perform any more operations. Unfortunately, most of time we end up with a solution that requires us to build a list of errors and check this list's contents for being empty, but there are easier and nicer solutions to this problem. This is where PureScript's Validation library comes into play.
## What is Validation?
```hs
@@ -68,22 +70,22 @@
```
And we can use this validated value already.
```hs
-printMyValidated :: MyValidated FormData -> Eff _ Unit
+printMyValidated :: MyValidated FormData -> Effect Unit
printMyValidated = unV
(\errors -> log $ "got errors: " <> intercalate ", " errors)
(\formData ->
log
$ "the apples were "
<> formData.appleColor
<> " and the bananas "
<> formData.bananaColor
)
-main :: forall e. Eff (console :: CONSOLE | e) Unit
+main :: Effect Unit
main = do
printMyValidated testMyValidated
-- output:
-- the apples were red and the bananas yellow
```
@@ -101,11 +103,11 @@
errorMyValidated2 =
{ appleColor: _, bananaColor: _, carrotColor: testData.carrotColor }
<$> appleIsRed "yellow"
<*> bananaIsNotGreen "green"
-main :: forall e. Eff (console :: CONSOLE | e) Unit
+main :: Effect Unit
main = do
printMyValidated testMyValidated
-- output:
-- the apples were red and the bananas yellow