Background
I am trying to pose 2 functions using Ramda, but I am having issue with pipe
, meaning I don't know how to use it.
Code
Let's imagine I have a function that returns an array:
var createQuery = params => [ getSQLQuery( params ), [ getMarket() ] ];
var getSQLQuery = ( { lang } ) => `My query is ${lang}`;
var getMarket = () => "en_en"
So, when calling createQuery({ lang: "es" })
I would have the following output: [ "My query is es", ["en_en"] ]
;
Now, let's also assume I am a nasty boy, and I wanna tap this vital information!
R.tap(console.log, createQuery({lang: "es"}))
A position ( well, a pipe, to be precise ) would be:
R.pipe(
createQuery( {lang: "en"} ),
R.tap(console.log)
);
Which returns a function.
Problem
Now let's say I want to execute said function:
var p = params => R.pipe(
createQuery( params ),
R.tap(console.log)
)(params);
p({lang: "uk"}); //Blows Up!?
Why is my function blowing up with f.apply is not a function
??
What am I doing wrong?
Background
I am trying to pose 2 functions using Ramda, but I am having issue with pipe
, meaning I don't know how to use it.
Code
Let's imagine I have a function that returns an array:
var createQuery = params => [ getSQLQuery( params ), [ getMarket() ] ];
var getSQLQuery = ( { lang } ) => `My query is ${lang}`;
var getMarket = () => "en_en"
So, when calling createQuery({ lang: "es" })
I would have the following output: [ "My query is es", ["en_en"] ]
;
Now, let's also assume I am a nasty boy, and I wanna tap this vital information!
R.tap(console.log, createQuery({lang: "es"}))
A position ( well, a pipe, to be precise ) would be:
R.pipe(
createQuery( {lang: "en"} ),
R.tap(console.log)
);
Which returns a function.
Problem
Now let's say I want to execute said function:
var p = params => R.pipe(
createQuery( params ),
R.tap(console.log)
)(params);
p({lang: "uk"}); //Blows Up!?
Why is my function blowing up with f.apply is not a function
??
What am I doing wrong?
- The problem is that you don't have a type checker telling you what's wrong with the intermediate types (of your partially applied functions). – user6445533 Commented Jan 9, 2018 at 10:06
- I am confused. I fail to see how this is an error that could e from type checking. – Flame_Phoenix Commented Jan 9, 2018 at 10:07
- ftor, so passive aggressive lol – Mulan Commented Jan 9, 2018 at 15:31
1 Answer
Reset to default 6The problem you're experiencing is because you are calling createQuery(params)
and then trying to treat the result as a function.
You're example function p
can be updated like so:
const p = params => R.pipe(createQuery, R.tap(console.log))(params)
and R.pipe
will pass params
and argument to createQuery
, the result of which is then given to the result of `R.tap(console.log).
This can be simplified to the following, by removing the immediate application of params
:
const p = R.pipe(createQuery, R.tap(console.log));