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

Use arrays instead of lists as they're cleaner and faster in our case #21

Merged
merged 1 commit into from
Jan 14, 2021

Conversation

gaku-sei
Copy link
Contributor

Notice that validations still take a list! I have a workaround but as it changes the surface API i will push it in an other pr

} else {
#ok(value)
let required = {
Description.names: list{"required"},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went for a record instead of a tuple as they're not slower and more explicit 👍

validations->ListExtra.flatMap(Validations.getName)
props["validations"]->Option.mapWithDefault([], validations =>
validations->ArrayExtra.flatMap(validation =>
validation->Validations.getNames->List.toArray
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to isolate the conversion code as much as I could.
When ready, we can simply drop the List.toArray function call and use arrays instead of lists

switch validation({
Validations.Validator.Args.label: props["errorLabel"]->OptionExtra.alt(
switch validator({
Validations.Validator.Args.label: props["errorLabel"]->OptionExtra.or(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More consistent with the future BeltExtra lib 😋

@gaku-sei gaku-sei force-pushed the use-array-instead-of-lists branch from fe8c478 to 98e5fc1 Compare January 14, 2021 09:51
@@ -27,26 +27,36 @@ module Validator = {
type t<'values, 'value, 'error> = Args.t<'values, 'value, 'error> => Value.t<'value, 'error>
}

module Pair = {
type t<'values, 'value, 'error> = (list<string>, Validator.t<'values, 'value, 'error>)
module Description = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a pair anymore ^^

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like Record more, since like you said it is clearer with the label

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the feedback 😄

@gaku-sei gaku-sei merged commit 776683f into master Jan 14, 2021
@gaku-sei gaku-sei deleted the use-array-instead-of-lists branch January 14, 2021 10:01
| list{x, ...xs} => x === y ? true : includes(xs, y)
}
module ArrayExtra = {
let flatMap = (xs, f) => xs->Array.reduce([], (acc, x) => acc->Js.Array2.concat(f(x)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why should we use Js.Array2.concat instead of Array.concat @gaku-sei -san?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's pretty simple, Js.Array2.concat is direct bindings to the native Array.prototype.concat method, while Array.concat is a reimplementation.

We might need to see which is better in the future 😕


module type Values = {
type t
}
Copy link
Contributor

@infothien infothien Jan 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel like you are not using it right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I dropped it in the other pr 👍

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

Successfully merging this pull request may close these issues.

2 participants