-
Notifications
You must be signed in to change notification settings - Fork 31
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
feat: add flip
function
#35
Conversation
Is there any way to make it work with any number of parameters? |
If we can keep it performant for the two-argument case, I'd say sure. Maybe something like this? export function flip(fn, length = fn.length) {
return length === 2
? (a: any, b: any) => fn(b, a)
: length !== fn.length
? (...args: any[]) =>
fn(...args.slice(0, length).reverse(), ...args.slice(length))
: (...args: any[]) => fn(...args.reverse())
} Note: The |
Perhaps it might be best to keep it simple (only two arguments) until the demand for more complex use cases is certain. |
35fc67a
to
04bad7b
Compare
Keeping it just the first two arguments, to align with Ramda (see here) |
Tip
The owner of this PR can publish a preview release by commenting
/publish
in this PR. Afterwards, anyone can try it out by runningpnpm add radashi@pr<PR_NUMBER>
.Description
The
flip
function takes a function and swaps its two arguments. It's most helpful for reversing the order of a comparator (i.e. going from ascending order to descending, or vice versa).Checklist
/docs
directory) has been updatedResolves