-
Notifications
You must be signed in to change notification settings - Fork 30
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
Some comments on the Array module #51
Comments
Right. Not sure why we have the unsafe "from" functions anyway. Can't we always use arrayLike, and if people really want to be unsafe for some reason, then they can cast to an arrayLike using type t<'a> = array<'a>
type arrayLike<'a> = Js.Array2.array_like<'a>
@val external from: arrayLike<'a> => t<'a> = "Array.from"
@val external fromWithMap: (arrayLike<'a>, 'a => 'b) => t<'b> = "Array.from"
Hmm, I don't know, it is a version of the JS
IMHO this would be inconsistent with the naming in the rest of the library which avoids such abbreviations. To me, this would feel more like "the OCaml way" than "the ReScript way". |
I agree. I don't think this library needs to exhaustively cover the entire JS API surface either.
So there are two rules that sort of conflict here already. One is that it's an established rescript convention to use I don't think the first rule applies all that much, since The other rule also has quite a few exceptions already. Just in the It is a downside that
I think I was actually the originator of "the ReScript way", from before it was even "the BuckleScript way", and I can tell you that it wasn't as well thought out and designed as you might think it was. Things were mostly just haphazardly added onto what was already there while trying to strike some balance between consistency, familiarity and intuitiveness. And while I do think this is a good fallback rule, it's also one I think should have plenty of exceptions since it's quite verbose. And indeed there are plenty of exceptions to it already. Just in the There are also several similar abbreviations in use already, for example But this naming is also inconsistent with the more general rule, which tends to describe additional function arguments. Whereas in this case Still, I can understand that the A more out-of-the-box alternative might be to remove these variant entirely, and just have the standard functions always pass the index. That means you'd have to ignore it when it's not used (e.g. |
Partly covered in the docstrings PR: #78 |
I agree WithIndex is verbose. findIndexWithIndex is the worst. In functions like someWithIndex and everyWithIndex the WithIndex part becomes more important than the core function name. F# and OCaml use the letter i abbreviation. I wouldn't make the index part required in a callback since I think most of the time it isn't needed. It's just so nice to write those callbacks as x => rather than (x,_) => |
from
is unsafe (not soundly typed), but not marked as suchfromWithMap
. It's also misleadingly named, suggesting it takes aMap
data structure as an additional argument, when in fact it wants a map function. The latter goes for all*WithMap
functions, but I won't repeat myself for every one of them. A better naming scheme for these might bemapFrom*
?*WithIndex
is a really common and quite verbose pattern. I would suggest special casing this and use just ani
suffix for this, e.g.mapi
instead ofmapWithIndex
. I think it's common enough that this makes sense.indexOfFrom
andlastIndexOfFrom
are not very intuitively named. PerhapsindexOfStartingFrom
would be better?getSymbol
seems like it would return a symbol, rather than what is pointed to by a symbol.getBySymbol
andsetBySymbol
might be better names.The text was updated successfully, but these errors were encountered: