rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

Add some utility functions to Belt Array

Open tsnobip opened this issue 5 years ago • 12 comments

I added the reverse version of map, forEach and keep.

I fixed some typos and examples of the docs.

I also added a rescript implementation of joinWith (it's around 3 times faster than Js.Array.joinWith on common examples, and still faster for arrays up to around 10,000 elements (result string of around 100,000 characters), not sure this function should be used for bigger arrays anyway. This function is only applicable for string array, not sure if it should be placed inside Belt.Array since the other functions apply to polymorphic arrays.

I couldn't find any test files for Belt so I just tested the functions manually. I'll add some tests if needed.

tsnobip avatar Sep 29 '20 13:09 tsnobip

I am in general in favor of this except some comments. Note I am going to take an vacation, so I will merge after it. Other reviews are welcome

bobzhang avatar Sep 30 '20 06:09 bobzhang

Ok thanks, there's no hurry anyway, I'll update my PR accordingly.

tsnobip avatar Sep 30 '20 06:09 tsnobip

do you think it's a good idea to use an optional argument here, for example:

map : 'a array -> ?reverse:bool -> ( 'a -> 'b) -> 'b array

bobzhang avatar Oct 08 '20 09:10 bobzhang

Good idea! that would indeed be quite elegant. I always forget you don't need an additional unit argument in such cases. That would help reduce the amount of functions needed in the API. We could also do the same for reduceReverse for coherence.

Maybe we could make a little survey on discourse?

tsnobip avatar Oct 08 '20 09:10 tsnobip

Maybe we could make a little survey on discourse?

sounds good to me

bobzhang avatar Oct 08 '20 12:10 bobzhang

Well there seems to be no real consensus on this: https://forum.rescript-lang.org/t/api-convention-for-reverse-versions-of-belt-functions/457/ Among 22 respondents, the bigger part would prefer to have extra functions, a smaller part would like to have a flag in the existing functions, some suggest to put those functions inside a Reverse module (the same could be done with the WithIndex functions but that would be a breaking change I guess) and some would even prefer not to have these functions at all in Belt.

The integration of these functions is up to you anyway, I'm OK with all these options, you're the Boss 😀

tsnobip avatar Oct 12 '20 14:10 tsnobip

hi @tsnobip can we have the least controversial utility toString merged first?

bobzhang avatar Oct 13 '20 13:10 bobzhang

sure, would like me to revert the commit where I add the reverse versions and rebase to trunk?

tsnobip avatar Oct 13 '20 14:10 tsnobip

@tsnobip you can also branch from that commit and make a separate PR, either works for me, thanks

bobzhang avatar Oct 14 '20 02:10 bobzhang

ok I created a separate PR (#4748) to make things easier and cleaner.

tsnobip avatar Oct 14 '20 17:10 tsnobip

Could be revisited now if rebased on master, assuming there's still interest.

cristianoc avatar Jun 25 '22 02:06 cristianoc

Could be revisited now if rebased on master, assuming there's still interest.

Yeah I think those functions can still be interesting from time to time. I'll rebase it on master when I have some time.

tsnobip avatar Jul 01 '22 10:07 tsnobip