selfrefactor / rambda

Faster and smaller alternative to Ramda
https://selfrefactor.github.io/rambda
MIT License
1.65k stars 89 forks source link

`R.prepend`/`R.append` fns accept broader types #699

Closed Peeja closed 1 year ago

Peeja commented 1 year ago

Before, R.prepend(4) or R.append(4) would produce a function which could only be applied to a number[]. However, you may well want to append a 4 to an array whose elements can be numbers or other things, such as a (string | number)[]. This commit improves the types to accept such arrays.

You may also have an array of a more specific type (such as number[]) and wish to use R.prepend/R.append to expand the type. Because it's usually a mistake, append("d")(listOfNumbers) will cause a type error; however, explicitly calling append("d")<string | number>(listOfNumbers) will give you a (string | number)[].

selfrefactor commented 1 year ago

Thanks for this PR.

I'd change few things before releasing:

Peeja commented 1 year ago

Sounds good! I went with that sort of naming because I kept losing track of what was what otherwise, but please do adjust it as you see fit. 🙂