I think it's a good idea to attempt to express these ideas using existing
syntax and see what that might look like.

So, for a bit of fun, I wrote this:

https://gist.github.com/zenparsing/9ff3036b6eb15fa436e4

Basically, there's a Maybe function which returns a proxy over a target,
and returns Maybes for calls and gets.  Then there's a Definitely function
that unwraps the Maybe (unwrapping Nothing to undefined of course).

    let scriptParent =
Definitely(Maybe(window).document.scripts[0].parentNode);

If you wanted syntactic sugar for this kind of thing, you'd probably want
postfix operators to replace the Maybe and Definitely function calls.

Swift does something similar with "?" and "!":

https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/OptionalChaining.html

This is kind of a generic monad pattern though, so it would be cool if the
syntax could be applied to other monad-ish things.
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to