# Add Computation Expressions (from f#) to javascript

**URL:** <https://es.discourse.group/t/add-computation-expressions-from-f-to-javascript/591>\
**Category:** 💡 Ideas\
**Created:** [December 21, 2020, 11:11am UTC](https://es.discourse.group/t/add-computation-expressions-from-f-to-javascript/591 "2020-12-21T11:11:25Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![entropitor](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/entropitor/32/554_2.png) [@entropitor](https://es.discourse.group/u/entropitor)\
**Post date:** [December 28, 2020, 8:35am UTC](https://es.discourse.group/t/add-computation-expressions-from-f-to-javascript/591/9 "2020-12-28T08:35:12Z")

</div>

> To avoid 'breaking the web' I think `async` wouldn't be allowed as a custom CE builder otherwise it would change the behaviour of existing code.

Oh I didn't know that async could be used as a variable name, then indeed, we shouldn't allow overriding that :(

> Also some additional syntax that signals when a CE is being used would likely be desired to avoid limiting future JS proposals too much. For example a proposal to add `Map` or `Set` literals

For this specific instance, Map or Set could actually be defined from a CE using the yield functionality (that's what the seq CE in f# does. You could get something very similar depending on actual concrete syntax (e.g. fsharp allows to drop the yield keyword in some circumstances)

But in general, I agree, I guess we could use it like `cancellableAsync function () {}` for the function syntax and following either `do cancellableAsync` or `cancellableAsync do` for block-syntax (similar to what [Async variant · Issue #4 · tc39/proposal-do-expressions · GitHub](https://github.com/tc39/proposal-do-expressions/issues/4) is planning to do for async)?

Then we wouldn't "use" too much possible syntax.

A set could then be defined as

```javascript
let s = do set { yield 1; yield 2; yield 3; };
// If yield ommission is supported
let s2 = do set { 1; 2; 3; };

```

If this was how we would define sets and maps, we have the advantage that userland could easily add other "literals" because it's just a matter of bringing in a certain value in scope and using that as a CE

---

_[View the full topic](https://es.discourse.group/t/add-computation-expressions-from-f-to-javascript/591)._
