I am trying to use a functional approach to solve a particular issue as part of an exercise in learning Ramda.js.
So I have this test:
it.only("map short name to long name POINTFREE", () => {
let options = [ { long: "perky", short: "p" }, { long: "turky", short: "t" } ];
let lookupByShortName = R.find(R.propEq("short", "t"));
let result = lookupByShortName(options);
expect(result).to.have.property("long", "turky");
});
"options" is used as a lookup sequence. I need to convert a series of strings specfied as a single char, to be the longer name equivalent by referring to the options sequence. So the character "t" should be converted to "turky" as defined in options.
However, this isn't quite structured the way I need to it to be to be useful. The function 'lookupByShortName' is not general, it is hard coded with the value "t". What I want is to omit the "t" parameter, so that when you call lookupByShortName, because it should be curried (by R.find), it should return a function that requires the missing argument. So if I do this, the test fails:
let lookupByShortName = R.find(R.propEq("short"));
so here, lookupByShortName should become a function that requires a single missing parameter, so theoretically, I think I should be able to invoke this function as follows:
lookupByShortName("t")
or more specifically (the "t" is appended at the end):
let lookupByShortName = R.find(R.propEq("short"))("t");
... but I am mistaken, because this does not work, the test fails:
1) Map short arg name to long option name map short name to long name POINTFREE: TypeError: lookupByShortName is not a function at Context.it.only (test/validator.spec.js:744:20)
So I thought of another solution (which does not work, but I don't understand why):
Since "t" is the 2nd parameter that is passed to R.propEq, use the R.__ placeholder, then pass in "t" at the end:
let lookupByShortName = R.find(R.propEq("short", R.__))("t");
I have worked through a series of articles on a blog, and although my understanding is better, I'm still not there yet.
Can you shed any light as to where I'm going wrong, thanks.