Folding Promises in JavaScript
codementor.io
Folding Promises in JavaScript
1–10 of 48 posts
Re: Folding Promises in JavaScript
#2In any case, this is very helpful, thanks for writing/sharing.
Re: Folding Promises in JavaScript
#3Or: How to make simple things complex and make a codebase a complete puzzle for those that come after you?
Re: Folding Promises in JavaScript
#4Re: Folding Promises in JavaScript
#5Re: Folding Promises in JavaScript
#6I don't know much about these concepts but isn't `const objToArray = ({ a }) => [a]; ` losing data, that being the key of the value in the object? I'm asking because it says that "Isomorphism is a pair of transformations between two categories with no data loss". In any case, this is very helpful, thanks for writing/sharing.
forall x. objToArray(arrayToObj(x)) == x
forall x. arrayToObj(objToArray(x)) == xRe: Folding Promises in JavaScript
#7I don't know much about these concepts but isn't `const objToArray = ({ a }) => [a]; ` losing data, that being the key of the value in the object? I'm asking because it says that "Isomorphism is a pair of transformations between two categories with no data loss". In any case, this is very helpful, thanks for writing/sharing.
As long as you know what the transformation is, you can convert between them without data loss.
Re: Folding Promises in JavaScript
#8I challenge the view that making the identity value being able to be something other than a Promise is 'making it better'. Pointless abstraction is one of my pet peeves in this industry. This looks like it has gone from a fairly straightforward, if kludgy, piece of code to something far more complex. Why not just:
const listOfPromises = [...]
const result = Promise.all(listOfPromises).then(results => {
return results.reduce((acc, next) => acc + next)
})
?Re: Folding Promises in JavaScript
#9I don't know much about these concepts but isn't `const objToArray = ({ a }) => [a]; ` losing data, that being the key of the value in the object? I'm asking because it says that "Isomorphism is a pair of transformations between two categories with no data loss". In any case, this is very helpful, thanks for writing/sharing.
You're right, because for a pair of functions f and g, you have an isomorphism if:
f(g(x)) == x
g(f(x)) == x
for every x. However, here of course (([a]) => {a})( (({ a }) => [a])({ key: 'data'}) )
is equal to { a: 'data' }
The OP doesn't quite master what he's talking about…Re: Folding Promises in JavaScript
#10I can't quite understand the difference between endomorphism ("input and output of the transformer must be from the same category") and homomorphism ("structure preserving transformation. We always stay in the same category"). Can someone help?
So a function that turns an array into another array of different length would be endomorphic (since it maintains the same type), but not homomorphic since it has a different structure (a different set of keys).