Tech Lead/Team Lead. Senior WebDev.
Intermediate Grade on Computer Systems-
High Grade on Web Application Development-
MBA (+Marketing+HHRR).
Studied a bit of law, economics and design
Location
Spain
Education
Higher Level Education Certificate on Web Application Development
You're right, the pipeline operator is just a Stage 2 experimental feature. The science application written in React is quite complex, and Babel is also included in the build system.
Tech Lead/Team Lead. Senior WebDev.
Intermediate Grade on Computer Systems-
High Grade on Web Application Development-
MBA (+Marketing+HHRR).
Studied a bit of law, economics and design
Location
Spain
Education
Higher Level Education Certificate on Web Application Development
Disabling all built-in syntax checking with "javascript.validate.enable": false seems risky.
You'll need to set up a tone of rules in ESLint to validate the rest, all this just to use a single feature that needs to escalate 2 stages more before being implemented.
I'd wholeheartedly suggest avoid using the pipeline operator till it's implemented in the core API (if it does end up like that). In the meantime, you can have a function to handle that pretty easily:
/** Executes Async functions in the order they are passed to,
sending the input argument as argument for the first function */exportconstpipeAsync:any=(...fns:Promise<Function>[])=>(initialArg:any)=>fns.reduce((currentFunc:Promise<Function>,func:Promise<Function>|any)=>currentFunc.then(func),Promise.resolve(initialArg));
It will work for both async and sync operations, though you can have a sync version of it as well, like so:
/** It executes functions in the order they are passed to,
sending the input argument as argument for the first function */exportconstpipe=(...functions:Function[])=>(initialArg:any)=>functions.reduce((chain,func)=>func(chain),initialArg);
Usage example:
exportdefaultasyncfunctionhandler(req:NextApiRequest,res:NextApiResponse){switch(req.method){case'GET':returnpipeAsync(provide,parseData,mock,answer)(req.headers).catch((error:Error)=>console.error(error));default:returnres.status(405).end(`Method ${req.method} Not Allowed`);}
Hi SlimTim, In the last few years I have been learning more FP techniques and applying them where appropriate in my JS code. Currying is an important technique to know but I have yet to find an opportunity to employ it. However, I use the associated technique of Partial Application (AP) extensively.
This is a fine discussion of the topic of Currying and I hope you follow it up with one on PA, which I think has far more utility.
Regards, Tracy
Web Dev full-stack [LAMP] since 2005, but much heavier on the JS stuff these days.
Jack of all Stacks, Master of some.
Always looking to learn new things. Always glad to help out, just ask.
Location
Atlanta, GA
Education
B.S. in Biochemistry 2004, M.S. in Computer Information Systems 2007
currying is terrible, pass multiple parameters to your functions, it's literally gonna save you time, money, and your sanity. functions should not return other functions; they should return values, at least in web development.
Currying is not commonly needed in typical JavaScript codebases. However, where function composition is fundamental, curried functions can be more elegant than the normal practice.
If you add pipeline operators to build, then currying will be much easier because you much cleaner way compose functions together.
which is equal:
render(validateInputState(normalizeEventParameters(userInputEvent)));
just fare more readable.
My luck, for 2 years I can write js fn code with pipeline operator.
Isn't this an experimental feature in stage 2?
Afaik tou need babel or another tool to "patch" it into a different expression for it to work.
You're right, the pipeline operator is just a Stage 2 experimental feature. The science application written in React is quite complex, and Babel is also included in the build system.
.babelrc
in VS code, also need to be set:
"javascript.validate.enable": falseDisabling all built-in syntax checking with
"javascript.validate.enable": falseseems risky.You'll need to set up a tone of rules in ESLint to validate the rest, all this just to use a single feature that needs to escalate 2 stages more before being implemented.
I'd wholeheartedly suggest avoid using the pipeline operator till it's implemented in the core API (if it does end up like that). In the meantime, you can have a function to handle that pretty easily:
It will work for both async and sync operations, though you can have a sync version of it as well, like so:
Usage example:
You can learn more about this here:
JS Functional Concepts: Pipe and Compose
JoelBonetR 🥇 ・ Jan 2 ・ 3 min read
Best regards 😃
or just ust ramda.js
it's actually very usuful in React...
Here is an example
And later:
I use this concept a lot.
Hi SlimTim, In the last few years I have been learning more FP techniques and applying them where appropriate in my JS code. Currying is an important technique to know but I have yet to find an opportunity to employ it. However, I use the associated technique of Partial Application (AP) extensively.
This is a fine discussion of the topic of Currying and I hope you follow it up with one on PA, which I think has far more utility.
Regards, Tracy
currying is terrible, pass multiple parameters to your functions, it's literally gonna save you time, money, and your sanity. functions should not return other functions; they should return values, at least in web development.
great
Currying is not commonly needed in typical JavaScript codebases. However, where function composition is fundamental, curried functions can be more elegant than the normal practice.
Сongratulations 🥳! Your article hit the top posts for the week - dev.to/fruntend/top-10-posts-for-f...
Keep it up 👍