Skip to content

Instantly share code, notes, and snippets.

@haskellcamargo
Created October 23, 2017 18:53
Show Gist options
  • Save haskellcamargo/bdb0daf36958a49de2b56d6275db20d7 to your computer and use it in GitHub Desktop.
Save haskellcamargo/bdb0daf36958a49de2b56d6275db20d7 to your computer and use it in GitHub Desktop.
const _effect = evaluator => ({ type: 'effect', evaluator });
const _mut = evaluator => ({ type: 'mut', evaluator });
const _while = (condition, body) => env => {
if (condition(env)) {
const state = body.reduce((env, elem) => {
if (elem.type === 'effect') {
void elem.evaluator(env);
return env;
} else if (elem.type === 'mut') {
return elem.evaluator(env);
}
}, env);
_while(condition, body)(state);
}
};
_while(
({ i }) => i < 10,
[
_effect(({ i }) => console.log(i)),
_mut(({ i }) => ({ i: i + 1 }))
]
)({ i: 0 })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment