TypeScript definition improvements for RamdaJS
Today we are proud to present a small fix to the RamdaJS TypeScript definitions. The change itself fixed the type signature for the
invoker function in the popular RamdaJS library. This issue prevented TypeScript users from correctly using the typings while calling the mentioned function.
- Arity: The number of arguments that the function takes.
- Currying: Breaking down a function with multiple arguments into a function that accepts only one argument at a time and returns a function that accepts the next parameter and so forth i.e
fn(a, b, c) --> fn(a)(b)(c).
- Rest parameters: Allows to pass several parameters that will be treated as an array within the function.
- Side effects: When a function modifies some state outside its scope.
RamdaJS brings certain features of functional programming into programs written in JavasScript. It contains a set of functions that encourage immutability and overall makes programmer life easier.
According to the documentation, the function
invoker in RamdaJS does the following:
Turns a named method with a specified arity into a function that can be called directly supplied with arguments and a target object. The returned function is curried and accepts arity + 1 parameters where the final parameter is the target object.
The old TypeScript definitions for the
The updated definition only requires the following signature:
Let’s say we need to apply some arguments to an object function for example the
slice from the string primitive data type.
The call would be like:
Then by using the RamdaJS
invoker it would be like:
In this case we used an arity of 2 but the
slice function also can be called with only one argument:
RamdaJS also applies some curry on the generated function so, calling:
Will produce the same result as the first example.