-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from scoville/use-array-instead-of-lists
Use arrays instead of lists as they're cleaner and faster in our case
- Loading branch information
Showing
6 changed files
with
64 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,32 @@ | ||
include Formidable.Validations | ||
open Validator.Args | ||
open Optic | ||
|
||
let required = ( | ||
list{"required"}, | ||
({label, value}) => | ||
if value == "" { | ||
#error(#error(("required", label))) | ||
} else { | ||
#ok(value) | ||
let required = { | ||
Description.names: list{"required"}, | ||
validator: ({label, value}) => | ||
switch value { | ||
| "" => #error(#error(("required", label))) | ||
| _ => #ok(value) | ||
}, | ||
) | ||
} | ||
|
||
let emailRegEx = %re("/.+@.+/") | ||
|
||
let email = ( | ||
list{"email"}, | ||
({label, value}) => | ||
if Js.Re.test_(emailRegEx, value) { | ||
let email = { | ||
Description.names: list{"email"}, | ||
validator: ({label, value}) => | ||
if emailRegEx->Js.Re.test_(value) { | ||
#ok(value) | ||
} else { | ||
#error(#error(("email", label))) | ||
}, | ||
) | ||
} | ||
|
||
let equals = lens => ( | ||
list{"equals"}, | ||
({label, value, values}) => | ||
if Lens.get(lens, values) === value { | ||
let equals = lens => { | ||
Description.names: list{"equals"}, | ||
validator: ({label, value, values}) => | ||
if lens.Optic.Lens.get(values) == value { | ||
#ok(value) | ||
} else { | ||
#error(#error(("equals", label))) | ||
}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters