Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validator API: option(string) => Js.Result.t(unit, string) #34

Closed
thangngoc89 opened this issue Feb 22, 2018 · 3 comments
Closed

Validator API: option(string) => Js.Result.t(unit, string) #34

thangngoc89 opened this issue Feb 22, 2018 · 3 comments

Comments

@thangngoc89
Copy link
Contributor

thangngoc89 commented Feb 22, 2018

Currently, validator API looks like this:

Custom(state => option(string))

Which is IMHO pretty confusing and requires you to read doc/source code to actually know what is option(string) actually means.

I would suggest that we use result type. It's in OCaml 4.0.3 but Bucklescript provides us a compat type Js.Result.t

Usage:

open Js.Result;
type validateResult = Js.Result.t(unit, string);
...
Custom(values => values.password == "123" ? Error("Really") : Ok())

And I think using result type should be self-described

@fakenickels
Copy link
Member

Sounds interesting

@fakenickels
Copy link
Member

But for me it looks similar, using option or Result in this case.
Let's see what the others think about this

@fakenickels
Copy link
Member

We have now something similar to this
Valid | Error(string)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants