I’ve Waited YEARS For This JavaScript Feature…
As a developer, there are certain features and updates that we eagerly anticipate. For me, one such feature was the introduction of async/await in JavaScript. I had waited years for this functionality to be added to the language, and when it finally arrived, it completely revolutionized my approach to writing asynchronous code.
Prior to the introduction of async/await, handling asynchronous operations in JavaScript often involved callbacks or promises, which could lead to deeply nested and hard-to-read code. With async/await, however, writing asynchronous code became much more straightforward and intuitive. The syntax allows for the use of the “await” keyword to pause execution until a promise is resolved, making it easier to write and understand asynchronous code.
One of the biggest benefits of async/await is its ability to make asynchronous code look and behave more like synchronous code. This not only makes the code easier to read and maintain, but it also reduces the likelihood of errors and bugs. As a result, I found myself spending less time debugging and more time writing new features and functionality in my applications.
Another aspect of async/await that I had waited years for is its error handling capabilities. With traditional async code, error handling often involved nested try/catch blocks or chaining .catch() methods onto promises. This could quickly become cumbersome and difficult to manage. With async/await, error handling is much simpler and more in line with synchronous code, making it easier to handle and propagate errors throughout the application.
In conclusion, the introduction of async/await in JavaScript was a game-changer for me and many other developers. It has made writing and maintaining asynchronous code much more manageable and enjoyable. I’ve waited years for this feature, and it definitely did not disappoint. I look forward to seeing what other improvements and updates the JavaScript language will bring in the future.
I like most of this video but lets please stop promoting code golf, outside of code golf, just for code golfs sake. (i.e. One line of code is rarely better than more lines of code unless the code is cleaner, more maintainable, or more performant)
Apart from that I cannot figure out how to put it in global scope here is a solution right now in typescript.
type PFunc<In, Out> = (val: In) => Out;
function next<In, PrevOut>(fn: PFunc<In, PrevOut>, input: In) {
return {
pipe: <NextOut>(nextFn: PFunc<PrevOut, NextOut>) => next(nextFn, fn(input)),
out: () => fn(input),
};
}
function to<In>(val: In) {
return {
pipe: <Out>(fn: PFunc<In, Out>) => next(fn, val),
};
}
const output = to(1)
.pipe((x) => x * 10)
.pipe((x) => Array(x).fill(null).join(`${x}`))
.pipe((x) => x.length)
.out();
console.log(output);
const magic = to({ x: 10, type: 'foo' })
.pipe((obj) => obj.x)
.pipe((x) => x.toFixed(10))
.pipe(Object.values)
.out();
console.log(magic);
Oooh man this would be amazing. I hope this goes through.
Regular brain: Assume ^ is the exponent operator like a regular human.
Big brain: Know what the exponent operator is.
Galaxy brain: Boost engagement by pretending that ^ is the exponent operator.
the fuck?
anddddddddd still waiting
Great! Used in Elixir which is a great language
This is rather nice. Would be cool if Haskell had that syntax sugar (without resorting to quasi-quotation).
is this like then(res =>) ??
Loved this when i encountered it in Elixir.
Very similar to R's Tidyverse pipes…
yes please do make more videos like this. We need them!
I saw your first video yesterday and immediately subscribed.
We need more videos that relate to the real life scenarios that developers face, not just tutorials.
great work man !
Hmm… I really like this operator. But I don't like Tailwind xD
Ramdajs is so small, fun and cool, that it even looks better than the native.
I was hyped before years, but I'm against it now.
I use compose and pipe everyday, and the other devs are like WTF??? I keep telling them to embrace/learn declarative and functional programming because it is the future!
Would it be possible to write x |> addTwo |> square? That’s how I like to do it in F#.
How would you use modulo operator though?
If this comes, im only scared of refactoring the codebases
2:19 "and we'll also be able to break this into a new line"
Javascript return doesn't usually do that tho, I hope we will really be able to do that. It would be kinda hilarious if implicit statement termination remains the same as they implement this operator
Was it JavaScript or TypeScript?
And how long will it take to have it in node.js, browsers and stuff like prettier