Skip to content
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

just-flip example code broken/doesn't work as expected? #63

Closed
vidhill opened this issue Oct 13, 2017 · 2 comments
Closed

just-flip example code broken/doesn't work as expected? #63

vidhill opened this issue Oct 13, 2017 · 2 comments

Comments

@vidhill
Copy link
Contributor

vidhill commented Oct 13, 2017

I was looking at just-flip,

I thought the example code looked interesting so I copied it into runkit, however the code does not git the expected result, an in the comments
It actually fails with an error,

I tried to fix the example, but I couldn't quite work it out
something about the combination of just-flip and just-map-object

const flip = require('just-flip');
const map = require('just-map-object');
const curry = require('just-curry');

const numbers = {x: 5, y: 10};
const flippedMap = flip(map);
const double = curry(flippedMap, (_, number) => number * 2);
double(numbers) // {x: 10, y: 20];

https://runkit.com/vidhill/59e13d4ae9c3a00012eb22a8

@angus-c
Copy link
Owner

angus-c commented Oct 14, 2017

Edit: Sorry I now realize you were referring to the README example code. It was wrong and I've updated it. Thanks for the bug report!

Hi, so I think the issue is just-curry doesn't work that way. It only takes the function as an argument, then saves subsequent args until it has enough.

function add(a, b, c) {
  return a + b + c;
}
curry(add)(1)(2)(3);

You want just-partial instead (note it uses undefined and not _ for the placeholder)

const flip = require('just-flip');
const map = require('just-map-object');
const partial = require('just-partial-it');

const numbers = {x: 5, y: 10};
const flippedMap = flip(map);
const double = partial(flippedMap, (undefined, number) => number * 2);
double(numbers) // {x: 10, y: 20]

Here's the runkit...
https://runkit.com/angus-c/59e165c5dc90a9001269a7f4

Hope this helps.

@angus-c angus-c closed this as completed Oct 15, 2017
@vidhill
Copy link
Contributor Author

vidhill commented Oct 15, 2017

Cheers,
Love the repo (utility set) by the way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants