New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

monadic flatMap #50

Closed
Raynos opened this Issue Dec 21, 2013 · 8 comments

Comments

Projects
None yet
3 participants
@Raynos

Raynos commented Dec 21, 2013

I believe ES6 promises is going to have a flatMap that does not do recursive flattening but instead flattens one level deep. it may also disable thenable assimilation on flatMap.

It would be nice to have something similar here.

@petkaantonov

This comment has been minimized.

Show comment
Hide comment
@petkaantonov

petkaantonov Dec 22, 2013

Owner

Are the semantics laid out somewhere where I can read? I cannot find them in promises_unwrapping repository.

Owner

petkaantonov commented Dec 22, 2013

Are the semantics laid out somewhere where I can read? I cannot find them in promises_unwrapping repository.

@Raynos

This comment has been minimized.

Show comment
Hide comment
@Raynos

Raynos Dec 22, 2013

Not sure what the actual semantics are.

If it's the monadic flatMap then the semantics are pretty much

function flatMap(p, transform) {
  return new Promise(function (resolve, reject) {
    p.then(function (value) {
      var newPromise = transform(value)
      resolve(newPromise.valueOf()) 
    }, reject);
  });
}

i.e. flatMap(p, function (value) { return promise }) it does one level of promise unwrapping.

very similar to chain from fantasy land

Raynos commented Dec 22, 2013

Not sure what the actual semantics are.

If it's the monadic flatMap then the semantics are pretty much

function flatMap(p, transform) {
  return new Promise(function (resolve, reject) {
    p.then(function (value) {
      var newPromise = transform(value)
      resolve(newPromise.valueOf()) 
    }, reject);
  });
}

i.e. flatMap(p, function (value) { return promise }) it does one level of promise unwrapping.

very similar to chain from fantasy land

@petkaantonov

This comment has been minimized.

Show comment
Hide comment
@petkaantonov

petkaantonov Dec 22, 2013

Owner

So transform returns a promise that is already resolved? How would you use this in asynchronous programming? Or how can you call .valueOf() (Which I assume works like .inspect().value()) ?

Owner

petkaantonov commented Dec 22, 2013

So transform returns a promise that is already resolved? How would you use this in asynchronous programming? Or how can you call .valueOf() (Which I assume works like .inspect().value()) ?

@domenic

This comment has been minimized.

Show comment
Hide comment
@domenic

domenic Dec 22, 2013

This is inaccurate; ES6 promises will have no such method. ES6 promises are API complete.

domenic commented Dec 22, 2013

This is inaccurate; ES6 promises will have no such method. ES6 promises are API complete.

@Raynos

This comment has been minimized.

Show comment
Hide comment
@Raynos

Raynos Dec 22, 2013

@domenic flatMap was removed? :/

Raynos commented Dec 22, 2013

@domenic flatMap was removed? :/

@Raynos

This comment has been minimized.

Show comment
Hide comment
@Raynos

Raynos Dec 22, 2013

@petkaantonov sorry it does not return one that is already resolved. I did it wrong. Implementing flatMap is more involved and can't be done with then.

Raynos commented Dec 22, 2013

@petkaantonov sorry it does not return one that is already resolved. I did it wrong. Implementing flatMap is more involved and can't be done with then.

@domenic

This comment has been minimized.

Show comment
Hide comment
@domenic

domenic Dec 22, 2013

flatMap was never part of ES6 promises. There are some members of the committee that want flatMap, but others who do not; the question will be revisited in ES7.

domenic commented Dec 22, 2013

flatMap was never part of ES6 promises. There are some members of the committee that want flatMap, but others who do not; the question will be revisited in ES7.

@Raynos

This comment has been minimized.

Show comment
Hide comment
@Raynos

Raynos Dec 23, 2013

Closing this. We can re-open it to prototype ES7 ideas later.

Raynos commented Dec 23, 2013

Closing this. We can re-open it to prototype ES7 ideas later.

@Raynos Raynos closed this Dec 23, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment