The heading image has been generated with Dall·E 2
In the previous post
JS Functional Concepts: Pipe and Compose
JoelBonetR 🥇 ・ Jan 2 ・ 3 min read
I explained these concepts in a way that I felt "enough understandable" for a wide range of people, though I can be wrong because it's my point of view at the end, so I've decided to try and make Chat GPT to explain what it does.
The conversation went like that:
can you explain me the following function
export const pipeAsync: any = (...fns: Promise<Function>) => (input: any) => fns.reduce((chain: Promise<Function>, func: Function | Promise<Function> | any) => chain.then(func), Promise.resolve(input));
This function is creating a utility function called "pipeAsync", which allows chaining multiple asynchronous functions together in a pipeline.
It takes a list of functions as input, passed as rest parameter, which are all wrapped inside a promise.
It returns a new function that takes an input value as an argument. This returned function uses the Array.prototype.reduce method to iterate over the array of functions, and calls each function in sequence, passing the result of the previous function call as input to the next function.
The reduce function starts with an initial value of Promise.resolve(input), which is the input passed to the returned function. This is the starting point of the pipeline.
The reduce function then calls the next function in the pipeline with the result of the previous function call, and this process continues for each function in the pipeline.
The result of the reduce function is a new promise that resolves with the final result of the pipeline.
The "pipeAsync" function allows you to chain together multiple asynchronous functions in a way that makes the code more readable and maintainable. It is similar to the "pipe" function from functional programming, but it's adapted to work with async/await.
While it is 100% accurate, the language and language resources it uses may require a bit of focus to understand in my opinion.
What do you think? Is it better explained by GPT or by flesh and bones people? Let me know in the comments!
Top comments (16)
It's actually crazy how it's hard for us humans to tell when an article was written by AI and when it wasn't. I did the same thing but to a bigger extend, which was documented here if you are interested
Hi @aneshodza thank you for sharing! I'll take a gander for sure 😁
So far I'm fairly confident I can tell when AI has been used. It's pretty sad if people's reading ability and discernment are so poor that they airways fall for it; though too many people fall for the lies spouted by politicians, so go figure...
From what I've seen so far AI generated text is usually highly descriptive; verbose and has no personality. It avoids expressing an opinion, but instead presents all possible sides of an argument. It's soulless and boring. Just what you would expect...
So at the end it outputs what any adult discussion should look like (at least in the science-related world, though it won't be true in yellow journalism for example) 😅
@blindfish3 @jonrandy sometimes it is really obvious, don't get me wrong. But as someone that picked up english as his 3rd language I would lie if I told you that I can always pick up on it.
Mostly it isn't that hard - they always have a certain 'feel' to them... whenever I'm suspicious I run it through a GPT detector and my hunch is usually correct
AI generated this comment!
Some people gonna have to start writing better posts if they don't want to be replace by AI.
I already tried it on detail and we still need to wait a bit more till this situation is present, so we have a bit more of time to train ourselves! 😂
Hi Joel, if you build your own model it'll typically do a much better job :)
Thanks @polterguy I'll take a look at it 😀
At first glance I doubt I can create "easily" a good enough training model to compete with Chat GPT though 😂😂
Of course not, but ask ChatGPT "who is Joel Bonet", then realise every single company out there might want a chatbot answering similar questions, such as "What's the price of your products?" or "Why should I chose your company?", etc, etc, etc.
If you ask the publicly available ChatGPT these questions, it will (at best) try to sell you a pro OpenAI account.
AI understands code better than developers.
That's why I've created WhisprAI - code review assistant.
I think it is true in regard to the technical side but AI still has difficulties when it is related to the business side.