Skip to content
New issue

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

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

Already on GitHub? # to your account

Add codec for Js.Dict.t #48

Merged
merged 6 commits into from
Feb 12, 2020
Merged

Conversation

jchavarri
Copy link
Contributor

Fixes #4.

Copy link
Member

@ryb73 ryb73 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @jchavarri! Left a couple notes

@@ -16,6 +16,7 @@ open Belt.Result; */
[@decco] type l('a) = list('a);
[@decco] type o('a) = option('a);
[@decco] type r('v, 'e) = Belt.Result.t('v, 'e);
[@decco] type d('v) = Js.Dict.t('v);
Copy link
Member

Choose a reason for hiding this comment

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

Could you write tests that use this type? Or give me permission to push?

src/Decco.re Outdated

| (Ok(prev), Ok(newVal)) => prev->Belt.List.add((key, newVal))->Ok;
}
)->Belt.Result.map(Belt.List.toArray)->Belt.Result.map(Js.Dict.fromArray);
Copy link
Member

Choose a reason for hiding this comment

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

Instead of building a list, converting it to an array. and then converting that to a Js.Dict.t, how about using the reducer to build the Js.Dict.t directly?

@jchavarri
Copy link
Contributor Author

jchavarri commented Jan 6, 2020

@ryb73 thanks for the review :) I think I tackled all requests 👍 Do you mind taking another look please?

Edit: regarding using arrays + lists to generate the new dict, I used them because Js.Dict.t is not immutable, and I try to avoid mutations as much as possible, as I've suffered so much in the past. But I think in this case using same instance across the whole life of reducer is harmless.

@jchavarri jchavarri requested a review from ryb73 January 6, 2020 23:27
Copy link
Member

@ryb73 ryb73 left a comment

Choose a reason for hiding this comment

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

Sorry for the delay. Looks good!!

@ryb73 ryb73 merged commit cfdf1c3 into rescript-labs:master Feb 12, 2020
ryb73 added a commit that referenced this pull request Feb 12, 2020
@mrmurphy
Copy link
Contributor

mrmurphy commented Mar 4, 2020

Muchisimas gracias, @jchavarri!

@jchavarri jchavarri deleted the add-js-dict branch March 15, 2020 12:36
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Js.Dict.t
3 participants