-
Notifications
You must be signed in to change notification settings - Fork 7
Description
I think it would be really beneficial in this proposal to explain what this does that yield does not enable you to do at the moment. As is, why would you want compositional functions given you can already do this in not-so-bad syntax with yield.
I think it might also be very beneficial to expand this proposal (without changing semantics) and explain how this can be used for arbitrary decorators.
Here are some interesting use cases that can be implemented with compositional functions and enjoy this syntax.
class Foo {
observable foo(){
// converts any return value to an Observable.just and any thrown error to a rejected
// observable to guard against double try/catching
}
promise bar(){
// same idea but with promises, converts throws to rejections and returns to fulfillments
}
cached baz(){
// this method's return value is memoized
}
synchronised boo(){
// method returns a promise/task/observable and guarantees calls to underlying fn are queued
}
remote ban(){
// this method executes a remote procedure call to a server
}
async animal(){
// normal promise returning fn
}
logged cow(){
// every call to this method is logged
}
timed chicken(){
// this method is benchmarked
}
contract(x => !Number.isNaN(x) && x > 0) factorial(num){
// this contract is enforced in runtime
}
contract(Boolean) doSomethingToTruthy(){
// enforces truthy arg in runtime
}
contract(x => x., ret => ret instanceof Observable) thisAlwaysReturnsObservables(){
// enforces return value
}
autocurry add(x,y){
// automatically curried
}
compose(autocurry, observable, contract(Boolean) map(fn, val){
// returns a carried version of the map that allows awaiting observables
// and ensures a non-null argument is passed for fn
}
}
I think the fact we can get arbitrary decoration in class declarations and expressions should not be understated here and that there are a lot of interesting use cases to show.
Also, I wonder why not add async as a global which makes this proposal completely possible on top of the async/await one and can streamline it.