-
Notifications
You must be signed in to change notification settings - Fork 75
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
Add a flip()
function
#36
Comments
Nice comments can you think of any other scenarios? When I think of flip I tend to be able to solve it with with array.reduceRight(fn) or using a bindRight (https://github.com/tjmehta/bind-right). |
Well, the There are lots of other functions out there which take a variable number of arguments, where the order matters. Say, the native A simple and performant FILO queue: var ReverseArray = flip(Array);
var queue = new ReverseArray(1, 2, 3);
queue.pop(); // 1
queue.pop(); // 2
queue.pop(); // 3 |
Nice, ES5 has array.reverse though — On Wed, Dec 17, 2014 at 3:18 PM, Tomek Wiszniewski
|
Yup, that was just a quick example from up the sleeve. But I guess the one Anyway, it would be great to have either flip or bindRight here. I think On 17 December 2014 at 22:20, Tejesh Mehta notifications@github.com wrote:
|
One more concrete use case. var a = {1: 'a'};
var b = {1: 'b', 2: 'b'};
var c = {1: 'c', 2: 'c', 3: 'c'};
assign(a, b, c); // » {1: 'c', 2: 'c', 3: 'c'}
flip(assign)(a, b, c); // » {1: 'a', 2: 'b', 3: 'c'} |
👍 var hasKeypaths = require('./has-keypaths');
var curry = require('./curry');
var flip = require('101/flip');
var hasFooBar = curry(flip(hasKeypaths), 2)(['foo.bar']);
hasFooBar({ foo: { bar : true } }); // true btw checkout https://github.com/stoeffel/reverse-arguments used in https://github.com/stoeffel/underscore.string.fp |
I will create a PR for this too this weekend. If it's okay with you guys? |
👍 |
1 similar comment
👍 |
I've been reading issue #16 (closed now), and just wanted to bump the idea of having a
flip()
function.The original proposition by @jfsiii:
Why it's great
In addition to the arguments posted already, I see one great use case – currying right-hand-side arguments.
In the JS world this is common:
doGreatStuff(target, options)
. A function with optional arguments or anoptions
object listed on the very right.I often want to
.bind()
the optional arguments. Wouldn't it be great to doflip(doGreatStuff).bind(null, {candyFloss: true})
?The text was updated successfully, but these errors were encountered: