-
Notifications
You must be signed in to change notification settings - Fork 10
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
Support index on array types #14
base: master
Are you sure you want to change the base?
Conversation
|
Oh this is very good, thanks a lot. I will review with care soon. |
Thank you very much @fakenickels. Notice that it's very wip and some things should probably change (like the way the array is updated in the setter). While writing the description I also wondered if having the constructor with index alongside the "global" one wouldn't be better (it would also make the withIndexes option useless): type _ field =
| Hobbies : string array field (* like usual *)
| HobbiesAt : int -> string option field We could even have an unsafe type _ field =
| Hobbies : string array field (* like usual *)
| HobbiesAt : int -> string option field
| HobbiesAtExn : int -> string field |
d0393b9
to
29ec265
Compare
Small update: I implemented the above, and dropped the It should be more or less ready for review, we just need to solve two issues: |
Sorry about taking so long to give feedback, but I promise I'll be taking a look til the end of this week |
ppat_desc: | ||
Ppat_construct( | ||
{ | ||
txt: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now with this additional code we reached the column size of text, I think it's a good idea to break this down into smaller functions
Sorry for the late reply, and thank you very much for your review @fakenickels When implementing this solution I was also considering some "refactor" but didn't want to change too many things. Also because I don't know what the plans are to make the code base scales. Do you have any ideas on how this could be refactored? Should I just split the code into functions, or is it ok to use the |
Hey there @gaku-sei ! Just to let you know I had to change a little bit the code to make it compatible with the new BS |
@gaku-sei sorry about taking so long to get updates here. I'm willing to merge this already, but could we split the code in more functions or use Ast_helper or ppx_metaquot to make it less verbose like you suggested? |
Target
The idea of this pr is to generate gadt constructors with an index attribute when the field is of type array.
This:
Will generate:
With the above example we can now type:
This becomes extremely useful once used with the new
Field
component introduced here. Since one can now write:Within a loop it can be:
Js.Dict
We could also consider adding this feature for
Js.Dict.t
with a key being astring
. Most of the work is already done/prepared.One word on the getter
Currently, the getter is a bit awkward, since you have to pass an optional value in order to update the field (with
*At
, not with*AtExn
).In order to allow the new provided value to be a
string
here instead of anoption(string)
, we have to make the generatedfield
type change, and accept two arguments:When setting an array's value using
*At
and passingNone
, nothing happens: