Skip to content

Instantly share code, notes, and snippets.

@atomita
Last active September 17, 2020 10:33
Show Gist options
  • Save atomita/bf01c712297b1d21d29610a110315d4e to your computer and use it in GitHub Desktop.
Save atomita/bf01c712297b1d21d29610a110315d4e to your computer and use it in GitHub Desktop.
function ifExpression (condition) {
if ('function' == typeof condition ? condition() : condition) {
return {
then: (callback) => {
const end = 'function' == typeof callback ? callback() : callback
const res = {
else: (callback) => ({
end
}),
elseif: (condition) => ({
then: (callback) => res
}),
end
}
return res
}
}
}
return {
then: (callback) => {
return {
else: (callback) => ({
end: 'function' == typeof callback ? callback() : callback
}),
elseif: (condition) => ifExpression(condition),
end: null
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment