I have this code:
const compose2 = (f, g) => (...args) => f(g(...args))
const compose = (...fns) => fns.reduce(compose2)
const count = arr => arr.length
const split = str => str.split(/\s+/)
const addAsyncWord = async str => `${str} some words obtained asynchronously`
const read = text => text
const word = compose(
count,
split,
(await addAsyncWord),
read
)
console.log('word ->', await word()) //<- edited
but is throwing the following error:
Uncaught SyntaxError: missing ) in parenthetical
output expected after reading, concat words (obtained from a server randomly, needs to be asynchronously), spliting words, and finally count the total length, must be something similar to this:
word -> 10
How to make this to work? thanks
I will post my solution here if helps anyone in the future:
const compose2 = (f, g) => async (...args) => f(await g(...args))
const compose = (...fns) => fns.reduce(compose2)
const count = arr => arr.length
const split = str => str.split(/\s+/)
const addAsyncWord = async str => `${str} some words obtained asynchronously`
const read = text => text
const word = compose(
count,
split,
addAsyncWord,
read
)
const test = async () => {
const word1 = await word('Hello world')
console.log('word ->', word1)
}
test()
thank you for your comments.