rescript-core
rescript-core copied to clipboard
List API is inconsistent with other modules
This is for historical reasons (the List module is copied from Belt).
For example:
- List:
let forEach: (t<'a>, 'a => 'b) => unit - Others:
let forEach: (t<'a>, 'a => unit) => unit
or
- List:
let mapWithIndex: (t<'a>, (int, 'a) => 'b) => t<'b> - Others:
let mapWithIndex: (t<'a>, ('a, int) => 'b) => t<'b>
or
- List:
getBy - Others:
find
@cknitt I think we can change it to make it consistent. Good to do before Core goes into the compiler. What do you think?
Yes, absolutely, I agree we should make it consistent before Core goes into the compiler. I can make a PR for that some time in the next days.
@zth See #195.
But there are still some open questions:
Listhastype t<'a> = list<'a>.Arraydoesn't have at<'a>defined, andt<'a>was also removed fromResultrecently. If the idea is to define at<'a>only where necessary, then it should be removed fromList, too?- List has
toShuffled, butsort,reverseetc. all withoutto. As this is an immutable data structure, we do not need the distinction betweenshuffleandtoShuffledlike inArray. So remove theto? List.concatManysignature is different fromArray.concatMany. Personally I find theArray.concatManysignature weird anyway (and different from what it was inBelt.Array) and would actually change it there.getAssoc,hasAssoc,removeAssoc,setAssoc: These serve for abusing a list as a map. Given that we have both the mutable JS Map and the immutable Belt.Map available in ReScript, should we really keep these?MapandSethavehasandsize,Arrayhasincludesandlength. What shouldListhave?
Personally I find the Array.concatMany signature weird anyway (and different from what it was in Belt.Array) and would actually change it there.
Which would then be the same as Array.flat. Hmmm. So not sure what to do about the different concatManys.