-
Notifications
You must be signed in to change notification settings - Fork 367
Open
Labels
Description
Babel docs: http://babeljs.io/docs/plugins/transform-do-expressions
Stage 1 gist reproduced below: https://gist.github.com/dherman/1c97dfb25179fa34a41b5fff040f9879 by @dherman
In Babel
interface DoExpression <: Expression {
type: "DoExpression";
body: BlockStatement
}Motivation
- expression-oriented programming one of the great advances of FP
- expressions plug together like legos, making more malleable programming experience in-the-small
Examples
Write in an expression-oriented style, scoping variables as locally as possible:
let x = do {
let tmp = f();
tmp * tmp + 1
};Use conditional statements as expressions, instead of awkward nested ternaries:
let x = do {
if (foo()) { f() }
else if (bar()) { g() }
else { h() }
};Especially nice for templating languages like JSX:
return (
<nav>
<Home />
{
do {
if (loggedIn) {
<LogoutButton />
} else {
<LoginButton />
}
}
}
</nav>
)Reactions are currently unavailable